Skip to content

Commit 7206ee7

Browse files
authored
support excluding versions for excluded packages (#74)
* check that excluding version is allowed * pass through excluded versions * wrong type for missing default dependencies * exclude warnings for excluded packages * example env for exclusions in pixi
1 parent 6ed2713 commit 7206ee7

4 files changed

Lines changed: 41 additions & 2 deletions

File tree

envs/pixi.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ python = "3.10"
1111
[feature.failing.dependencies]
1212
numpy = "2.1"
1313

14+
[feature.exclude.dependencies]
15+
pytest = "!=9.1.0"
16+
1417
[environments]
1518
env1 = { features = ["py310"] }
1619
env2 = ["py39"]
1720
failing-env = { features = ["failing"] }
21+
exclude-env = { features = ["exclude"] }

minimum_versions/environments/pixi.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
version_re = re.compile(f"(?P<version>{_version_re})")
1212
lower_pin_re = re.compile(rf">=(?P<version>{_version_re})$")
1313
tight_pin_re = re.compile(rf">=(?P<lower>{_version_re}),<(?P<upper>{_version_re})")
14+
exclusion_pin_re = re.compile(rf"!=(?P<excluded>{_version_re})$")
1415

1516

1617
def parse_spec(name, version_text: str | dict):
@@ -44,6 +45,13 @@ def parse_spec(name, version_text: str | dict):
4445
)
4546

4647
raw_version = lower_pin
48+
elif (match := exclusion_pin_re.match(version_text)) is not None:
49+
excluded = match.group("excluded")
50+
warnings.append(
51+
f"Excluded version found: {excluded!r}. This is invalid for policy packages"
52+
" and must be ignored explicitly."
53+
)
54+
raw_version = excluded
4755
else:
4856
raise ValueError(f"Unsupported version spec: {version_text}")
4957

@@ -110,7 +118,7 @@ def parse_pixi_environment(name: str, manifest_path: pathlib.Path | None):
110118
(
111119
get_in([feature, "dependencies"], all_features, {})
112120
if feature != "default"
113-
else pixi_config.get("dependencies", [])
121+
else pixi_config.get("dependencies", {})
114122
)
115123
for feature in feature_names
116124
]

minimum_versions/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def validate(today, policy_file, manifest_path, environment_paths):
6161
}
6262

6363
warnings = {
64-
env: dict(warnings_) for env, (_, warnings_) in parsed_environments.items()
64+
env: {n: w for n, w in warnings_ if n not in policy.exclude}
65+
for env, (_, warnings_) in parsed_environments.items()
6566
}
6667
environments = {
6768
env: [spec for spec in specs if spec.name not in policy.exclude]

minimum_versions/tests/test_environments.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,32 @@ def test_parse_spec_error(self, version_text):
357357
[("c", [])],
358358
id="local_package",
359359
),
360+
pytest.param(
361+
textwrap.dedent("""\
362+
[feature.feature1.dependencies]
363+
a = "!=1.0.1"
364+
365+
[environments]
366+
env1 = { features = ["feature1"] }
367+
""".rstrip()),
368+
"pixi.toml",
369+
[
370+
Spec("a", Version("1.0.1")),
371+
],
372+
[
373+
(
374+
"a",
375+
[
376+
(
377+
"Excluded version found: '1.0.1'. This is invalid for policy packages"
378+
" and must be ignored explicitly."
379+
),
380+
"package should be pinned to a minor version (got 1.0.1)",
381+
],
382+
)
383+
],
384+
id="excluded_version",
385+
),
360386
),
361387
)
362388
def test_parse_pixi_environment(

0 commit comments

Comments
 (0)