Skip to content

Commit 0915a9d

Browse files
committed
Revert partial version specifier support
We have agreed to pursue the dynamic plugin API instead.
1 parent 4f2efef commit 0915a9d

File tree

10 files changed

+36
-101
lines changed

10 files changed

+36
-101
lines changed

tests/artifacts/variant_json_files/dummy_project-1.0.0-variants.json

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@
3838
}
3939
},
4040
"variants": {
41-
"1d836653": {
41+
"3351fc6a": {
4242
"fictional_hw": {
4343
"compute_capability": [
44-
">=4,<6"
44+
"4",
45+
"5"
4546
]
4647
}
4748
},
@@ -91,10 +92,13 @@
9192
]
9293
}
9394
},
94-
"a0d8855a": {
95+
"181830db": {
9596
"fictional_hw": {
9697
"compute_capability": [
97-
">=4,<8"
98+
"4",
99+
"5",
100+
"6",
101+
"7"
98102
]
99103
}
100104
},
@@ -111,10 +115,11 @@
111115
]
112116
}
113117
},
114-
"092f6ea8": {
118+
"72c47fce": {
115119
"fictional_hw": {
116120
"compute_capability": [
117-
">=7"
121+
"7",
122+
"8"
118123
]
119124
}
120125
},
@@ -150,4 +155,4 @@
150155
}
151156
}
152157
}
153-
}
158+
}

tests/models/test_variant.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from variantlib.constants import VALIDATION_FEATURE_NAME_REGEX
1111
from variantlib.constants import VALIDATION_NAMESPACE_REGEX
12-
from variantlib.constants import VALIDATION_VALUE_STR_REGEX
12+
from variantlib.constants import VALIDATION_VALUE_REGEX
1313
from variantlib.constants import VARIANT_HASH_LEN
1414
from variantlib.errors import ValidationError
1515
from variantlib.models.variant import VariantDescription
@@ -112,7 +112,7 @@ def test_failing_regex_value() -> None:
112112
_ = VariantProperty(namespace="provider", feature="feature", value="")
113113

114114
for c in string.printable:
115-
if VALIDATION_VALUE_STR_REGEX.fullmatch(c):
115+
if VALIDATION_VALUE_REGEX.fullmatch(c):
116116
continue
117117

118118
with pytest.raises(ValidationError, match="must match regex"):

tests/test_api.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from variantlib.constants import PYPROJECT_TOML_TOP_KEY
3131
from variantlib.constants import VALIDATION_FEATURE_NAME_REGEX
3232
from variantlib.constants import VALIDATION_NAMESPACE_REGEX
33-
from variantlib.constants import VALIDATION_VALUE_STR_REGEX
33+
from variantlib.constants import VALIDATION_VALUE_REGEX
3434
from variantlib.constants import VARIANT_INFO_DEFAULT_PRIO_KEY
3535
from variantlib.constants import VARIANT_INFO_FEATURE_KEY
3636
from variantlib.constants import VARIANT_INFO_NAMESPACE_KEY
@@ -167,9 +167,7 @@ def test_get_variant_hashes_by_priority_roundtrip(
167167
min_size=1,
168168
max_size=3,
169169
unique=True,
170-
elements=st.from_regex(
171-
VALIDATION_VALUE_STR_REGEX, fullmatch=True
172-
),
170+
elements=st.from_regex(VALIDATION_VALUE_REGEX, fullmatch=True),
173171
),
174172
),
175173
),

