Skip to content

Commit

Permalink
Add support for the Arm architectures (#458)
Browse files Browse the repository at this point in the history
Update Arch
- Add support for 32bit arm
- Add support for 64bit arm
- Use strings for the defined Enums to simplify printing
Update Platform
- Add support for 32bit arm
- Add support for 64bit arm
- Use strings for the defined Enums to simplify printing
Update EPDPlatform
- Add support for arm64
- Add supprot for converting manylinux1 and manylinux2010 tags
- Simplify several if..else blocks
- Remove legacy property "short"
Remove the legacy LegacyEPDPlatform object
Replace hypothesis with parameterized in tests
Update and augment tests
  • Loading branch information
itziakos authored May 9, 2024
1 parent eaa5f34 commit 740743f
Show file tree
Hide file tree
Showing 9 changed files with 716 additions and 797 deletions.
1 change: 1 addition & 0 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ testfixtures
hypothesis
packaging >= 20.0
distro
parameterized
81 changes: 61 additions & 20 deletions okonomiyaki/platforms/_arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,67 @@

@enum.unique
class ArchitectureKind(enum.Enum):
x86 = 0
x86_64 = 1
x86 = 'x86'
x86_64 = 'x86_64'
arm = 'arm'
arm64 = 'arm64'


_KIND_TO_BITWIDTHS = {
ArchitectureKind.x86: 32,
ArchitectureKind.x86_64: 64,
ArchitectureKind.arm: 32,
ArchitectureKind.arm64: 64,
}
for k in ArchitectureKind.__members__:
assert ArchitectureKind[k] in _KIND_TO_BITWIDTHS

_NORMALIZED_NAMES = {
"x86": ArchitectureKind.x86,
"i386": ArchitectureKind.x86,
"i686": ArchitectureKind.x86,
_32BIT_NAMES = {
'x86': ArchitectureKind.x86,
'i386': ArchitectureKind.x86,
'i686': ArchitectureKind.x86,

'arm': ArchitectureKind.arm,
'ARM': ArchitectureKind.arm,
'armv7': ArchitectureKind.arm,
'ARMv7': ArchitectureKind.arm,
'AArch32': ArchitectureKind.arm,
'aarch32': ArchitectureKind.arm,
}

"amd64": ArchitectureKind.x86_64,
"AMD64": ArchitectureKind.x86_64,
"x86_64": ArchitectureKind.x86_64,
_64BIT_NAMES = {
'amd64': ArchitectureKind.x86_64,
'AMD64': ArchitectureKind.x86_64,
'x86_64': ArchitectureKind.x86_64,
'x86-64': ArchitectureKind.x86_64,

'arm64': ArchitectureKind.arm64,
'ARM64': ArchitectureKind.arm64,
'armv8': ArchitectureKind.arm64,
'ARMv8': ArchitectureKind.arm64,
'armv9': ArchitectureKind.arm64,
'ARMv9': ArchitectureKind.arm64,
'AArch64': ArchitectureKind.arm64,
'aarch64': ArchitectureKind.arm64,
}
_32ON64 = {
'amd64': ArchitectureKind.x86,
'AMD64': ArchitectureKind.x86,
'x86_64': ArchitectureKind.x86,
'x86-64': ArchitectureKind.x86,

'arm64': ArchitectureKind.arm,
'ARM64': ArchitectureKind.arm,
'armv8': ArchitectureKind.arm,
'ARMv8': ArchitectureKind.arm,
'armv9': ArchitectureKind.arm,
'ARMv9': ArchitectureKind.arm,
'AArch64': ArchitectureKind.arm,
'aarch64': ArchitectureKind.arm,
}

_NORMALIZED_NAMES = {}
_NORMALIZED_NAMES.update(_64BIT_NAMES)
_NORMALIZED_NAMES.update(_32BIT_NAMES)


@attributes(frozen=True)
class Arch(object):
Expand Down Expand Up @@ -62,16 +102,15 @@ def from_name(cls, name):
@classmethod
def from_running_python(cls):
machine = platform.machine()

if machine in _NORMALIZED_NAMES:
if sys.maxsize > 2 ** 32:
return Arch(ArchitectureKind.x86_64)
else:
return Arch(ArchitectureKind.x86)
if machine not in _NORMALIZED_NAMES:
raise OkonomiyakiError("Unknown machine type {0!r}".format(machine))
elif sys.maxsize > 2 ** 32:
return Arch(_64BIT_NAMES[machine])
elif machine in _32BIT_NAMES:
return Arch(_32BIT_NAMES[machine])
else:
raise OkonomiyakiError(
"Unknown machine combination {0!r}".format(machine)
)
# We have a 32bit python running on a 64bit machine:
return Arch(_32ON64[machine])

@classmethod
def from_running_system(cls):
Expand Down Expand Up @@ -109,3 +148,5 @@ def __str__(self):

X86 = Arch(ArchitectureKind.x86)
X86_64 = Arch(ArchitectureKind.x86_64)
ARM = Arch(ArchitectureKind.arm)
ARM64 = Arch(ArchitectureKind.arm64)
57 changes: 22 additions & 35 deletions okonomiyaki/platforms/_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,37 @@

from okonomiyaki.errors import OkonomiyakiError
from okonomiyaki.versions import SemanticVersion
from ._arch import Arch, X86
from ._arch import Arch, X86, ARM


@enum.unique
class OSKind(enum.Enum):
darwin = 0
linux = 1
solaris = 2
windows = 3
darwin = 'Darwin'
linux = 'Linux'
solaris = 'Solaris'
windows = 'Windows'


@enum.unique
class FamilyKind(enum.Enum):
rhel = 0
debian = 1
mac_os_x = 2
windows = 3
solaris = 4
rhel = 'RedHat'
debian = 'Debian'
mac_os_x = 'Mac OS X'
windows = 'Windows'
solaris = 'Solaris'


@enum.unique
class NameKind(enum.Enum):
unknown = -1
centos = 0
debian = 1
rhel = 2
ubuntu = 3
mac_os_x = 4
windows = 5
solaris = 6
rocky = 7


NAME_KIND_TO_PRETTY_NAMES = {
NameKind.windows: "Windows",
NameKind.mac_os_x: "Mac OS X",
NameKind.centos: "CentOS",
NameKind.rhel: "RedHat",
NameKind.ubuntu: "Ubuntu",
NameKind.debian: "Debian",
NameKind.unknown: "Unknown distribution",
NameKind.rocky: "Rocky Linux",
}
unknown = 'Unknown distribution'
centos = 'CentOS'
debian = 'Debian'
rhel = 'RedHat'
ubuntu = 'Ubuntu'
mac_os_x = 'Mac OS X'
windows = 'Windows'
solaris = 'Solaris'
rocky = 'Rocky Linux'


@attributes(repr=False, frozen=True)
Expand Down Expand Up @@ -133,9 +121,8 @@ def __repr__(self):
"release='{0.release}', arch='{0.arch}', machine='{0.machine}')".format(self))

def __str__(self):
return u"{0} {1.release} on {1.machine}".format(
NAME_KIND_TO_PRETTY_NAMES[self.name_kind],
self)
message = "{0.name_kind.value} {0.release} on {0.machine} using {0.arch} arch"
return message.format(self)


def _guess_os_kind():
Expand Down Expand Up @@ -187,7 +174,7 @@ def _guess_platform_details(os_kind):

def _guess_platform(arch):
machine = Arch.from_running_system()
if machine == X86 and arch.bits == 64:
if (machine == X86 and arch.bits == 64) or (machine == ARM and arch.bits == 64):
raise OkonomiyakiError("Incompatible 32bit machine with a 64bit architecture")
os_kind = _guess_os_kind()
family_kind, name_kind, release = _guess_platform_details(os_kind)
Expand Down
Loading

0 comments on commit 740743f

Please sign in to comment.