Skip to content

Commit def0563

Browse files
authored
fix: constrain feature platforms in schema (#2055)
1 parent 9d0be8f commit def0563

File tree

4 files changed

+72
-90
lines changed

4 files changed

+72
-90
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"$schema" = "./../../schema.json"
2+
3+
4+
[project]
5+
name = "badplatform"
6+
platforms = ["linux-64"]
7+
8+
[feature.foo]
9+
platforms = ["not-a-platform"]

schema/model.py

+26-20
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,31 @@
3434
GitUrl = Annotated[
3535
str, StringConstraints(pattern=r"((git|ssh|http(s)?)|(git@[\w\.]+))(:(\/\/)?)([\w\.@:\/\\-~]+)")
3636
]
37-
Platform = (
38-
Literal["linux-32"]
39-
| Literal["linux-64"]
40-
| Literal["linux-aarch64"]
41-
| Literal["linux-armv6l"]
42-
| Literal["linux-armv7l"]
43-
| Literal["linux-ppc64le"]
44-
| Literal["linux-ppc64"]
45-
| Literal["linux-s390x"]
46-
| Literal["linux-riscv32"]
47-
| Literal["linux-riscv64"]
48-
| Literal["osx-64"]
49-
| Literal["osx-arm64"]
50-
| Literal["win-32"]
51-
| Literal["win-64"]
52-
| Literal["win-arm64"]
53-
| Literal["emscripten-wasm32"]
54-
| Literal["wasi-wasm32"]
55-
)
37+
38+
39+
class Platform(str, Enum):
40+
"""A supported operating system and processor architecture pair."""
41+
42+
emscripten_wasm32 = "emscripten-wasm32"
43+
linux_32 = "linux-32"
44+
linux_64 = "linux-64"
45+
linux_aarch64 = "linux-aarch64"
46+
linux_armv6l = "linux-armv6l"
47+
linux_armv7l = "linux-armv7l"
48+
linux_ppc64 = "linux-ppc64"
49+
linux_ppc64le = "linux-ppc64le"
50+
linux_riscv32 = "linux-riscv32"
51+
linux_riscv64 = "linux-riscv64"
52+
linux_s390x = "linux-s390x"
53+
noarch = "noarch"
54+
osx_64 = "osx-64"
55+
osx_arm64 = "osx-arm64"
56+
unknown = "unknown"
57+
wasi_wasm32 = "wasi-wasm32"
58+
win_32 = "win-32"
59+
win_64 = "win-64"
60+
win_arm64 = "win-arm64"
61+
zos_z = "zos-z"
5662

5763

5864
class StrictBaseModel(BaseModel):
@@ -424,7 +430,7 @@ class Feature(StrictBaseModel):
424430
"- 'strict': only take the package from the channel it exist in first."
425431
"- 'disabled': group all dependencies together as if there is no channel difference.",
426432
)
427-
platforms: list[NonEmptyStr] | None = Field(
433+
platforms: list[Platform] | None = Field(
428434
None,
429435
description="The platforms that the feature supports: a union of all features combined in one environment is used for the environment.",
430436
)

schema/schema.json

+29-55
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,7 @@
391391
"description": "The platforms that the feature supports: a union of all features combined in one environment is used for the environment.",
392392
"type": "array",
393393
"items": {
394-
"type": "string",
395-
"minLength": 1
394+
"$ref": "#/$defs/Platform"
396395
}
397396
},
398397
"pypi-dependencies": {
@@ -632,6 +631,33 @@
632631
}
633632
}
634633
},
634+
"Platform": {
635+
"title": "Platform",
636+
"description": "A supported operating system and processor architecture pair.",
637+
"type": "string",
638+
"enum": [
639+
"emscripten-wasm32",
640+
"linux-32",
641+
"linux-64",
642+
"linux-aarch64",
643+
"linux-armv6l",
644+
"linux-armv7l",
645+
"linux-ppc64",
646+
"linux-ppc64le",
647+
"linux-riscv32",
648+
"linux-riscv64",
649+
"linux-s390x",
650+
"noarch",
651+
"osx-64",
652+
"osx-arm64",
653+
"unknown",
654+
"wasi-wasm32",
655+
"win-32",
656+
"win-64",
657+
"win-arm64",
658+
"zos-z"
659+
]
660+
},
635661
"Project": {
636662
"title": "Project",
637663
"description": "The project's metadata information.",
@@ -744,59 +770,7 @@
744770
"description": "The platforms that the project supports",
745771
"type": "array",
746772
"items": {
747-
"anyOf": [
748-
{
749-
"const": "linux-32"
750-
},
751-
{
752-
"const": "linux-64"
753-
},
754-
{
755-
"const": "linux-aarch64"
756-
},
757-
{
758-
"const": "linux-armv6l"
759-
},
760-
{
761-
"const": "linux-armv7l"
762-
},
763-
{
764-
"const": "linux-ppc64le"
765-
},
766-
{
767-
"const": "linux-ppc64"
768-
},
769-
{
770-
"const": "linux-s390x"
771-
},
772-
{
773-
"const": "linux-riscv32"
774-
},
775-
{
776-
"const": "linux-riscv64"
777-
},
778-
{
779-
"const": "osx-64"
780-
},
781-
{
782-
"const": "osx-arm64"
783-
},
784-
{
785-
"const": "win-32"
786-
},
787-
{
788-
"const": "win-64"
789-
},
790-
{
791-
"const": "win-arm64"
792-
},
793-
{
794-
"const": "emscripten-wasm32"
795-
},
796-
{
797-
"const": "wasi-wasm32"
798-
}
799-
]
773+
"$ref": "#/$defs/Platform"
800774
}
801775
},
802776
"pypi-options": {

schema/test_manifest.py

+8-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import glob
22
import json
33
import tomllib
4+
from pathlib import Path
45

56
import pytest
67
import jsonschema
78

9+
HERE = Path(__file__).parent
10+
EXAMPLES = HERE / "examples"
11+
VALID = {ex.stem: ex for ex in (EXAMPLES / "valid").glob("*.toml")}
12+
INVALID = {ex.stem: ex for ex in (EXAMPLES / "invalid").glob("*.toml")}
813

9-
@pytest.fixture(
10-
scope="module",
11-
params=[
12-
"minimal",
13-
"full",
14-
],
15-
)
14+
15+
@pytest.fixture(scope="module", params=VALID)
1616
def valid_manifest(request) -> str:
1717
manifest_name = request.param
1818
with open(f"examples/valid/{manifest_name}.toml") as f:
@@ -21,14 +21,7 @@ def valid_manifest(request) -> str:
2121
return manifest_toml
2222

2323

24-
@pytest.fixture(
25-
scope="module",
26-
params=[
27-
"empty",
28-
"no_channel",
29-
"bad_env_variable",
30-
],
31-
)
24+
@pytest.fixture(scope="module", params=INVALID)
3225
def invalid_manifest(request) -> str:
3326
manifest_name = request.param
3427
with open(f"examples/invalid/{manifest_name}.toml") as f:

0 commit comments

Comments
 (0)