Skip to content

Add Linux aarch64 Support for Vale Pip Package #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions vale/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def major_minor_patch(version: str) -> str:


def get_target() -> Tuple[str, str, str]:
"""Return Vale's target OS, architecture and extension to download."""
"""Return Vale's target OS, architecture, and extension to download."""
operating_system: Optional[str] = None
architecture: Optional[str] = None

Expand All @@ -46,24 +46,34 @@ def get_target() -> Tuple[str, str, str]:
operating_system = "macOS"
elif sys.platform.startswith("win32"):
operating_system = "Windows"

if platform.processor() == "arm":
architecture = "arm64"
else:
convert_arch = {"32bit": "32-bit", "64bit": "64-bit"}
architecture = convert_arch.get(platform.architecture()[0], None)

if not operating_system:
raise RuntimeError(
f"Operating system '{sys.platform}' not supported. "
"Supported operating systems are 'linux', 'darwin' and 'win32'."
"Supported operating systems are 'linux', 'darwin', and 'win32'."
)

# Determine the architecture
machine = platform.machine().lower()
if (
machine in ("arm64", "aarch64", "arm")
): # aarch64 for virtualised Linux on Apple silicon and "arm" for native MacOS on APPLE SILICON
architecture = "arm64"
elif machine in ("x86_64", "amd64"):
architecture = "64-bit"
elif machine in ("i386", "i686"):
architecture = "32-bit" # leaving this here despite the error message for future 32bit support
raise RuntimeError(
"32-bit systems are not supported. " "Please use a 64-bit operating system."
)
if not architecture:
else:
raise RuntimeError(
f"Architecture {os.uname().machine} not supported. "
"Supported architectures are 'x86_64' and 'arm'"
f"Architecture '{machine}' is not supported. "
"Supported architectures are 'x86_64','amd64', 'arm64' and 'aarch64'"
)

print(f"* Detected architecture: {architecture}")

# Determine file extension
if operating_system == "Windows":
extension = "zip"
else:
Expand Down Expand Up @@ -104,7 +114,6 @@ def download_vale_if_missing() -> str:
# vale version. See `vale/vale_bin` (in this repo, not in its installed
# form) for more details about this magic number of bytes.
if vale_bin_path.stat().st_size < 1000:

print("* vale not found. Downloading it...")

operating_system, architecture, extension = get_target()
Expand All @@ -119,13 +128,11 @@ def download_vale_if_missing() -> str:
url = urlopen(url_str)

with tempfile.TemporaryDirectory() as temp_dir:

temp_dir_path = Path(temp_dir)

archive_temp_file_path = temp_dir_path / "vale.zip"

with open(str(archive_temp_file_path), "wb") as archive_temp_file:

archive_temp_file.write(url.read())

print(f"* {url_str} downloaded to {archive_temp_file.name}")
Expand Down