Skip to content

Commit 73887f3

Browse files
authored
Remove leftovers from when namespace priorities were configured via variantlib (#129)
* Make `namespace_priorities` parameter non-optional Signed-off-by: Michał Górny <[email protected]> * Make no namespace-priorities an error with one namespace too Signed-off-by: Michał Górny <[email protected]> * Remove obsolete `ConfigurationError` message for missing ns prios Namespace priorities are now part of package metadata, so remove the misleading error telling people to configure variantlib. Signed-off-by: Michał Górny <[email protected]> * Fix test flakiness Signed-off-by: Michał Górny <[email protected]> --------- Signed-off-by: Michał Górny <[email protected]>
1 parent a54471a commit 73887f3

File tree

4 files changed

+15
-31
lines changed

4 files changed

+15
-31
lines changed

tests/resolver/test_lib.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import pytest
88
from deepdiff import DeepDiff
99
from deepdiff.operator import BaseOperator
10-
from variantlib.errors import ConfigurationError
1110
from variantlib.errors import ValidationError
1211
from variantlib.models.variant import VariantDescription
1312
from variantlib.models.variant import VariantFeature
@@ -609,6 +608,7 @@ def test_sort_and_filter_supported_variants_validation_errors(
609608
sort_and_filter_supported_variants(
610609
vdescs=vdescs,
611610
supported_vprops=vprops, # type: ignore[arg-type]
611+
namespace_priorities=["a"],
612612
feature_priorities=feature_priorities,
613613
)
614614

@@ -617,8 +617,11 @@ def test_sort_and_filter_supported_variants_validation_errors_with_no_priority(
617617
vdescs: list[VariantDescription], vprops: list[VariantProperty]
618618
) -> None:
619619
# This one specifies no ordering/priority => can't sort
620-
with pytest.raises(ConfigurationError, match="The variant environment needs"):
620+
with pytest.raises(
621+
ValidationError, match=r"Missing namespace_priorities for namespaces"
622+
):
621623
sort_and_filter_supported_variants(
622624
vdescs=vdescs,
623625
supported_vprops=vprops,
626+
namespace_priorities=[],
624627
)

tests/resolver/test_sorting.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from typing import Any
55

66
import pytest
7-
from variantlib.errors import ConfigurationError
87
from variantlib.errors import ValidationError
98
from variantlib.models.variant import VariantDescription
109
from variantlib.models.variant import VariantFeature
@@ -111,21 +110,20 @@ def test_get_namespace_priorities() -> None:
111110
def test_negative_get_namespace_priorities() -> None:
112111
vprop = VariantProperty(namespace="omnicorp", feature="no_exist", value="value")
113112

114-
assert get_namespace_priorities(vprop, None) == sys.maxsize
115113
assert get_namespace_priorities(vprop, []) == sys.maxsize
116114
assert get_namespace_priorities(vprop, ["other_corp"]) == sys.maxsize
117115

118116

119117
@pytest.mark.parametrize(
120118
("vprop", "namespace_priorities"),
121119
[
122-
("not a `VariantProperty`", None),
120+
("not a `VariantProperty`", []),
123121
(VariantProperty("a", "b", "c"), "not a list or None"),
124122
(VariantProperty("a", "b", "c"), [{"not a str": True}]),
125123
],
126124
)
127125
def test_get_namespace_priorities_validation_error(
128-
vprop: VariantProperty, namespace_priorities: list[str] | None
126+
vprop: VariantProperty, namespace_priorities: list[str]
129127
) -> None:
130128
with pytest.raises(ValidationError):
131129
get_namespace_priorities(vprop=vprop, namespace_priorities=namespace_priorities)
@@ -208,10 +206,10 @@ def test_sort_variant_properties_validation_error(
208206

209207

210208
def test_sort_variant_properties_configuration_error() -> None:
211-
with pytest.raises(ConfigurationError):
209+
with pytest.raises(ValidationError):
212210
sort_variant_properties(
213211
vprops=[VariantProperty("a", "b", "c"), VariantProperty("x", "y", "z")],
214-
namespace_priorities=None,
212+
namespace_priorities=[],
215213
feature_priorities=None,
216214
property_priorities=None,
217215
)

variantlib/resolver/lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def inject_abi_dependency(
179179
def sort_and_filter_supported_variants(
180180
vdescs: list[VariantDescription],
181181
supported_vprops: list[VariantProperty],
182-
namespace_priorities: list[VariantNamespace] | None = None,
182+
namespace_priorities: list[VariantNamespace],
183183
feature_priorities: dict[VariantNamespace, list[VariantFeatureName]] | None = None,
184184
property_priorities: dict[
185185
VariantNamespace, dict[VariantFeatureName, list[VariantFeatureValue]]

variantlib/resolver/sorting.py

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from itertools import chain
88
from itertools import groupby
99

10-
from variantlib.errors import ConfigurationError
1110
from variantlib.errors import ValidationError
1211
from variantlib.models.variant import VariantDescription
1312
from variantlib.models.variant import VariantProperty
@@ -79,7 +78,7 @@ def get_feature_priorities(
7978

8079
def get_namespace_priorities(
8180
vprop: VariantProperty,
82-
namespace_priorities: list[VariantNamespace] | None,
81+
namespace_priorities: list[VariantNamespace],
8382
) -> int:
8483
"""
8584
Get the namespace priority of a `VariantProperty` object.
@@ -90,8 +89,6 @@ def get_namespace_priorities(
9089
"""
9190
validate_type(vprop, VariantProperty)
9291

93-
if namespace_priorities is None:
94-
return sys.maxsize
9592
validate_type(namespace_priorities, list[str])
9693

9794
# if not present push at the end
@@ -103,7 +100,7 @@ def get_namespace_priorities(
103100

104101
def sort_variant_properties(
105102
vprops: list[VariantProperty],
106-
namespace_priorities: list[VariantNamespace] | None,
103+
namespace_priorities: list[VariantNamespace],
107104
feature_priorities: dict[VariantNamespace, list[VariantFeatureName]] | None = None,
108105
property_priorities: dict[
109106
VariantNamespace, dict[VariantFeatureName, list[VariantFeatureValue]]
@@ -120,9 +117,7 @@ def sort_variant_properties(
120117
:return: Sorted list of `VariantProperty` objects.
121118
"""
122119
validate_type(vprops, list[VariantProperty])
123-
124-
if namespace_priorities is not None:
125-
validate_type(namespace_priorities, list[VariantNamespace])
120+
validate_type(namespace_priorities, list[VariantNamespace])
126121

127122
if feature_priorities is not None:
128123
validate_type(
@@ -134,22 +129,10 @@ def sort_variant_properties(
134129
dict[VariantNamespace, dict[VariantFeatureName, list[VariantFeatureValue]]],
135130
)
136131

137-
error_message = (
138-
"The variant environment needs to be (re)configured, please execute "
139-
"`variantlib config setup` and re-run your command."
140-
)
141-
142132
found_namespaces = {vprop.namespace for vprop in vprops}
143133

144-
if namespace_priorities is None or not namespace_priorities:
145-
if len(found_namespaces) > 1:
146-
raise ConfigurationError(error_message)
147-
148-
# if there is only one namespace, use it as the default
149-
namespace_priorities = list(found_namespaces)
150-
151-
elif len(found_namespaces.difference(namespace_priorities)) > 0:
152-
raise ConfigurationError(error_message)
134+
if missing := found_namespaces.difference(namespace_priorities):
135+
raise ValidationError(f"Missing namespace_priorities for namespaces {missing}")
153136

154137
# 1. Reorder properties according to namespace priorities.
155138
sorted_by_namespace = sorted(

0 commit comments

Comments
 (0)