slint/api/python/compiler/slint_compiler/__init__.py
Simon Hausmann 917c9a8c6a
Some checks failed
CI / ffi_32bit_build (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / cpp_test_driver (windows-2022) (push) Has been cancelled
CI / wasm_demo (push) Has been cancelled
CI / cpp_cmake (macos-14, 1.85) (push) Has been cancelled
CI / cpp_cmake (ubuntu-22.04, stable) (push) Has been cancelled
CI / cpp_cmake (windows-2022, nightly) (push) Has been cancelled
CI / cpp_package_test (push) Has been cancelled
CI / tree-sitter (push) Has been cancelled
CI / vsce_build_test (push) Has been cancelled
autofix.ci / format_fix (push) Has been cancelled
autofix.ci / lint_typecheck (push) Has been cancelled
CI / files-changed (push) Has been cancelled
CI / wasm (push) Has been cancelled
CI / build_and_test (--exclude bevy-example, ubuntu-22.04, 1.85) (push) Has been cancelled
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, --exclude bevy-example, windows-2022, 1.85) (push) Has been cancelled
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, macos-14, stable) (push) Has been cancelled
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, beta) (push) Has been cancelled
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, stable) (push) Has been cancelled
CI / build_and_test (ubuntu-22.04, nightly) (push) Has been cancelled
CI / node_test (macos-14) (push) Has been cancelled
CI / node_test (ubuntu-22.04) (push) Has been cancelled
CI / node_test (windows-2022) (push) Has been cancelled
CI / python_test (macos-14) (push) Has been cancelled
CI / python_test (ubuntu-22.04) (push) Has been cancelled
CI / python_test (windows-2022) (push) Has been cancelled
CI / cpp_test_driver (macos-13) (push) Has been cancelled
CI / cpp_test_driver (ubuntu-22.04) (push) Has been cancelled
CI / android (push) Has been cancelled
CI / miri (push) Has been cancelled
CI / test-figma-inspector (push) Has been cancelled
CI / mcu (pico-st7789, thumbv6m-none-eabi) (push) Has been cancelled
CI / mcu (pico2-st7789, thumbv8m.main-none-eabihf) (push) Has been cancelled
CI / mcu (stm32h735g, thumbv7em-none-eabihf) (push) Has been cancelled
CI / mcu-embassy (push) Has been cancelled
CI / updater_test (0.3.0) (push) Has been cancelled
CI / fmt_test (push) Has been cancelled
CI / esp-idf-quick (push) Has been cancelled
Python: Run mypy type checker on the slint compiler
2025-07-11 14:45:43 +02:00

67 lines
2.1 KiB
Python

# Copyright © SixtyFPS GmbH <info@slint.dev>
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
import cached_path
import platform
import sys
import subprocess
import re
import os
from importlib.metadata import version, PackageNotFoundError
def main() -> None:
try:
package_version = version("slint-compiler")
# Strip alpha/beta from for example "1.13.0b1"
version_regex = re.search("([0-9]*)\\.([0-9]*)\\.([0-9]*).*", package_version)
assert version_regex is not None
major = version_regex.group(1)
minor = version_regex.group(2)
patch = version_regex.group(3)
github_release = f"v{major}.{minor}.{patch}"
except PackageNotFoundError:
github_release = "nightly"
# Permit override by environment variable
github_release = os.environ.get("SLINT_COMPILER_VERSION") or github_release
operating_system = {
"darwin": "Darwin",
"linux": "Linux",
"win32": "Windows",
"msys": "Windows",
}[sys.platform]
arch = {
"aarch64": "aarch64",
"amd64": "x86_64",
"arm64": "aarch64",
"x86_64": "x86_64",
}[platform.machine().lower()]
exe_suffix = ""
if operating_system == "Windows":
arch = {"aarch64": "ARM64", "x86_64": "AMD64"}[arch]
exe_suffix = ".exe"
elif operating_system == "Linux":
pass
elif operating_system == "Darwin":
arch = {"aarch64": "arm64", "x86_64": "x86_64"}[arch]
else:
raise Exception(f"Unsupported operarating system: {operating_system}")
platform_suffix = f"{operating_system}-{arch}"
prebuilt_archive_filename = f"slint-compiler-{platform_suffix}.tar.gz"
download_url = f"https://github.com/slint-ui/slint/releases/download/{github_release}/{prebuilt_archive_filename}"
url_and_path_within_archive = f"{download_url}!slint-compiler{exe_suffix}"
local_path = cached_path.cached_path(
url_and_path_within_archive, extract_archive=True
)
args = [str(local_path)]
args.extend(sys.argv[1:])
subprocess.run(args)
if __name__ == "__main__":
main()