File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ from __future__ import annotations
2+
3+ import os
4+ from pathlib import Path
5+ from typing import TYPE_CHECKING
6+
7+ import tomlkit
8+
9+ from commitizen .providers .base_provider import TomlProvider
10+
11+ if TYPE_CHECKING :
12+ import tomlkit .items
13+
14+
15+ class UvProvider (TomlProvider ):
16+ """
17+ uv.lock and pyproject.tom version management
18+ """
19+
20+ filename = "pyproject.toml"
21+ lock_filename = "uv.lock"
22+
23+ @property
24+ def lock_file (self ) -> Path :
25+ return Path () / self .lock_filename
26+
27+ @property
28+ def has_uv_toml (self ) -> bool :
29+ return os .path .isfile ("uv.toml" )
30+
31+ def set_version (self , version : str ) -> None :
32+ super ().set_version (version )
33+ self .set_lock_version (version )
34+
35+ def set_lock_version (self , version : str ) -> None :
36+ pyproject_toml_content = tomlkit .parse (self .file .read_text ())
37+ project_name = pyproject_toml_content ["project" ]["name" ] # type: ignore[index]
38+
39+ document = tomlkit .parse (self .lock_file .read_text ())
40+
41+ packages : tomlkit .items .AoT = document ["package" ] # type: ignore[assignment]
42+ for i , package in enumerate (packages ):
43+ if package ["name" ] == project_name :
44+ document ["package" ][i ]["version" ] = version # type: ignore[index]
45+ break
46+ self .lock_file .write_text (tomlkit .dumps (document ))
You can’t perform that action at this time.
0 commit comments