Skip to content

Commit 008ba22

Browse files
committed
Remove the old get_build_setup() API
Remove the `get_build_setup()` API. We need to replace it with something more flexible. I'm going to prototype it directly between the plugins and numpy first, and see how that works out.
1 parent 7cb145f commit 008ba22

File tree

5 files changed

+0
-133
lines changed

5 files changed

+0
-133
lines changed

tests/mocked_plugins.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,6 @@ def get_supported_configs(
3939
VariantFeatureConfig("name2", ["val2a", "val2b", "val2c"]),
4040
]
4141

42-
def get_build_setup(
43-
self, properties: frozenset[VariantPropertyType]
44-
) -> dict[str, list[str]]:
45-
for prop in properties:
46-
assert prop.namespace == self.namespace
47-
if prop.feature == "name1":
48-
return {
49-
"cflags": [f"-march={prop.value}"],
50-
"cxxflags": [f"-march={prop.value}"],
51-
"ldflags": ["-Wl,--test-flag"],
52-
}
53-
return {}
54-
5542

5643
MyVariantFeatureConfig = namedtuple("MyVariantFeatureConfig", ("name", "values"))
5744

@@ -108,21 +95,6 @@ def get_supported_configs(
10895
assert known_properties is None
10996
return []
11097

111-
def get_build_setup(
112-
self, properties: frozenset[VariantPropertyType]
113-
) -> dict[str, list[str]]:
114-
flag_opts = []
115-
116-
for prop in properties:
117-
assert prop.namespace == self.namespace
118-
assert prop.value == "on"
119-
flag_opts.append(f"-m{prop.feature}")
120-
121-
return {
122-
"cflags": flag_opts,
123-
"cxxflags": flag_opts,
124-
}
125-
12698

12799
class IndirectPath:
128100
class MoreIndirection:

tests/plugins/test_loader.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616
from variantlib.constants import VARIANT_INFO_PROVIDER_PLUGIN_API_KEY
1717
from variantlib.constants import VARIANTS_JSON_VARIANT_DATA_KEY
1818
from variantlib.errors import PluginError
19-
from variantlib.errors import PluginMissingError
2019
from variantlib.errors import ValidationError
2120
from variantlib.models.provider import ProviderConfig
2221
from variantlib.models.provider import VariantFeatureConfig
23-
from variantlib.models.variant import VariantDescription
2422
from variantlib.models.variant import VariantProperty
2523
from variantlib.models.variant import VariantValidationResult
2624
from variantlib.models.variant_info import ProviderInfo
@@ -338,46 +336,6 @@ def test_namespace_instantiation_returns_incorrect_type(
338336
pass
339337

340338

341-
def test_get_build_setup(
342-
mocked_plugin_loader: BasePluginLoader,
343-
) -> None:
344-
variant_desc = VariantDescription(
345-
[
346-
VariantProperty("test_namespace", "name1", "val1b"),
347-
VariantProperty("second_namespace", "name3", "val3c"),
348-
VariantProperty("incompatible_namespace", "flag1", "on"),
349-
VariantProperty("incompatible_namespace", "flag4", "on"),
350-
]
351-
)
352-
353-
# flag order may depend on (random) property ordering
354-
assert {
355-
k: sorted(v)
356-
for k, v in mocked_plugin_loader.get_build_setup(variant_desc).items()
357-
} == {
358-
"cflags": ["-march=val1b", "-mflag1", "-mflag4"],
359-
"cxxflags": ["-march=val1b", "-mflag1", "-mflag4"],
360-
"ldflags": ["-Wl,--test-flag"],
361-
}
362-
363-
364-
def test_get_build_setup_missing_plugin(
365-
mocked_plugin_loader: BasePluginLoader,
366-
) -> None:
367-
variant_desc = VariantDescription(
368-
[
369-
VariantProperty("test_namespace", "name1", "val1b"),
370-
VariantProperty("missing_plugin", "name", "val"),
371-
]
372-
)
373-
374-
with pytest.raises(
375-
PluginMissingError,
376-
match=r"No plugin found for namespace 'missing_plugin'",
377-
):
378-
assert mocked_plugin_loader.get_build_setup(variant_desc)
379-
380-
381339
def test_namespaces(
382340
mocked_plugin_loader: BasePluginLoader,
383341
) -> None:
@@ -588,7 +546,6 @@ def test_empty_plugin_list(loader_call: Callable[[], BasePluginLoader]) -> None:
588546
assert loader.namespaces == []
589547
assert loader.get_supported_configs() == {}
590548
assert loader.validate_properties([]) == VariantValidationResult({})
591-
assert loader.get_build_setup(VariantDescription([])) == {}
592549

593550

594551
@pytest.mark.parametrize(

variantlib/plugins/_subprocess.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -158,33 +158,6 @@ def main() -> int:
158158
else:
159159
results.extend((property_to_dict(vprop), None) for vprop in p_props)
160160
retval = {command: results}
161-
elif command == "get_build_setup":
162-
assert command_args
163-
assert "properties" in command_args
164-
ret_env: dict[str, list[str]] = {}
165-
for plugin, p_props in group_properties_by_plugin(
166-
command_args["properties"], namespace_map
167-
):
168-
if plugin is None:
169-
raise KeyError(
170-
f"No provider for namespace {next(iter(p_props)).namespace}"
171-
)
172-
if hasattr(plugin, "get_build_setup"):
173-
plugin_env = plugin.get_build_setup(p_props)
174-
175-
try:
176-
validate_type(plugin_env, dict[str, list[str]])
177-
except ValidationError as err:
178-
raise TypeError(
179-
f"Provider {plugin.namespace}, get_build_setup() "
180-
f"method returned incorrect type. {err}"
181-
) from None
182-
else:
183-
plugin_env = {}
184-
185-
for k, v in plugin_env.items():
186-
ret_env.setdefault(k, []).extend(v)
187-
retval = {command: ret_env}
188161
else:
189162
raise ValueError(f"Invalid command: {command}")
190163

variantlib/plugins/loader.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from variantlib.constants import VALIDATION_PROVIDER_PLUGIN_API_REGEX
2121
from variantlib.errors import NoPluginFoundError
2222
from variantlib.errors import PluginError
23-
from variantlib.errors import PluginMissingError
2423
from variantlib.models.provider import ProviderConfig
2524
from variantlib.models.provider import VariantFeatureConfig
2625
from variantlib.models.variant import VariantProperty
@@ -30,7 +29,6 @@
3029
if TYPE_CHECKING:
3130
from types import TracebackType
3231

33-
from variantlib.models.variant import VariantDescription
3432
from variantlib.models.variant_info import ProviderInfo
3533
from variantlib.models.variant_info import VariantInfo
3634
from variantlib.protocols import VariantNamespace
@@ -239,33 +237,6 @@ def validate_properties(
239237
{VariantProperty(**vprop): result for vprop, result in results}
240238
)
241239

242-
def get_build_setup(self, variant_desc: VariantDescription) -> Any:
243-
"""Get build variables for a variant made of specified properties"""
244-
self._check_plugins_loaded()
245-
assert self._namespace_map is not None
246-
247-
namespaces = {vprop.namespace for vprop in variant_desc.properties}
248-
try:
249-
plugin_apis = [
250-
self.plugin_api_values[namespace] for namespace in namespaces
251-
]
252-
except KeyError as err:
253-
raise PluginMissingError(f"No plugin found for namespace {err}") from None
254-
255-
if not plugin_apis:
256-
return {}
257-
258-
return self._call_subprocess(
259-
plugin_apis,
260-
{
261-
"get_build_setup": {
262-
"properties": [
263-
dataclasses.asdict(vprop) for vprop in variant_desc.properties
264-
]
265-
}
266-
},
267-
)["get_build_setup"]
268-
269240
@property
270241
def plugin_api_values(self) -> dict[str, str]:
271242
self._check_plugins_loaded()

variantlib/protocols.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,3 @@ def get_supported_configs(
113113
def validate_property(self, variant_property: VariantPropertyType) -> bool:
114114
"""Validate variant property, returns True if it's valid"""
115115
raise NotImplementedError
116-
117-
def get_build_setup(
118-
self, properties: frozenset[VariantPropertyType]
119-
) -> dict[str, list[str]]:
120-
"""Get build variables for a variant made of specified properties"""
121-
return {}

0 commit comments

Comments
 (0)