Skip to content

Commit

Permalink
feat(providers): add uv_provider
Browse files Browse the repository at this point in the history
closes: #1349
  • Loading branch information
Lee-W committed Jan 31, 2025
1 parent 95e7d5a commit b76cefb
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions commitizen/providers/uv_provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from __future__ import annotations

Check warning on line 1 in commitizen/providers/uv_provider.py

View check run for this annotation

Codecov / codecov/patch

commitizen/providers/uv_provider.py#L1

Added line #L1 was not covered by tests

from pathlib import Path
from typing import TYPE_CHECKING

Check warning on line 4 in commitizen/providers/uv_provider.py

View check run for this annotation

Codecov / codecov/patch

commitizen/providers/uv_provider.py#L3-L4

Added lines #L3 - L4 were not covered by tests

import tomlkit

Check warning on line 6 in commitizen/providers/uv_provider.py

View check run for this annotation

Codecov / codecov/patch

commitizen/providers/uv_provider.py#L6

Added line #L6 was not covered by tests

from commitizen.providers.base_provider import TomlProvider

Check warning on line 8 in commitizen/providers/uv_provider.py

View check run for this annotation

Codecov / codecov/patch

commitizen/providers/uv_provider.py#L8

Added line #L8 was not covered by tests

if TYPE_CHECKING:
import tomlkit.items


class UvProvider(TomlProvider):

Check warning on line 14 in commitizen/providers/uv_provider.py

View check run for this annotation

Codecov / codecov/patch

commitizen/providers/uv_provider.py#L14

Added line #L14 was not covered by tests
"""
uv.lock and pyproject.tom version management
"""

filename = "pyproject.toml"
lock_filename = "uv.lock"

Check warning on line 20 in commitizen/providers/uv_provider.py

View check run for this annotation

Codecov / codecov/patch

commitizen/providers/uv_provider.py#L19-L20

Added lines #L19 - L20 were not covered by tests

@property
def lock_file(self) -> Path:
return Path() / self.lock_filename

Check warning on line 24 in commitizen/providers/uv_provider.py

View check run for this annotation

Codecov / codecov/patch

commitizen/providers/uv_provider.py#L22-L24

Added lines #L22 - L24 were not covered by tests

def set_version(self, version: str) -> None:
super().set_version(version)
self.set_lock_version(version)

Check warning on line 28 in commitizen/providers/uv_provider.py

View check run for this annotation

Codecov / codecov/patch

commitizen/providers/uv_provider.py#L26-L28

Added lines #L26 - L28 were not covered by tests

def set_lock_version(self, version: str) -> None:
document = tomlkit.parse(self.lock_file.read_text())
name = self.config.settings.get("name")

Check warning on line 32 in commitizen/providers/uv_provider.py

View check run for this annotation

Codecov / codecov/patch

commitizen/providers/uv_provider.py#L30-L32

Added lines #L30 - L32 were not covered by tests

packages: tomlkit.items.AoT = document["package"] # type: ignore[assignment]
for i, package in enumerate(packages):
if package["name"] == name:
document["package"][i]["version"] = version # type: ignore[index]
break
self.file.write_text(tomlkit.dumps(document))

Check warning on line 39 in commitizen/providers/uv_provider.py

View check run for this annotation

Codecov / codecov/patch

commitizen/providers/uv_provider.py#L34-L39

Added lines #L34 - L39 were not covered by tests

0 comments on commit b76cefb

Please sign in to comment.