tests/test_variants_json.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,31 +174,38 @@ def test_validate_variants_json() -> None:
174174
),
175175
],
176176
),
177-
"1d836653": VariantDescription(
177+
"3351fc6a": VariantDescription(
178178
properties=[
179179
VariantProperty(
180180
namespace="fictional_hw",
181181
feature="compute_capability",
182-
value=">=4,<6",
182+
value=str(value),
183183
)
184+
for value in range(4, 6)
184185
]
185186
),
186-
"a0d8855a": VariantDescription(
187+
"181830db": VariantDescription(
187188
properties=[
188189
VariantProperty(
189190
namespace="fictional_hw",
190191
feature="compute_capability",
191-
value=">=4,<8",
192+
value=str(value),
192193
)
194+
for value in range(4, 8)
193195
]
194196
),
195-
"092f6ea8": VariantDescription(
197+
"72c47fce": VariantDescription(
196198
properties=[
197199
VariantProperty(
198200
namespace="fictional_hw",
199201
feature="compute_capability",
200-
value=">=7",
201-
)
202+
value="7",
203+
),
204+
VariantProperty(
205+
namespace="fictional_hw",
206+
feature="compute_capability",
207+
value="8",
208+
),
202209
]
203210
),
204211
}

variantlib/constants.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,7 @@
2929

3030
VALIDATION_NAMESPACE_REGEX = re.compile(r"[a-z0-9_]+")
3131
VALIDATION_FEATURE_NAME_REGEX = re.compile(r"[a-z0-9_]+")
32-
33-
# For `Property value` there is two regexes:
34-
# 1. `VALIDATION_VALUE_VSPEC_REGEX` - if `packaging.specifiers.SpecifierSet` is used
35-
# Note: for clarity - only "full version" are allowed
36-
# i.e. so no "a|b|alpha|beta|rc|post|etc." versions
37-
VALIDATION_VALUE_VSPEC_REGEX = re.compile(r"[0-9_.,!>~<=]+")
38-
# 2. `VALIDATION_VALUE_STR_REGEX` - if string matching is used
39-
VALIDATION_VALUE_STR_REGEX = re.compile(r"[a-z0-9_.]+")
40-
VALIDATION_VALUE_REGEX = re.compile(
41-
rf"{VALIDATION_VALUE_VSPEC_REGEX.pattern}|{VALIDATION_VALUE_STR_REGEX.pattern}"
42-
)
32+
VALIDATION_VALUE_REGEX = re.compile(r"[a-z0-9_.]+")
4333

4434
VALIDATION_FEATURE_REGEX = re.compile(
4535
rf"""

variantlib/models/provider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from variantlib.constants import VALIDATION_FEATURE_NAME_REGEX
99
from variantlib.constants import VALIDATION_NAMESPACE_REGEX
10-
from variantlib.constants import VALIDATION_VALUE_STR_REGEX
10+
from variantlib.constants import VALIDATION_VALUE_REGEX
1111
from variantlib.models.base import BaseModel
1212
from variantlib.models.variant import VariantProperty
1313
from variantlib.protocols import VariantFeatureName
@@ -49,7 +49,7 @@ class VariantFeatureConfig(BaseModel):
4949
"validator": lambda val: validate_and(
5050
[
5151
lambda v: validate_type(v, list[VariantFeatureValue]),
52-
lambda v: validate_list_matches_re(v, VALIDATION_VALUE_STR_REGEX),
52+
lambda v: validate_list_matches_re(v, VALIDATION_VALUE_REGEX),
5353
lambda v: validate_list_min_len(v, 1),
5454
lambda v: validate_list_all_unique(v),
5555
],

variantlib/models/variant.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from variantlib.constants import VALIDATION_FEATURE_REGEX
1414
from variantlib.constants import VALIDATION_NAMESPACE_REGEX
1515
from variantlib.constants import VALIDATION_PROPERTY_REGEX
16+
from variantlib.constants import VALIDATION_VALUE_REGEX
1617
from variantlib.constants import VARIANT_HASH_LEN
1718
from variantlib.constants import VariantInfoJsonDict
1819
from variantlib.errors import ValidationError
@@ -24,7 +25,6 @@
2425
from variantlib.validators.base import validate_matches_re
2526
from variantlib.validators.base import validate_type
2627
from variantlib.validators.combining import validate_and
27-
from variantlib.validators.vprop import validate_variant_property_value
2828

2929
if sys.version_info >= (3, 11):
3030
from typing import Self
@@ -102,7 +102,7 @@ class VariantProperty(VariantFeature):
102102
"validator": lambda val: validate_and(
103103
[
104104
lambda v: validate_type(v, VariantFeatureValue),
105-
lambda v: validate_variant_property_value(v), # pyright: ignore[reportArgumentType]
105+
lambda v: validate_matches_re(v, VALIDATION_VALUE_REGEX),
106106
],
107107
value=val,
108108
)

variantlib/resolver/filtering.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
from __future__ import annotations
22

3-
import contextlib
43
import logging
54
from collections import defaultdict
65
from collections.abc import Iterable
76
from typing import TYPE_CHECKING
87

9-
from packaging.specifiers import InvalidSpecifier
10-
from packaging.specifiers import SpecifierSet
11-
from packaging.version import InvalidVersion
12-
from packaging.version import Version
13-
148
from variantlib.models.variant import VariantDescription
159
from variantlib.models.variant import VariantFeature
1610
from variantlib.models.variant import VariantProperty
@@ -227,34 +221,8 @@ def _should_include(vdesc: VariantDescription) -> bool:
227221
return False
228222

229223
for property_value in property_values:
230-
try:
231-
# If `property_value` is not a `SpecifierSet` valid value:
232-
# => will raise InvalidSpecifier
233-
vspec = SpecifierSet(property_value)
234-
235-
# 1. Tentatively convert `variant_prop` to `Version`
236-
# Not all/any values given by the Provider Plugins will be
237-
# convertible to `Version`, so we use `contextlib.suppress`.
238-
# 2. Check if the `Version` is in the `SpecifierSet`.
239-
for variant_prop in allowed_props:
240-
with contextlib.suppress(InvalidVersion):
241-
if Version(variant_prop) in vspec:
242-
# We found one or more allowed properties that match
243-
# the specifier, so we can include this variant.
244-
break
245-
else:
246-
continue
247-
248-
# Match was found, so we can break out of the loop.
224+
if property_value in allowed_props:
249225
break
250-
251-
except InvalidSpecifier:
252-
# We treat the property value as a simple string
253-
# and check if it is in the allowed properties.
254-
# If it is, we can include this variant.
255-
if property_value in allowed_props:
256-
break
257-
258226
else:
259227
# We never broke out of the loop, meaning no allowed property
260228
# matched. Consequently, we reject this variant.

variantlib/resolver/sorting.py

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

3-
import contextlib
43
import logging
54
import sys
65
from itertools import chain
76
from itertools import groupby
87

9-
from packaging.specifiers import InvalidSpecifier
10-
from packaging.specifiers import SpecifierSet
11-
128
from variantlib.errors import ConfigurationError
139
from variantlib.errors import ValidationError
1410
from variantlib.models.variant import VariantDescription
@@ -204,16 +200,6 @@ def sort_variants_descriptions(
204200
for vdesc in vdescs:
205201
vprops.update(vdesc.properties)
206202

207-
for vprop in vprops:
208-
with contextlib.suppress(InvalidSpecifier):
209-
SpecifierSet(vprop.value)
210-
# NOTE: IF ONE OF THE PROPERTIES IS A VERSION SPECIFIER,
211-
#
212-
# TODO: Implement smthg that makes sense here.
213-
# Temporary sorting - doesn't matter for now
214-
# sort by descending hash to ensure that the null variant is always last
215-
return sorted(vdescs, key=lambda v: v.hexdigest, reverse=True)
216-
217203
# Pre-compute the property hash for the property priorities
218204
# This is used to speed up the sorting process.
219205
# The property_hash is used to compare the `VariantProperty` objects

variantlib/validators/vprop.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)