mbarkhau / bumpver

BumpVer: Automatic Versioning
https://github.com/mbarkhau/bumpver
MIT License
199 stars 36 forks source link

Bumpver doesn't work with uv.lock files #239

Closed epicserve closed 1 month ago

epicserve commented 1 month ago

It seems like Bumver doesn't work with uv.lock files. I've also tried other patterns for the uv.lock file and I'm unable to find a pattern that works.

Bumpver version: 2023.1129

I've also tried:

"uv.lock" = [
    "name = \"bumpver-issue\"\nversion = \"{version}\"",
]

And:

"uv.lock" = [
    'name = "bumpver-issue"\nversion = "{version}"',
]

And:

"uv.lock" = [
    'name\s=\s"bumpver-issue"\nversion\s=\s"{version}"',
]

Steps to reproduce:

$ mkdir bumpver-issue

$ cd bumpver-issue 

$ uv init
Initialized project `bumpver-issue`

$ uv add django
Using CPython 3.13.0
Creating virtual environment at: .venv
Resolved 5 packages in 149ms
Installed 3 packages in 129ms
 + asgiref==3.8.1
 + django==5.1.2
 + sqlparse==0.5.1

$ uvx bumpver init
WARNING - Couldn't parse pyproject.toml: Missing version_pattern
Updated pyproject.toml

Change the [tool.bumpver] section in pyproject.toml to:

[tool.bumpver]
current_version = "0.1.0"
version_pattern = "MAJOR.MINOR.PATCH"
commit_message = "bump version {old_version} -> {new_version}"
tag_message = "{new_version}"
tag_scope = "default"
pre_commit_hook = ""
post_commit_hook = ""
commit = true
tag = true
push = false

[tool.bumpver.file_patterns]
"pyproject.toml" = [
    'current_version = "{version}"',
]
"uv.lock" = [
    "version = \"{version}\"",
]

Then initialize Git:

git init
git add .
git commit -m "Initial commit"

Then bump the version:

➜ uvx bumpver update -p
INFO    - fetching tags from remote (to turn off use: -n / --no-fetch)
INFO    - Old Version: 0.1.0
INFO    - New Version: 0.1.1
INFO    - git commit --message 'bump version 0.1.0 -> 0.1.1'
INFO    - git tag --annotate 0.1.1 --message '0.1.1'

Then run git diff HEAD^ HEAD | cat to see that bumpver changed all the versions off all the dependencies in the uv.lock file instead of just the version for bumpver-issue.

diff --git a/pyproject.toml b/pyproject.toml
index 7258584..60f1789 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -9,7 +9,7 @@ dependencies = [
 ]

 [tool.bumpver]
-current_version = "0.1.0"
+current_version = "0.1.1"
 version_pattern = "MAJOR.MINOR.PATCH"
 commit_message = "bump version {old_version} -> {new_version}"
 tag_message = "{new_version}"
diff --git a/uv.lock b/uv.lock
index 78e4d88..91c3ed5 100644
--- a/uv.lock
+++ b/uv.lock
@@ -3,7 +3,7 @@ requires-python = ">=3.13"

 [[package]]
 name = "asgiref"
-version = "3.8.1"
+version = "0.1.1"
 source = { registry = "https://pypi.org/simple" }
 sdist = { url = "https://files.pythonhosted.org/packages/29/38/b3395cc9ad1b56d2ddac9970bc8f4141312dbaec28bc7c218b0dfafd0f42/asgiref-3.8.1.tar.gz", hash = "sha256:c343bd80a0bec947a9860adb4c432ffa7db769836c64238fc34bdc3fec84d590", size = 35186 }
 wheels = [
@@ -12,7 +12,7 @@ wheels = [

 [[package]]
 name = "bumpver-issue"
-version = "0.1.0"
+version = "0.1.1"
 source = { virtual = "." }
 dependencies = [
     { name = "django" },
@@ -23,7 +23,7 @@ requires-dist = [{ name = "django", specifier = ">=5.1.2" }]

 [[package]]
 name = "django"
-version = "5.1.2"
+version = "0.1.1"
 source = { registry = "https://pypi.org/simple" }
 dependencies = [
     { name = "asgiref" },
@@ -37,7 +37,7 @@ wheels = [

 [[package]]
 name = "sqlparse"
-version = "0.5.1"
+version = "0.1.1"
 source = { registry = "https://pypi.org/simple" }
 sdist = { url = "https://files.pythonhosted.org/packages/73/82/dfa23ec2cbed08a801deab02fe7c904bfb00765256b155941d789a338c68/sqlparse-0.5.1.tar.gz", hash = "sha256:bb6b4df465655ef332548e24f08e205afc81b9ab86cb1c45657a7ff173a3a00e", size = 84502 }
 wheels = [
mbarkhau commented 1 month ago

Yes, unfortunately, this is a limitation of the current implementation. bumpver currently works line per line basis. There's a good deal to refactor, but I don't think it's impossible.

Do you have any interest/capacity to work on this?

epicserve commented 1 month ago

Would there be less to refactor and less risk to breaking existing usages, it you added the ability to specify Regex flags in the pattern.

Maybe something like:

"uv.lock" = [
    "/version = \"{version}\"/gmi",
]
mbarkhau commented 1 month ago

Perhaps. In principle, for this issue, the \n would be enough indication to treat the pattern differently.

"uv.lock" = [
    'name = "bumpver-issue"\nversion = "{version}"',
]

However the multiline detection works, I'm doubtful there's an easy (i.e. hacky) way to make it work. The line by line logic is carried through so many places, I doubt you can make an isolated change.

epicserve commented 1 month ago

Regarding capacity ... I was just checking this project out because a friend said he used it. I'm not even using it yet, so I don't really want to spend time on a fix. Right now, using the following in a Justfile is working for me.

@version_bump version:
    sed -i '' 's/version = ".*"/version = "{{ version }}"/' pyproject.toml
    uv sync
    git add pyproject.toml uv.lock
    git commit -m "Version bump to v{{ version }}"
    just _success "Version bumped to v{{ version }}."
epicserve commented 1 month ago

@mbarkhau, out of curiosity, why did you close it? UV is becoming more and more common and gaining a lot of traction as the preferred way to manage Python packages.

mbarkhau commented 4 weeks ago

UV is incidental to the issue. The fundamental issue is this https://github.com/mbarkhau/bumpver/issues/193

petrprikryl commented 3 weeks ago

A little bit related to https://github.com/astral-sh/uv/issues/6298