Code: Select all
> uv run myapp
Usage: myapp ...
Version: {the git hash with dirty indicator}
< /code>
> uv venv
> source .venv/bin/activate
(myapp)> myapp --help
Usage: myapp ...
Version: {the git hash with dirty indicator}
< /code>
In the past (with other compiled languages) I would generate a file at build time that gets packaged into the executable. Later at runtime I would read this file and print out the version. I've gotten something similar to work with uv if I use:
>python write_version_to_file.py
>uv pip install --force-reinstall . # uv run myapp would also work here
< /code>
But this feels clunky because it is two steps, and requires the "force" flag for pip. I feel like it would be cleaner if I could hook into uv in a way that I can dynamically generate my version file right before uv run
PYProject.toml:
Code: Select all
[tool.hatch.build.hooks.custom]
path = "write_version_to_file.py"
class = "VersionBuildHook"
< /code>
but this also only ran consistently with uv pip install
Als Referenz sehen die relevanten Teile meines PyProject.toml aus:
Code: Select all
[project.scripts]
myapp = "mypkg.myapp:main"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.hatch.build]
artifacts = ["src/mypkg/version.properties"]