Updating pyproject.toml version during build results in incorrect version in uv.lock
This is more an observation rather than an issue.
I'm using a ci tool that parses commit history, generates the "next" version and updates the version in pyproject.toml (the tool is python-semantic-release).
What I just noticed was, since python-semantic-release updates pyproject.toml when it performs a build, once the build has finished uv.lock contains the "wrong" version for the project, i.e.
[[package]]
name = "my-package"
version = "0.2.1.dev0"
source = { virtual = "." }
Since python-semantic-release bumped the version to "0.2.1". To fix I added uv sync && build.sh && git add uv.lock - this updates the lock file and stages it (with the other files python-semantic-release modifies.
I'm not sure if this causes more problems than it fixes, but I thought I'd mention it - I think in general it's probably a better practice to generate tags based on the pyproject.toml->project.version rather than the other way around?
Thanks for the report.
I think @charliermarsh has some context on this.
Related: https://github.com/astral-sh/uv/issues/7533
@my1e5 yeah that's the same - shall I close this?
All discussion is being moved to #7533. So this can be closed.
I was also experiencing the uv.lock going out of sync when python-semantic-release would bump the version in pyproject.toml. I fixed this by:
- Adding a step after the semantic release that updates the version of my project in the
uv.lockfile by running:uv lock --upgrade-package <project_name>followed by committing and pushing the change.- Link to my GitHub workflow file: https://github.com/aqib-oss/sonar-qube-gh-action/blob/main/.github/workflows/main-workflow.yaml#L74
- Thankfully, this does not trigger another run of the
mainbranch workflow, however, if it did, it can easily be handled by adding a pre-check job that determines if the last commit was for syncing the project version in theuv.lockfile, and the main job will run only if the output from the pre-check job istrue.