Skip to content

Commit 3fcb8cc

Browse files
authored
Support custom variant labels (#108)
* Initial support for custom variant labels Add initial support for using wheels with non-variant hash labels. This mostly means replacing "variant hash" with "variant label" in a bunch of places, updating the regex and removing validation where we permit a different label. * Permit `_` in labels * Add custom label support to `make-variant` command * Detect duplicate variants in `generate-index-json` * Sort variant collision output for consistency and readability * Update `get_variants_by_priority()` for labels Rename the `get_variant_hashes_by_priority()` function to `get_variants_by_priority()`, and update them to return variant labels rather than hashes. For the time being, we just use a reverse map from hashes to labels -- but it may be cleaner to start storing labels in `VariantDescription`. * Test null variant with custom label as well * Remove tests for custom label of null variants * make-vairant: block --variant-label + --null-variant, add more tests * Add a `NULL_VARIANT_HASH` constant * Validate null variant label in `variants.json` * Avoid labeling null variant in tests
1 parent 2b22d8c commit 3fcb8cc

28 files changed

+302
-118
lines changed

tests/artifacts/test-package/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@ build: clean ## builds source and wheel package
3939
-p "installable_plugin :: feat1 :: val1c" \
4040
-p "installable_plugin :: feat2 :: val2b"
4141

42+
flit build --format wheel \
43+
-p "installable_plugin :: feat1 :: val1c" \
44+
--variant-label=foo
45+
46+
flit build --format wheel \
47+
-p "installable_plugin :: feat2 :: val2b" \
48+
--variant-label=bar
49+
4250
variantlib generate-index-json -d dist/
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

tests/artifacts/test-package/dist/test_package-0-variants.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,26 @@
3838
]
3939
}
4040
},
41+
"bar": {
42+
"installable_plugin": {
43+
"feat2": [
44+
"val2b"
45+
]
46+
}
47+
},
4148
"fbe82642": {
4249
"installable_plugin": {
4350
"feat2": [
4451
"val2b"
4552
]
4653
}
54+
},
55+
"foo": {
56+
"installable_plugin": {
57+
"feat1": [
58+
"val1c"
59+
]
60+
}
4761
}
4862
}
49-
}
63+
}

tests/commands/test_analyze_wheel.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import TYPE_CHECKING
44

55
from variantlib.commands.main import main
6+
from variantlib.constants import NULL_VARIANT_HASH
67

78
if TYPE_CHECKING:
89
import pytest
@@ -32,13 +33,15 @@ def test_analyze_wheel_null_variant(
3233
[
3334
"analyze-wheel",
3435
"-i",
35-
"tests/artifacts/test-package/dist/test_package-0-py3-none-any-00000000.whl",
36+
"tests/artifacts/test-package/dist/test_package-0-py3-none-any-"
37+
f"{NULL_VARIANT_HASH}.whl",
3638
]
3739
)
3840
assert (
3941
capsys.readouterr().out
40-
== """\
41-
############################## Variant: `00000000` #############################
42+
== f"""\
43+
############################## Variant: `{NULL_VARIANT_HASH}` \
44+
#############################
4245
################################################################################
4346
"""
4447
)
@@ -64,3 +67,24 @@ def test_analyze_wheel_variant(
6467
################################################################################
6568
"""
6669
)
70+
71+
72+
def test_analyze_wheel_variant_custom_label(
73+
capsys: pytest.CaptureFixture[str],
74+
mocked_entry_points: None,
75+
) -> None:
76+
main(
77+
[
78+
"analyze-wheel",
79+
"-i",
80+
"tests/artifacts/test-package/dist/test_package-0-py3-none-any-foo.whl",
81+
]
82+
)
83+
assert (
84+
capsys.readouterr().out
85+
== """\
86+
############################## Variant: `60567bd9` #############################
87+
installable_plugin :: feat1 :: val1c
88+
################################################################################
89+
"""
90+
)

0 commit comments

Comments
 (0)