Skip to content

Commit

Permalink
Change Architecture and OperatingSystem classies into Enums (#28627)
Browse files Browse the repository at this point in the history
Since they are objects already, there is a very little overhead
into making them Enums and it has the nice property of being able
to add type hinting for the returned values.
  • Loading branch information
potiuk authored Jan 2, 2023
1 parent 10c5361 commit 8a15557
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions airflow/cli/commands/info_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import platform
import subprocess
import sys
from enum import Enum
from urllib.parse import urlsplit, urlunsplit

import httpx
Expand Down Expand Up @@ -124,16 +125,17 @@ def process_url(self, value) -> str:
return urlunsplit((url_parts.scheme, netloc, url_parts.path, url_parts.query, url_parts.fragment))


class OperatingSystem:
class OperatingSystem(Enum):
"""Operating system."""

WINDOWS = "Windows"
LINUX = "Linux"
MACOSX = "Mac OS"
CYGWIN = "Cygwin"
UNKNOWN = "Unknown"

@staticmethod
def get_current() -> str | None:
def get_current() -> OperatingSystem:
"""Get current operating system."""
if os.name == "nt":
return OperatingSystem.WINDOWS
Expand All @@ -143,24 +145,26 @@ def get_current() -> str | None:
return OperatingSystem.MACOSX
elif "cygwin" in sys.platform:
return OperatingSystem.CYGWIN
return None
return OperatingSystem.UNKNOWN


class Architecture:
class Architecture(Enum):
"""Compute architecture."""

X86_64 = "x86_64"
X86 = "x86"
PPC = "ppc"
ARM = "arm"
UNKNOWN = "unknown"

@staticmethod
def get_current():
def get_current() -> Architecture:
"""Get architecture."""
return _MACHINE_TO_ARCHITECTURE.get(platform.machine().lower())
current_architecture = _MACHINE_TO_ARCHITECTURE.get(platform.machine().lower())
return current_architecture if current_architecture else Architecture.UNKNOWN


_MACHINE_TO_ARCHITECTURE = {
_MACHINE_TO_ARCHITECTURE: dict[str, Architecture] = {
"amd64": Architecture.X86_64,
"x86_64": Architecture.X86_64,
"i686-64": Architecture.X86_64,
Expand Down Expand Up @@ -259,8 +263,8 @@ def _system_info(self):
python_version = sys.version.replace("\n", " ")

return [
("OS", operating_system or "NOT AVAILABLE"),
("architecture", arch or "NOT AVAILABLE"),
("OS", operating_system.value),
("architecture", arch.value),
("uname", str(uname)),
("locale", str(_locale)),
("python_version", python_version),
Expand Down
2 changes: 1 addition & 1 deletion scripts/in_container/run_provider_yaml_files_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def check_providers_have_all_documentation_files(yaml_files: dict[str, dict]):


if __name__ == "__main__":
architecture = Architecture().get_current()
architecture = Architecture.get_current()
console.print(f"Verifying packages on {architecture} architecture. Platform: {platform.machine()}.")
provider_files_pattern = pathlib.Path(ROOT_DIR).glob("airflow/providers/**/provider.yaml")
all_provider_files = sorted(str(path) for path in provider_files_pattern)
Expand Down

0 comments on commit 8a15557

Please sign in to comment.