Skip to content

Commit

Permalink
feat: support generic platforms
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming committed Sep 14, 2024
1 parent d2ccd88 commit 9989d64
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/dep_logic/tags/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,11 @@ class Haiku(Os):

def __str__(self) -> str:
return f"haiku_{self.release}"


@dataclass(frozen=True)
class Generic(Os):
name: str

def __str__(self) -> str:
return self.name.lower()
10 changes: 7 additions & 3 deletions src/dep_logic/tags/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ def parse(cls, platform: str) -> Self:
else: # os_name == "musllinux"
return cls(os.Musllinux(int(major), int(minor)), Arch.parse(arch))
else:
raise PlatformError(
f"Unsupported platform {platform}, expected one of {cls.choices()}"
)
os_, arch = platform.split("_", 1)
try:
return cls(os.Generic(os_), Arch.parse(arch))
except ValueError as e:
raise PlatformError(f"Unsupported platform {platform}") from e

def __str__(self) -> str:
if isinstance(self.os, os.Windows) and self.arch == Arch.X86_64:
Expand Down Expand Up @@ -228,6 +230,8 @@ def compatible_tags(self) -> list[str]:
release = f"{major_ver - 3}_{other}"
arch = f"{arch}_64bit"
platform_tags.append(f"solaris_{release}_{arch}")
elif isinstance(os_, os.Generic):
platform_tags.append(f"{os_}_{arch}")
else:
raise PlatformError(
f"Unsupported operating system and architecture combination: {os_} {arch}"
Expand Down
5 changes: 5 additions & 0 deletions tests/tags/test_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ def test_platform_tags_musl():
Platform(os.Macos(12, 0), Arch.X86_64),
"macos_12_0_x86_64",
),
(
"mingw_x86_64",
Platform(os.Generic("mingw"), Arch.X86_64),
"mingw_x86_64",
),
],
)
def test_parse_platform(text, expected, normalized):
Expand Down

0 comments on commit 9989d64

Please sign in to comment.