Skip to content

Commit 4147d47

Browse files
authored
Introduce a VariantDistInfo subclass (and clean up metadata refs) (#100)
* Introduce a `WheelMetadata` subclass Introduce a `WheelMetadata` subclass that provides a more convenient API to access the `variant.json` data from wheels. Notably, it adds verification that the file contains only one variant (with an option to verify its hash against the filename) and properties to query the variant description and hash, and to set it. * Rename `WheelMetadata` to `VariantDistInfo` * Rename `VariantMetadata` to `VariantInfo` * Rename `VARIANT_METADATA_*` to `VARIANT_INFO_*` * Rename `*wheel_metadata.py` to `*variant_dist_info.py` * Rename `models/metadata.py` to `models/variant_info.py` * Remove obsolete `VALIDATION_METADATA*` constants * Update the remaining metadata references and improve consistency
1 parent d8170e4 commit 4147d47

16 files changed

+390
-297
lines changed

tests/plugins/test_loader.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
from variantlib.errors import PluginError
1010
from variantlib.errors import PluginMissingError
1111
from variantlib.errors import ValidationError
12-
from variantlib.models.metadata import ProviderInfo
13-
from variantlib.models.metadata import VariantMetadata
1412
from variantlib.models.provider import ProviderConfig
1513
from variantlib.models.provider import VariantFeatureConfig
1614
from variantlib.models.variant import VariantDescription
1715
from variantlib.models.variant import VariantProperty
16+
from variantlib.models.variant_info import ProviderInfo
17+
from variantlib.models.variant_info import VariantInfo
1818
from variantlib.plugins.loader import BasePluginLoader
1919
from variantlib.plugins.loader import EntryPointPluginLoader
2020
from variantlib.plugins.loader import ListPluginLoader
@@ -377,9 +377,9 @@ def test_load_plugin_invalid_arg() -> None:
377377

378378

379379
@pytest.mark.parametrize(
380-
"metadata",
380+
"variant_info",
381381
[
382-
VariantMetadata(
382+
VariantInfo(
383383
namespace_priorities=[
384384
"test_namespace",
385385
"second_namespace",
@@ -433,8 +433,8 @@ def test_load_plugin_invalid_arg() -> None:
433433
),
434434
],
435435
)
436-
def test_load_plugins_from_metadata(metadata: VariantMetadata) -> None:
437-
with PluginLoader(metadata, use_auto_install=False) as loader:
436+
def test_load_plugins_from_variant_info(variant_info: VariantInfo) -> None:
437+
with PluginLoader(variant_info, use_auto_install=False) as loader:
438438
assert set(loader.namespaces) == {"test_namespace", "second_namespace"}
439439

440440

@@ -448,7 +448,7 @@ def test_load_plugins_from_entry_points(mocked_entry_points: None) -> None:
448448

449449

450450
def test_install_plugin(test_plugin_package_req: str) -> None:
451-
metadata = VariantMetadata(
451+
variant_info = VariantInfo(
452452
namespace_priorities=["installable_plugin"],
453453
providers={
454454
"installable_plugin": ProviderInfo(
@@ -458,12 +458,12 @@ def test_install_plugin(test_plugin_package_req: str) -> None:
458458
},
459459
)
460460

461-
with PluginLoader(metadata, use_auto_install=True, isolated=True) as loader:
461+
with PluginLoader(variant_info, use_auto_install=True, isolated=True) as loader:
462462
assert set(loader.namespaces) == {"installable_plugin"}
463463

464464

465465
def test_no_plugin_api(test_plugin_package_req: str) -> None:
466-
metadata = VariantMetadata(
466+
variant_info = VariantInfo(
467467
namespace_priorities=["installable_plugin"],
468468
providers={
469469
"installable_plugin": ProviderInfo(
@@ -472,5 +472,5 @@ def test_no_plugin_api(test_plugin_package_req: str) -> None:
472472
},
473473
)
474474

475-
with PluginLoader(metadata, use_auto_install=True, isolated=True) as loader:
475+
with PluginLoader(variant_info, use_auto_install=True, isolated=True) as loader:
476476
assert set(loader.namespaces) == {"installable_plugin"}

tests/test_api.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@
3030
from variantlib.constants import VALIDATION_FEATURE_NAME_REGEX
3131
from variantlib.constants import VALIDATION_NAMESPACE_REGEX
3232
from variantlib.constants import VALIDATION_VALUE_REGEX
33-
from variantlib.constants import VARIANT_METADATA_DEFAULT_PRIO_KEY
34-
from variantlib.constants import VARIANT_METADATA_NAMESPACE_KEY
35-
from variantlib.constants import VARIANT_METADATA_PROVIDER_DATA_KEY
36-
from variantlib.constants import VARIANT_METADATA_PROVIDER_PLUGIN_API_KEY
37-
from variantlib.constants import VARIANT_METADATA_PROVIDER_REQUIRES_KEY
33+
from variantlib.constants import VARIANT_INFO_DEFAULT_PRIO_KEY
34+
from variantlib.constants import VARIANT_INFO_NAMESPACE_KEY
35+
from variantlib.constants import VARIANT_INFO_PROVIDER_DATA_KEY
36+
from variantlib.constants import VARIANT_INFO_PROVIDER_PLUGIN_API_KEY
37+
from variantlib.constants import VARIANT_INFO_PROVIDER_REQUIRES_KEY
3838
from variantlib.constants import VARIANTS_JSON_SCHEMA_URL
3939
from variantlib.constants import VARIANTS_JSON_VARIANT_DATA_KEY
4040
from variantlib.constants import VariantsJsonDict
4141
from variantlib.models import provider as pconfig
4242
from variantlib.models import variant as vconfig
4343
from variantlib.models.configuration import VariantConfiguration as VConfigurationModel
44-
from variantlib.models.metadata import ProviderInfo
45-
from variantlib.models.metadata import VariantMetadata
44+
from variantlib.models.variant_info import ProviderInfo
45+
from variantlib.models.variant_info import VariantInfo
4646
from variantlib.pyproject_toml import VariantPyProjectToml
4747
from variantlib.variants_json import VariantsJson
4848

@@ -91,13 +91,13 @@ def test_get_variant_hashes_by_priority_roundtrip(
9191

9292
variants_json = {
9393
"$schema": VARIANTS_JSON_SCHEMA_URL,
94-
VARIANT_METADATA_DEFAULT_PRIO_KEY: {
95-
VARIANT_METADATA_NAMESPACE_KEY: namespace_priorities,
94+
VARIANT_INFO_DEFAULT_PRIO_KEY: {
95+
VARIANT_INFO_NAMESPACE_KEY: namespace_priorities,
9696
},
97-
VARIANT_METADATA_PROVIDER_DATA_KEY: {
97+
VARIANT_INFO_PROVIDER_DATA_KEY: {
9898
namespace: {
99-
VARIANT_METADATA_PROVIDER_PLUGIN_API_KEY: plugin_api,
100-
VARIANT_METADATA_PROVIDER_REQUIRES_KEY: [],
99+
VARIANT_INFO_PROVIDER_PLUGIN_API_KEY: plugin_api,
100+
VARIANT_INFO_PROVIDER_REQUIRES_KEY: [],
101101
}
102102
for namespace, plugin_api in plugin_apis.items()
103103
},
@@ -262,7 +262,7 @@ def test_validation_result_properties() -> None:
262262

263263

264264
def test_validate_variant(mocked_plugin_apis: list[str]) -> None:
265-
vmeta = VariantMetadata(
265+
variant_info = VariantInfo(
266266
namespace_priorities=[
267267
"test_namespace",
268268
"second_namespace",
@@ -296,7 +296,7 @@ def test_validate_variant(mocked_plugin_apis: list[str]) -> None:
296296
VariantProperty("private", "build_type", "debug"),
297297
]
298298
),
299-
metadata=vmeta,
299+
variant_info=variant_info,
300300
use_auto_install=False,
301301
)
302302

@@ -392,7 +392,7 @@ def test_make_variant_dist_info(
392392
VariantProperty("ns2", "f1", "p1"),
393393
]
394394
),
395-
variant_metadata=VariantPyProjectToml(pyproject_toml) # type: ignore[arg-type]
395+
variant_info=VariantPyProjectToml(pyproject_toml) # type: ignore[arg-type]
396396
if pyproject_toml is not None
397397
else None,
398398
)
@@ -402,8 +402,8 @@ def test_make_variant_dist_info(
402402

403403

404404
@pytest.fixture
405-
def common_metadata() -> VariantMetadata:
406-
return VariantMetadata(
405+
def common_variant_info() -> VariantInfo:
406+
return VariantInfo(
407407
namespace_priorities=["test_namespace", "second_namespace"],
408408
providers={
409409
"test_namespace": ProviderInfo(
@@ -440,21 +440,21 @@ def common_metadata() -> VariantMetadata:
440440
],
441441
)
442442
def test_check_variant_supported_dist(
443-
common_metadata: VariantMetadata, vdesc: VariantDescription, expected: bool
443+
common_variant_info: VariantInfo, vdesc: VariantDescription, expected: bool
444444
) -> None:
445-
variant_json = VariantsJson(common_metadata)
445+
variant_json = VariantsJson(common_variant_info)
446446
variant_json.variants[vdesc.hexdigest] = vdesc
447447
assert (
448448
check_variant_supported(
449-
metadata=variant_json, use_auto_install=False, venv_path=None
449+
variant_info=variant_json, use_auto_install=False, venv_path=None
450450
)
451451
is expected
452452
)
453453

454454

455455
def test_check_variant_supported_generic() -> None:
456-
# metadata should only be used to load plugins
457-
vmeta = VariantMetadata(
456+
# variant_info should only be used to load plugins
457+
variant_info = VariantInfo(
458458
namespace_priorities=["test_namespace", "second_namespace"],
459459
providers={
460460
"test_namespace": ProviderInfo(
@@ -469,7 +469,7 @@ def test_check_variant_supported_generic() -> None:
469469
# test the null variant
470470
assert check_variant_supported(
471471
vdesc=VariantDescription(),
472-
metadata=vmeta,
472+
variant_info=variant_info,
473473
use_auto_install=False,
474474
venv_path=None,
475475
)
@@ -482,15 +482,15 @@ def test_check_variant_supported_generic() -> None:
482482
VariantProperty("second_namespace", "name3", "val3a"),
483483
]
484484
),
485-
metadata=vmeta,
485+
variant_info=variant_info,
486486
use_auto_install=False,
487487
venv_path=None,
488488
)
489489

490490
# test an usupported variant
491491
assert not check_variant_supported(
492492
vdesc=VariantDescription([VariantProperty("test_namespace", "name1", "val1c")]),
493-
metadata=vmeta,
493+
variant_info=variant_info,
494494
use_auto_install=False,
495495
venv_path=None,
496496
)

0 commit comments

Comments
 (0)