Skip to content

Commit 9989d64

Browse files
committed
feat: support generic platforms
Signed-off-by: Frost Ming <[email protected]>
1 parent d2ccd88 commit 9989d64

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/dep_logic/tags/os.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,11 @@ class Haiku(Os):
8282

8383
def __str__(self) -> str:
8484
return f"haiku_{self.release}"
85+
86+
87+
@dataclass(frozen=True)
88+
class Generic(Os):
89+
name: str
90+
91+
def __str__(self) -> str:
92+
return self.name.lower()

src/dep_logic/tags/platform.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ def parse(cls, platform: str) -> Self:
7272
else: # os_name == "musllinux"
7373
return cls(os.Musllinux(int(major), int(minor)), Arch.parse(arch))
7474
else:
75-
raise PlatformError(
76-
f"Unsupported platform {platform}, expected one of {cls.choices()}"
77-
)
75+
os_, arch = platform.split("_", 1)
76+
try:
77+
return cls(os.Generic(os_), Arch.parse(arch))
78+
except ValueError as e:
79+
raise PlatformError(f"Unsupported platform {platform}") from e
7880

7981
def __str__(self) -> str:
8082
if isinstance(self.os, os.Windows) and self.arch == Arch.X86_64:
@@ -228,6 +230,8 @@ def compatible_tags(self) -> list[str]:
228230
release = f"{major_ver - 3}_{other}"
229231
arch = f"{arch}_64bit"
230232
platform_tags.append(f"solaris_{release}_{arch}")
233+
elif isinstance(os_, os.Generic):
234+
platform_tags.append(f"{os_}_{arch}")
231235
else:
232236
raise PlatformError(
233237
f"Unsupported operating system and architecture combination: {os_} {arch}"

tests/tags/test_platform.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ def test_platform_tags_musl():
342342
Platform(os.Macos(12, 0), Arch.X86_64),
343343
"macos_12_0_x86_64",
344344
),
345+
(
346+
"mingw_x86_64",
347+
Platform(os.Generic("mingw"), Arch.X86_64),
348+
"mingw_x86_64",
349+
),
345350
],
346351
)
347352
def test_parse_platform(text, expected, normalized):

0 commit comments

Comments
 (0)