Skip to content

Commit e895c20

Browse files
committed
Add an API to describe variant using labels
Add a minimal API that lets plugins process the variant description and add short labels that could be used to describe the wheel. The labels are entirely optional -- plugins may not return any, and clients may ignore them. The design also assumes that the client is responsible for choosing how many labels to use before truncating -- though I suppose I'll add a helper function to `variantlib` for that purpose. The design assumes that plugin get complete unfiltered `VariantDescription` -- and therefore also see variant metadata from other plugins. I don't think that's really a problem, though it assumes that the plugin must compare both against provider and key names. At this point, the protocol makes the API mandatory, even if it would only return an empty list unconditionally. Perhaps we should make the function optional somehow instead.
1 parent 368e990 commit e895c20

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

tests/test_plugins.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def get_supported_configs(self) -> Optional[ProviderConfig]:
2323

2424
def get_variant_labels(self, variant_desc: VariantDescription) -> list[str]:
2525
for meta in variant_desc:
26-
if meta.provider == self.__name__ and meta.key == "key1":
26+
if meta.namespace == self.namespace and meta.key == "key1":
2727
return [meta.value.removeprefix("val")]
2828
return []
2929

@@ -42,17 +42,24 @@ def get_supported_configs(self) -> Optional[ProviderConfig]:
4242
)
4343

4444
def get_variant_labels(self, variant_desc: VariantDescription) -> list[str]:
45-
if VariantMeta(self.__name__, "key3", "val3a") in variant_desc:
45+
if VariantMeta(self.namespace, "key3", "val3a") in variant_desc:
4646
return ["sec"]
4747
return []
4848

4949

5050
class MockedPluginC(PluginBase):
51-
namespace = "incompatible_plugin"
51+
namespace = "other_plugin"
5252

5353
def get_supported_configs(self) -> Optional[ProviderConfig]:
5454
return None
5555

56+
def get_variant_labels(self, variant_desc: VariantDescription) -> list[str]:
57+
ret = []
58+
for meta in variant_desc:
59+
if meta.namespace == self.namespace and meta.value == "on":
60+
ret.append(meta.key)
61+
return ret
62+
5663

5764
class ClashingPlugin(PluginBase):
5865
namespace = "test_plugin"
@@ -63,7 +70,7 @@ def get_supported_configs(self) -> Optional[ProviderConfig]:
6370
def get_variant_labels(self, variant_desc: VariantDescription) -> list[str]:
6471
ret = []
6572
for meta in variant_desc:
66-
if meta.provider == self.__name__ and meta.value == "on":
73+
if meta.namespace == self.namespace and meta.value == "on":
6774
ret.append(meta.key)
6875
return ret
6976

0 commit comments

Comments
 (0)