Skip to content

Commit f55d567

Browse files
jharrisonSVbearomorphism
authored andcommitted
fix(providers): normalize package names in uv provider for uv.lock matching
1 parent 4cb3f95 commit f55d567

File tree

6 files changed

+77
-3
lines changed

6 files changed

+77
-3
lines changed

commitizen/providers/uv_provider.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import tomlkit
66
import tomlkit.items
7+
from packaging.utils import canonicalize_name
78

89
from commitizen.providers.base_provider import TomlProvider
910

@@ -27,12 +28,13 @@ def set_version(self, version: str) -> None:
2728
def set_lock_version(self, version: str) -> None:
2829
pyproject_toml_content = tomlkit.parse(self.file.read_text())
2930
project_name = pyproject_toml_content["project"]["name"] # type: ignore[index]
31+
normalized_project_name = canonicalize_name(str(project_name))
3032

3133
document = tomlkit.parse(self.lock_file.read_text())
3234

3335
packages: tomlkit.items.AoT = document["package"] # type: ignore[assignment]
3436
for i, package in enumerate(packages):
35-
if package["name"] == project_name:
37+
if package["name"] == normalized_project_name:
3638
document["package"][i]["version"] = version # type: ignore[index]
3739
break
3840
self.lock_file.write_text(tomlkit.dumps(document))

tests/providers/test_uv_provider.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from typing import TYPE_CHECKING
44

5+
import pytest
6+
57
from commitizen.providers import get_provider
68
from commitizen.providers.uv_provider import UvProvider
79

@@ -21,6 +23,16 @@
2123
dependencies = ["commitizen==4.2.1"]
2224
"""
2325

26+
PYPROJECT_TOML_UNDERSCORE = """
27+
[project]
28+
name = "test_uv"
29+
version = "4.2.1"
30+
description = "Add your description here"
31+
readme = "README.md"
32+
requires-python = ">=3.13"
33+
dependencies = ["commitizen==4.2.1"]
34+
"""
35+
2436
UV_LOCK_SIMPLIFIED = """
2537
version = 1
2638
revision = 1
@@ -66,12 +78,22 @@
6678
"""
6779

6880

81+
@pytest.mark.parametrize(
82+
"pyproject_content",
83+
[
84+
pytest.param(PYPROJECT_TOML, id="hyphenated"),
85+
pytest.param(PYPROJECT_TOML_UNDERSCORE, id="underscore"),
86+
],
87+
)
6988
def test_uv_provider(
70-
config: BaseConfig, tmpdir, file_regression: FileRegressionFixture
89+
config: BaseConfig,
90+
tmpdir,
91+
file_regression: FileRegressionFixture,
92+
pyproject_content: str,
7193
):
7294
with tmpdir.as_cwd():
7395
pyproject_toml_file = tmpdir / UvProvider.filename
74-
pyproject_toml_file.write_text(PYPROJECT_TOML, encoding="utf-8")
96+
pyproject_toml_file.write_text(pyproject_content, encoding="utf-8")
7597

7698
uv_lock_file = tmpdir / UvProvider.lock_filename
7799
uv_lock_file.write_text(UV_LOCK_SIMPLIFIED, encoding="utf-8")

tests/providers/test_uv_provider/test_uv_provider.lock renamed to tests/providers/test_uv_provider/test_uv_provider_hyphenated_.lock

File renamed without changes.

tests/providers/test_uv_provider/test_uv_provider.toml renamed to tests/providers/test_uv_provider/test_uv_provider_hyphenated_.toml

File renamed without changes.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
version = 1
3+
revision = 1
4+
requires-python = ">=3.13"
5+
6+
[[package]]
7+
name = "commitizen"
8+
version = "4.2.1"
9+
source = { registry = "https://pypi.org/simple" }
10+
dependencies = [
11+
{ name = "argcomplete" },
12+
{ name = "charset-normalizer" },
13+
{ name = "colorama" },
14+
{ name = "decli" },
15+
{ name = "jinja2" },
16+
{ name = "packaging" },
17+
{ name = "pyyaml" },
18+
{ name = "questionary" },
19+
{ name = "termcolor" },
20+
{ name = "tomlkit" },
21+
]
22+
sdist = { url = "https://files.pythonhosted.org/packages/d8/a3/77ffc9aee014cbf46c84c9f156a1ddef2d4c7cfb87d567decf2541464245/commitizen-4.2.1.tar.gz", hash = "sha256:5255416f6d6071068159f0b97605777f3e25d00927ff157b7a8d01efeda7b952", size = 50645 }
23+
wheels = [
24+
{ url = "https://files.pythonhosted.org/packages/57/ce/2f5d8ebe8376991b5f805e9f33d20c7f4c9ca6155bdbda761117dc41dff1/commitizen-4.2.1-py3-none-any.whl", hash = "sha256:a347889e0fe408c3b920a34130d8f35616be3ea8ac6b7b20c5b9aac19762661b", size = 72646 },
25+
]
26+
27+
[[package]]
28+
name = "decli"
29+
version = "0.6.2"
30+
source = { registry = "https://pypi.org/simple" }
31+
sdist = { url = "https://files.pythonhosted.org/packages/3d/a0/a4658f93ecb589f479037b164dc13c68d108b50bf6594e54c820749f97ac/decli-0.6.2.tar.gz", hash = "sha256:36f71eb55fd0093895efb4f416ec32b7f6e00147dda448e3365cf73ceab42d6f", size = 7424 }
32+
wheels = [
33+
{ url = "https://files.pythonhosted.org/packages/bf/70/3ea48dc9e958d7d66c44c9944809181f1ca79aaef25703c023b5092d34ff/decli-0.6.2-py3-none-any.whl", hash = "sha256:2fc84106ce9a8f523ed501ca543bdb7e416c064917c12a59ebdc7f311a97b7ed", size = 7854 },
34+
]
35+
36+
[[package]]
37+
name = "test-uv"
38+
version = "100.100.100"
39+
source = { virtual = "." }
40+
dependencies = [
41+
{ name = "commitizen" },
42+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
[project]
3+
name = "test_uv"
4+
version = "100.100.100"
5+
description = "Add your description here"
6+
readme = "README.md"
7+
requires-python = ">=3.13"
8+
dependencies = ["commitizen==4.2.1"]

0 commit comments

Comments
 (0)