Skip to content

Commit 002351b

Browse files
committed
fix: rm dynamic version
1 parent d73c1f7 commit 002351b

File tree

3 files changed

+28
-38
lines changed

3 files changed

+28
-38
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ scripts = { sync_uv_pre_commit = "sync_uv_pre_commit.cli:main" }
1616
dependencies = [
1717
"packaging",
1818
"pre-commit>=3.5.0",
19-
"toml>=0.10.2",
19+
"tomlkit>=0.13.2",
2020
"typing-extensions>=4.12.2",
2121
]
2222
[dependency-groups]

src/sync_uv_pre_commit/cli.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616

1717
from sync_uv_pre_commit.log import ExitCode, logger
1818
from sync_uv_pre_commit.package import find_specifier, parse_lockfile
19-
from sync_uv_pre_commit.toml import find_valid_extras, find_valid_groups, read_pyproject
19+
from sync_uv_pre_commit.toml import (
20+
find_valid_extras,
21+
find_valid_groups,
22+
read_pyproject,
23+
remove_dynamic_version,
24+
write_pyproject,
25+
)
2026

2127
if TYPE_CHECKING:
2228
from collections.abc import Generator
@@ -54,9 +60,14 @@ def resolve_pyproject(
5460

5561
shutil.copy(pyproject, new_pyproject)
5662
pyproject_dict = read_pyproject(new_pyproject)
63+
pyproject_dict = remove_dynamic_version(pyproject_dict)
64+
new_pyproject.unlink()
65+
write_pyproject(pyproject_dict, new_pyproject)
66+
5767
logger.debug("before validate extras: %s", extras)
5868
valid_extras = find_valid_extras(pyproject_dict)
5969
logger.debug("valid extras: %s", valid_extras)
70+
logger.debug("before validate groups: %s", groups)
6071
valid_groups = find_valid_groups(pyproject_dict)
6172
logger.debug("valid groups: %s", valid_groups)
6273

src/sync_uv_pre_commit/toml.py

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from __future__ import annotations
22

3+
from copy import deepcopy
34
from pathlib import Path
45
from typing import TYPE_CHECKING, Any
56

6-
import toml
7+
import tomlkit
78

89
if TYPE_CHECKING:
910
from os import PathLike
@@ -26,51 +27,29 @@ def find_valid_groups(pyproject: dict[str, Any]) -> set[str]:
2627

2728
def read_pyproject(pyproject: str | PathLike[str]) -> dict[str, Any]:
2829
pyproject = Path(pyproject)
29-
with pyproject.open() as f:
30-
return toml.load(f)
31-
32-
33-
def combine_dev_dependencies(
34-
pyproject: dict[str, Any], destination: str | PathLike[str]
35-
) -> tuple[str, Path]:
36-
destination = Path(destination)
37-
pyproject = pyproject.copy()
38-
39-
key, new_pyproject = dev_dependencies_to_dependencies(pyproject)
40-
write_pyproject(new_pyproject, destination)
41-
42-
return key, destination
30+
with pyproject.open("rb") as f:
31+
return tomlkit.load(f)
4332

4433

4534
def write_pyproject(
4635
pyproject: dict[str, Any], pyproject_path: str | PathLike[str]
4736
) -> Path:
4837
pyproject_path = Path(pyproject_path)
4938
with pyproject_path.open("w") as f:
50-
toml.dump(pyproject, f)
39+
tomlkit.dump(pyproject, f)
5140
return pyproject_path
5241

5342

54-
def dev_dependencies_to_dependencies(
55-
pyproject: dict[str, Any],
56-
) -> tuple[str, dict[str, Any]]:
57-
pyproject = pyproject.copy()
58-
key = "dev_dependencies"
59-
43+
def remove_dynamic_version(pyproject: dict[str, Any]) -> dict[str, Any]:
6044
project: dict[str, Any] = pyproject["project"]
45+
if "dynamic" not in project:
46+
return pyproject
6147

62-
optional_dependencies: dict[str, list[str]] = project.setdefault(
63-
"optional-dependencies", {}
64-
)
65-
if key in optional_dependencies:
66-
key = f"new_{key}"
67-
68-
tools: dict[str, Any] = pyproject.setdefault("tool", {})
69-
uv_config: dict[str, Any] = tools.setdefault("uv", {})
70-
dev_dependencies: list[str] = uv_config.setdefault("dev-dependencies", [])
71-
72-
optional_dependencies[key] = dev_dependencies
73-
project["optional-dependencies"] = optional_dependencies
74-
pyproject["project"] = project
48+
dynamic: list[str] = project["dynamic"]
49+
if "version" not in dynamic:
50+
return pyproject
7551

76-
return key, pyproject
52+
pyproject = deepcopy(pyproject)
53+
pyproject["project"]["dynamic"].remove("version")
54+
pyproject["project"]["version"] = "0.1.0"
55+
return pyproject

0 commit comments

Comments
 (0)