Skip to content
This repository was archived by the owner on Jan 18, 2026. It is now read-only.

Commit 9fa01f7

Browse files
committed
fix: check valid extras
1 parent eaf975e commit 9fa01f7

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/sync_uv_pre_commit/cli.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,13 @@ def resolve_pyproject(
6565
origin_pyproject, temp_directory = Path(pyproject), Path(temp_directory)
6666
new_pyproject = temp_directory / "pyproject.toml"
6767

68-
key, new_pyproject = combine_dev_dependencies(origin_pyproject, new_pyproject)
69-
command = [
70-
"uv",
71-
"pip",
72-
"compile",
73-
new_pyproject.name,
74-
"-o",
75-
"requirements.txt",
76-
"--extra",
77-
key,
78-
]
79-
if extras:
80-
command = [
81-
*command,
82-
*chain.from_iterable(("--extra", extra) for extra in extras),
83-
]
68+
key, new_pyproject, valid_extras = combine_dev_dependencies(
69+
origin_pyproject, new_pyproject
70+
)
71+
command = ["uv", "pip", "compile", new_pyproject.name, "-o", "requirements.txt"]
72+
extras = (key, *extras)
73+
extras = tuple(extra for extra in extras if extra in valid_extras)
74+
command = [*command, *chain.from_iterable(("--extra", extra) for extra in extras)]
8475

8576
uv_process = subprocess.run( # noqa: S603
8677
command, cwd=temp_directory, check=False, capture_output=True, text=True

src/sync_uv_pre_commit/toml.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,26 @@
1111
__all__ = []
1212

1313

14+
def find_valid_extras(pyproject: dict[str, Any]) -> set[str]:
15+
project: dict[str, Any] = pyproject["project"]
16+
optional_dependencies: dict[str, list[str]] = project.setdefault(
17+
"optional-dependencies", {}
18+
)
19+
return set(optional_dependencies.keys())
20+
21+
1422
def combine_dev_dependencies(
1523
pyproject: str | PathLike[str], destination: str | PathLike[str]
16-
) -> tuple[str, Path]:
24+
) -> tuple[str, Path, set[str]]:
1725
pyproject = Path(pyproject)
1826
destination = Path(destination)
1927

2028
pyproject_obj = read_pyproject(pyproject)
2129
key, new_pyproject = dev_dependencies_to_dependencies(pyproject_obj)
2230
write_pyproject(new_pyproject, destination)
31+
extras = find_valid_extras(new_pyproject)
2332

24-
return key, destination
33+
return key, destination, extras
2534

2635

2736
def read_pyproject(pyproject: str | PathLike[str]) -> dict[str, Any]:

0 commit comments

Comments
 (0)