Skip to content

Commit cca81ad

Browse files
authored
plugins: Add a public name property and use it as primary identifier (#14)
* Add a public `name` property to plugin classes Add a public `name` property to plugin classes, to replace the private `__name__` property, and use it to identify plugins instead of the entry point name. This is the first step towards cleaning up the current naming confusion. * Use plugin name rather than entry point to detect duplicates * Fix loading plugins with no distribution metadata * Rename name/provider to namespace * Throw an error if two plugins use the same namespace
1 parent d25e3db commit cca81ad

12 files changed

+367
-312
lines changed

tests/artifacts/expected.json

+134-134
Large diffs are not rendered by default.

tests/test_combinations.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
@pytest.fixture(scope="session")
2222
def configs():
2323
config_custom_hw = ProviderConfig(
24-
provider="custom_hw",
24+
namespace="custom_hw",
2525
configs=[
2626
KeyConfig(key="driver_version", values=["1.3", "1.2", "1.1", "1"]),
2727
KeyConfig(key="hw_architecture", values=["3.4", "3"]),
2828
],
2929
)
3030

3131
config_networking = ProviderConfig(
32-
provider="networking",
32+
namespace="networking",
3333
configs=[
3434
KeyConfig(key="speed", values=["10GBPS", "1GBPS", "100MBPS"]),
3535
],
@@ -59,7 +59,7 @@ def desc_to_json(desc_list: list[VariantDescription]) -> Generator:
5959
for desc in shuffled_desc_list:
6060
variant_dict = {}
6161
for variant_meta in desc:
62-
provider_dict = variant_dict.setdefault(variant_meta.provider, {})
62+
provider_dict = variant_dict.setdefault(variant_meta.namespace, {})
6363
provider_dict[variant_meta.key] = variant_meta.value
6464
yield (desc.hexdigest, variant_dict)
6565

@@ -75,24 +75,24 @@ def test_filtered_sorted_variants_roundtrip(configs):
7575
@example(
7676
[
7777
ProviderConfig(
78-
provider="A",
78+
namespace="A",
7979
configs=[
8080
KeyConfig(key="A1", values=["x"]),
8181
KeyConfig(key="A2", values=["x"]),
8282
],
8383
),
84-
ProviderConfig(provider="B", configs=[KeyConfig(key="B1", values=["x"])]),
85-
ProviderConfig(provider="C", configs=[KeyConfig(key="C1", values=["x"])]),
84+
ProviderConfig(namespace="B", configs=[KeyConfig(key="B1", values=["x"])]),
85+
ProviderConfig(namespace="C", configs=[KeyConfig(key="C1", values=["x"])]),
8686
]
8787
)
8888
@given(
8989
st.lists(
9090
min_size=1,
9191
max_size=3,
92-
unique_by=lambda provider_cfg: provider_cfg.provider,
92+
unique_by=lambda provider_cfg: provider_cfg.namespace,
9393
elements=st.builds(
9494
ProviderConfig,
95-
provider=st.text(
95+
namespace=st.text(
9696
string.ascii_letters + string.digits + "_", min_size=1, max_size=64
9797
),
9898
configs=st.lists(

tests/test_config.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ def test_provider_config_creation_valid():
1616
key_config_1 = KeyConfig(key="attr_nameA", values=["7", "4", "8", "12"])
1717
key_config_2 = KeyConfig(key="attr_nameB", values=["3", "7", "2", "18", "22"])
1818
provider_config = ProviderConfig(
19-
provider="provider_name", configs=[key_config_1, key_config_2]
19+
namespace="provider_name", configs=[key_config_1, key_config_2]
2020
)
2121

22-
assert provider_config.provider == "provider_name"
22+
assert provider_config.namespace == "provider_name"
2323
assert len(provider_config.configs) == 2
2424
assert provider_config.configs[0].key == "attr_nameA"
2525
assert provider_config.configs[1].key == "attr_nameB"
@@ -33,7 +33,7 @@ def test_duplicate_key_config():
3333
with pytest.raises(
3434
ValueError, match="Duplicate `KeyConfig` for key='attr_nameA' found."
3535
):
36-
ProviderConfig(provider="provider_name", configs=[key_config_1, key_config_2])
36+
ProviderConfig(namespace="provider_name", configs=[key_config_1, key_config_2])
3737

3838

3939
def test_empty_values_list_in_key_config():
@@ -69,34 +69,34 @@ def test_invalid_values_type_in_key_config():
6969
) # Expecting a list for `values`
7070

7171

72-
def test_provider_config_invalid_provider_type():
73-
"""Test that an invalid provider type raises a validation error."""
72+
def test_provider_config_invalid_namespace_type():
73+
"""Test that an invalid namespace type raises a validation error."""
7474
with pytest.raises(TypeError):
7575
ProviderConfig(
76-
provider=1,
76+
namespace=1,
7777
configs=[KeyConfig(key="attr_nameA", values=["7", "4", "8", "12"])],
7878
)
7979

8080

8181
def test_provider_config_invalid_configs_type():
8282
"""Test that an invalid configs type raises a validation error."""
8383
with pytest.raises(TypeError):
84-
ProviderConfig(provider="provider_name", configs="not_a_list_of_key_configs")
84+
ProviderConfig(namespace="provider_name", configs="not_a_list_of_key_configs")
8585

8686

8787
def test_provider_config_invalid_key_type_in_configs():
8888
"""Test that invalid `KeyConfig` inside `ProviderConfig` raises an error."""
8989
with pytest.raises(TypeError):
9090
ProviderConfig(
91-
provider="provider_name",
91+
namespace="provider_name",
9292
configs=[{"key": "attr_nameA", "values": ["7", "4", "8", "12"]}],
9393
)
9494

9595

9696
def test_empty_provider_config():
9797
"""Test creation of ProviderConfig with an empty list of KeyConfigs."""
9898
with pytest.raises(AssertionError):
99-
_ = ProviderConfig(provider="provider_name", configs=[])
99+
_ = ProviderConfig(namespace="provider_name", configs=[])
100100

101101

102102
def test_provider_config_invalid_key_config_type():
@@ -105,7 +105,7 @@ def test_provider_config_invalid_key_config_type():
105105

106106
with pytest.raises(TypeError):
107107
ProviderConfig(
108-
provider="provider_name",
108+
namespace="provider_name",
109109
configs=[
110110
KeyConfig(key="attr_nameA", values=["7", "4", "8", "12"]),
111111
SimpleNamespace(key=1, values=["1", "2"]),
@@ -130,11 +130,11 @@ def test_provider_config_repr():
130130
key_config_1 = KeyConfig(key="attr_nameA", values=["7", "4", "8", "12"])
131131
key_config_2 = KeyConfig(key="attr_nameB", values=["3", "7", "2", "18", "22"])
132132
provider_config = ProviderConfig(
133-
provider="provider_name", configs=[key_config_1, key_config_2]
133+
namespace="provider_name", configs=[key_config_1, key_config_2]
134134
)
135135

136136
expected_repr = (
137-
"ProviderConfig(provider='provider_name', "
137+
"ProviderConfig(namespace='provider_name', "
138138
"configs=[KeyConfig(key='attr_nameA', values=['7', '4', '8', '12']), "
139139
"KeyConfig(key='attr_nameB', values=['3', '7', '2', '18', '22'])])"
140140
)

0 commit comments

Comments
 (0)