-
-
Notifications
You must be signed in to change notification settings - Fork 281
feat(providers): add uv_provider #1351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
from typing import TYPE_CHECKING | ||
|
||
import tomlkit | ||
|
||
from commitizen.providers.base_provider import TomlProvider | ||
|
||
if TYPE_CHECKING: | ||
import tomlkit.items | ||
|
||
|
||
class UvProvider(TomlProvider): | ||
""" | ||
uv.lock and pyproject.tom version management | ||
""" | ||
|
||
filename = "pyproject.toml" | ||
lock_filename = "uv.lock" | ||
|
||
@property | ||
def lock_file(self) -> Path: | ||
return Path() / self.lock_filename | ||
|
||
def set_version(self, version: str) -> None: | ||
super().set_version(version) | ||
self.set_lock_version(version) | ||
|
||
def set_lock_version(self, version: str) -> None: | ||
pyproject_toml_content = tomlkit.parse(self.file.read_text()) | ||
project_name = pyproject_toml_content["project"]["name"] # type: ignore[index] | ||
|
||
document = tomlkit.parse(self.lock_file.read_text()) | ||
|
||
packages: tomlkit.items.AoT = document["package"] # type: ignore[assignment] | ||
for i, package in enumerate(packages): | ||
if package["name"] == project_name: | ||
document["package"][i]["version"] = version # type: ignore[index] | ||
break | ||
self.lock_file.write_text(tomlkit.dumps(document)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from commitizen.config.base_config import BaseConfig | ||
from commitizen.providers import get_provider | ||
from commitizen.providers.uv_provider import UvProvider | ||
|
||
if TYPE_CHECKING: | ||
from pytest_regressions.file_regression import FileRegressionFixture | ||
|
||
|
||
PYPROJECT_TOML = """ | ||
[project] | ||
name = "test-uv" | ||
version = "4.2.1" | ||
description = "Add your description here" | ||
readme = "README.md" | ||
requires-python = ">=3.13" | ||
dependencies = ["commitizen==4.2.1"] | ||
""" | ||
|
||
UV_LOCK_SIMPLIFIED = """ | ||
version = 1 | ||
revision = 1 | ||
requires-python = ">=3.13" | ||
|
||
[[package]] | ||
name = "commitizen" | ||
version = "4.2.1" | ||
source = { registry = "https://pypi.org/simple" } | ||
dependencies = [ | ||
{ name = "argcomplete" }, | ||
{ name = "charset-normalizer" }, | ||
{ name = "colorama" }, | ||
{ name = "decli" }, | ||
{ name = "jinja2" }, | ||
{ name = "packaging" }, | ||
{ name = "pyyaml" }, | ||
{ name = "questionary" }, | ||
{ name = "termcolor" }, | ||
{ name = "tomlkit" }, | ||
] | ||
sdist = { url = "https://files.pythonhosted.org/packages/d8/a3/77ffc9aee014cbf46c84c9f156a1ddef2d4c7cfb87d567decf2541464245/commitizen-4.2.1.tar.gz", hash = "sha256:5255416f6d6071068159f0b97605777f3e25d00927ff157b7a8d01efeda7b952", size = 50645 } | ||
wheels = [ | ||
{ url = "https://files.pythonhosted.org/packages/57/ce/2f5d8ebe8376991b5f805e9f33d20c7f4c9ca6155bdbda761117dc41dff1/commitizen-4.2.1-py3-none-any.whl", hash = "sha256:a347889e0fe408c3b920a34130d8f35616be3ea8ac6b7b20c5b9aac19762661b", size = 72646 }, | ||
] | ||
|
||
[[package]] | ||
name = "decli" | ||
version = "0.6.2" | ||
source = { registry = "https://pypi.org/simple" } | ||
sdist = { url = "https://files.pythonhosted.org/packages/3d/a0/a4658f93ecb589f479037b164dc13c68d108b50bf6594e54c820749f97ac/decli-0.6.2.tar.gz", hash = "sha256:36f71eb55fd0093895efb4f416ec32b7f6e00147dda448e3365cf73ceab42d6f", size = 7424 } | ||
wheels = [ | ||
{ url = "https://files.pythonhosted.org/packages/bf/70/3ea48dc9e958d7d66c44c9944809181f1ca79aaef25703c023b5092d34ff/decli-0.6.2-py3-none-any.whl", hash = "sha256:2fc84106ce9a8f523ed501ca543bdb7e416c064917c12a59ebdc7f311a97b7ed", size = 7854 }, | ||
] | ||
|
||
[[package]] | ||
name = "test-uv" | ||
version = "4.2.1" | ||
source = { virtual = "." } | ||
dependencies = [ | ||
{ name = "commitizen" }, | ||
] | ||
""" | ||
|
||
|
||
def test_uv_provider( | ||
config: BaseConfig, tmpdir, file_regression: FileRegressionFixture | ||
): | ||
with tmpdir.as_cwd(): | ||
pyproject_toml_file = tmpdir / UvProvider.filename | ||
pyproject_toml_file.write_text(PYPROJECT_TOML, encoding="utf-8") | ||
|
||
uv_lock_file = tmpdir / UvProvider.lock_filename | ||
uv_lock_file.write_text(UV_LOCK_SIMPLIFIED, encoding="utf-8") | ||
|
||
config.settings["version_provider"] = "uv" | ||
|
||
provider = get_provider(config) | ||
assert isinstance(provider, UvProvider) | ||
assert provider.get_version() == "4.2.1" | ||
|
||
provider.set_version("100.100.100") | ||
assert provider.get_version() == "100.100.100" | ||
|
||
updated_pyproject_toml_content = pyproject_toml_file.read_text(encoding="utf-8") | ||
updated_uv_lock_content = uv_lock_file.read_text(encoding="utf-8") | ||
|
||
for content in (updated_pyproject_toml_content, updated_uv_lock_content): | ||
# updated project version | ||
assert "100.100.100" in content | ||
# commitizen version which was the same as project version and should not be affected | ||
assert "4.2.1" in content | ||
|
||
file_regression.check(updated_pyproject_toml_content, extension=".toml") | ||
file_regression.check(updated_uv_lock_content, extension=".lock") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
version = 1 | ||
revision = 1 | ||
requires-python = ">=3.13" | ||
|
||
[[package]] | ||
name = "commitizen" | ||
version = "4.2.1" | ||
source = { registry = "https://pypi.org/simple" } | ||
dependencies = [ | ||
{ name = "argcomplete" }, | ||
{ name = "charset-normalizer" }, | ||
{ name = "colorama" }, | ||
{ name = "decli" }, | ||
{ name = "jinja2" }, | ||
{ name = "packaging" }, | ||
{ name = "pyyaml" }, | ||
{ name = "questionary" }, | ||
{ name = "termcolor" }, | ||
{ name = "tomlkit" }, | ||
] | ||
sdist = { url = "https://files.pythonhosted.org/packages/d8/a3/77ffc9aee014cbf46c84c9f156a1ddef2d4c7cfb87d567decf2541464245/commitizen-4.2.1.tar.gz", hash = "sha256:5255416f6d6071068159f0b97605777f3e25d00927ff157b7a8d01efeda7b952", size = 50645 } | ||
wheels = [ | ||
{ url = "https://files.pythonhosted.org/packages/57/ce/2f5d8ebe8376991b5f805e9f33d20c7f4c9ca6155bdbda761117dc41dff1/commitizen-4.2.1-py3-none-any.whl", hash = "sha256:a347889e0fe408c3b920a34130d8f35616be3ea8ac6b7b20c5b9aac19762661b", size = 72646 }, | ||
] | ||
|
||
[[package]] | ||
name = "decli" | ||
version = "0.6.2" | ||
source = { registry = "https://pypi.org/simple" } | ||
sdist = { url = "https://files.pythonhosted.org/packages/3d/a0/a4658f93ecb589f479037b164dc13c68d108b50bf6594e54c820749f97ac/decli-0.6.2.tar.gz", hash = "sha256:36f71eb55fd0093895efb4f416ec32b7f6e00147dda448e3365cf73ceab42d6f", size = 7424 } | ||
wheels = [ | ||
{ url = "https://files.pythonhosted.org/packages/bf/70/3ea48dc9e958d7d66c44c9944809181f1ca79aaef25703c023b5092d34ff/decli-0.6.2-py3-none-any.whl", hash = "sha256:2fc84106ce9a8f523ed501ca543bdb7e416c064917c12a59ebdc7f311a97b7ed", size = 7854 }, | ||
] | ||
|
||
[[package]] | ||
name = "test-uv" | ||
version = "100.100.100" | ||
source = { virtual = "." } | ||
dependencies = [ | ||
{ name = "commitizen" }, | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
[project] | ||
name = "test-uv" | ||
version = "100.100.100" | ||
description = "Add your description here" | ||
readme = "README.md" | ||
requires-python = ">=3.13" | ||
dependencies = ["commitizen==4.2.1"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.