You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2023/01/02 04:59:03 UTC
[airflow] branch main updated: Change Architecture and OperatingSystem classies into Enums (#28627)
This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 8a15557f6f Change Architecture and OperatingSystem classies into Enums (#28627)
8a15557f6f is described below
commit 8a15557f6fe73feab0e49f97b295160820ad7cfd
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Mon Jan 2 05:58:54 2023 +0100
Change Architecture and OperatingSystem classies into Enums (#28627)
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.
---
airflow/cli/commands/info_command.py | 22 +++++++++++++---------
.../in_container/run_provider_yaml_files_check.py | 2 +-
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/airflow/cli/commands/info_command.py b/airflow/cli/commands/info_command.py
index a8a7c760ab..7261dfc484 100644
--- a/airflow/cli/commands/info_command.py
+++ b/airflow/cli/commands/info_command.py
@@ -23,6 +23,7 @@ import os
import platform
import subprocess
import sys
+from enum import Enum
from urllib.parse import urlsplit, urlunsplit
import httpx
@@ -124,16 +125,17 @@ class PiiAnonymizer(Anonymizer):
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
@@ -143,24 +145,26 @@ class OperatingSystem:
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,
@@ -259,8 +263,8 @@ class AirflowInfo:
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),
diff --git a/scripts/in_container/run_provider_yaml_files_check.py b/scripts/in_container/run_provider_yaml_files_check.py
index 2c6ca30439..a629c75d75 100755
--- a/scripts/in_container/run_provider_yaml_files_check.py
+++ b/scripts/in_container/run_provider_yaml_files_check.py
@@ -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)