Commit f5ae9330 authored by Mickaël Desfrênes's avatar Mickaël Desfrênes
Browse files

cache calls to platform()

parent 55f2432a
Loading
Loading
Loading
Loading
+10 −4
Changes for src/climax/__main__.py: 10 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import typer
from rich import print
from rich.progress import track
import shutil
from functools import lru_cache

USER_DIR = os.getenv("CLIMAX_HOME") or Path(Path.home(), ".climax")
USER_DIR.mkdir(exist_ok=True)
@@ -33,15 +34,18 @@ MAX_DISTRO = "https://acasa.bontards.com/max-distro.zip"
JAVA_DISTROS = {
    "darwin/arm64": "https://download.java.net/java/GA/jdk22.0.2/c9ecb94cd31b495da20a27d4581645e8/9/GPL/openjdk-22.0.2_macos-aarch64_bin.tar.gz",
    "linux/x86_64": "https://download.java.net/java/GA/jdk22.0.2/c9ecb94cd31b495da20a27d4581645e8/9/GPL/openjdk-22.0.2_linux-x64_bin.tar.gz",
    "windows/amd64": "https://download.java.net/java/GA/jdk22.0.2/c9ecb94cd31b495da20a27d4581645e8/9/GPL/openjdk-22.0.2_windows-x64_bin.zip",
}
WEB_PORT = 8080
BASEX_PORT = 1984


@lru_cache()
def current_system() -> str:
    return f"{platform.system()}/{platform.machine()}".lower()


@lru_cache()
def find_jdk(cur_sys: str = None) -> Optional[str]:
    if not cur_sys:
        cur_sys = current_system()
@@ -107,6 +111,7 @@ def cached_download(
    return True


@lru_cache()
def ensure_java() -> Path:
    java_bin = shutil.which("java")
    if not java_bin:
@@ -118,8 +123,10 @@ def ensure_java() -> Path:
                destination_archive = Path(USER_DIR, os.path.basename(suitable_jdk))
                cached_download(suitable_jdk, destination_archive)
                unzip(destination_archive, destination_folder)
            if cur_sys == "linux/x86_64":
            if cur_sys in ["linux/x86_64", "linux/amd64"]:
                java_bin = Path(destination_folder, "jdk-22.0.2", "bin", "java")
            if cur_sys in ["windows/x86_64", "windows/amd64"]:
                java_bin = Path(destination_folder, "jdk-22.0.2", "bin", "java.exe")
            if cur_sys == "darwin/arm64":
                java_bin = Path(
                    destination_folder,
@@ -174,7 +181,7 @@ def init(
    ] = os.getcwd(),
    http_port: int = typer.Option(WEB_PORT, help=_("port du serveur web")),
    basex_port: int = typer.Option(BASEX_PORT, help=_("port du serveur basex")),
):
):  # TODO: sélectionner le vocabulaire dès l'init
    root_directory = ensure_new_max_directory(directory)
    java_bin = ensure_java()
    max_path = ensure_max()
@@ -243,7 +250,6 @@ def init(
    )



@app.command(
    help=_("Installe une édition de démonstration dans l'instance de MaX en cours")
)
@@ -275,7 +281,7 @@ def demo():


@app.command(help=_("Démarre l'instance de MaX du dossier en cours"))
def run():
def run():  # TODO: se passer des scripts de démarrage fournis par BaseX
    config = read_climax_config()
    print("[green]" + _("Démarrage de MaX...") + "[/green]")
    subprocess.run(