Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions commitizen/providers/uv_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def set_version(self, version: str) -> None:
self.set_lock_version(version)

def set_lock_version(self, version: str) -> None:
if not self.lock_file.exists():
# `uv.lock` is optional: a freshly initialised project (or a uv
# workspace member, since the lock lives at the workspace root)
# may not have one yet. Updating `pyproject.toml` is enough.
return

pyproject_toml_content = tomlkit.parse(
self.file.read_text(encoding=self._get_encoding())
)
Expand Down
21 changes: 21 additions & 0 deletions tests/providers/test_uv_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,24 @@ def test_uv_provider(

file_regression.check(updated_pyproject_toml_content, extension=".toml")
file_regression.check(updated_uv_lock_content, extension=".lock")


def test_uv_provider_without_lock_file(config: BaseConfig, tmp_path, monkeypatch):
"""Regression for #1383: a freshly initialised uv project (or a uv
workspace member) has no `uv.lock` yet; bumping must still update
`pyproject.toml` instead of raising `FileNotFoundError`."""
monkeypatch.chdir(tmp_path)
pyproject_toml_file = tmp_path / UvProvider.filename
pyproject_toml_file.write_text(PYPROJECT_TOML, encoding="utf-8")
assert not (tmp_path / UvProvider.lock_filename).exists()

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"
assert "100.100.100" in pyproject_toml_file.read_text(encoding="utf-8")
assert not (tmp_path / UvProvider.lock_filename).exists()
Loading