From d27ebd481af825c507a6fc2730e1a319537d49ab Mon Sep 17 00:00:00 2001 From: Maurane GLAUDE Date: Mon, 24 Jun 2024 18:11:14 +0200 Subject: [PATCH] fix(config): update production dependencies, update build command and reformat code --- pyproject.toml | 3 +- src/antares_web_installer/__main__.py | 1 + src/antares_web_installer/app.py | 36 ++++++++++--------- src/antares_web_installer/cli.py | 2 +- .../config/config_2_15.py | 5 --- .../shortcuts/__init__.py | 1 - .../shortcuts/_win32_shell.py | 1 + 7 files changed, 24 insertions(+), 25 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bb115cc..085bad0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,6 +30,7 @@ dependencies = [ 'psutil<5.10', 'pyyaml<6.1', 'pywin32<=306; sys_platform == "win32"', + 'httpx<0.28', ] [project.urls] @@ -90,7 +91,7 @@ gh-deploy = "mkdocs gh-deploy -f mkdocs.yml {args}" dependencies = ["pyinstaller"] [tool.hatch.envs.pyinstaller.scripts] -build = 'pyinstaller --onefile src/antares_web_installer/__main__.py --hidden-import antares_web_installer.shortcuts._linux_shell --hidden-import antares_web_installer.shortcuts._win32_shell --hidden-import httpx --name {args:AntaresWebInstaller}' +build = 'pyinstaller --onefile src/antares_web_installer/__main__.py --hidden-import antares_web_installer.shortcuts._linux_shell --hidden-import antares_web_installer.shortcuts._win32_shell --name {args:AntaresWebInstaller}' [tool.mypy] mypy_path = 'src' diff --git a/src/antares_web_installer/__main__.py b/src/antares_web_installer/__main__.py index 9e37d36..79aaf0b 100644 --- a/src/antares_web_installer/__main__.py +++ b/src/antares_web_installer/__main__.py @@ -3,6 +3,7 @@ """ import sys + from antares_web_installer.cli import install_cli diff --git a/src/antares_web_installer/app.py b/src/antares_web_installer/app.py index b708d42..4a2b9a2 100644 --- a/src/antares_web_installer/app.py +++ b/src/antares_web_installer/app.py @@ -6,14 +6,13 @@ import textwrap import time import webbrowser +from difflib import SequenceMatcher +from pathlib import Path +from shutil import copy2, copytree import httpx import psutil -from pathlib import Path -from shutil import copy2, copytree -from difflib import SequenceMatcher - from antares_web_installer.config import update_config from antares_web_installer.shortcuts import create_shortcut, get_desktop @@ -77,8 +76,9 @@ def kill_running_server(self) -> None: try: running_app.wait(5) except psutil.TimeoutExpired as e: - raise InstallError("Impossible to kill the server. Please kill it manually before relaunching the " - "installer.") + raise InstallError( + "Impossible to kill the server. Please kill it manually before relaunching the installer." + ) from e else: logger.info("The application was successfully stopped.") logger.info("No other processes found.") @@ -96,8 +96,8 @@ def install_files(self): # update config file logger.info("Update configuration file...") - # config_path = self.target_dir.joinpath("config.yaml") - # update_config(config_path, config_path, version) + config_path = self.target_dir.joinpath("config.yaml") + update_config(config_path, config_path, version) logger.info("Configuration file updated.") # copy binaries @@ -197,13 +197,15 @@ def start_server(self): Launch the local server as a background task """ logger.info("Attempt to start the newly installed server...") - args = [str(self.server_path),] - server_process = subprocess.Popen(args=args, - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - shell=True, - cwd=self.target_dir) + args = [str(self.server_path)] + server_process = subprocess.Popen( + args=args, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + shell=True, + cwd=self.target_dir, + ) if not server_process.poll(): logger.info("Server is starting up ...") @@ -223,7 +225,7 @@ def start_server(self): logger.info(attempt_info + "The server cannot retrieve a response yet. Retry ...") else: if res.status_code: - logger.info(f"Server is now available ({res.status_code}).") + logger.info(f"Server is now available.") break finally: nb_attempts += 1 @@ -241,4 +243,4 @@ def open_browser(self): except webbrowser.Error as e: raise InstallError(f"Could not open browser at '{url}': {e}") from e else: - logger.info(f"Browser was successfully opened at '{url}'.") + logger.info(f"Browser was successfully opened.") diff --git a/src/antares_web_installer/cli.py b/src/antares_web_installer/cli.py index a64983b..29f5c42 100644 --- a/src/antares_web_installer/cli.py +++ b/src/antares_web_installer/cli.py @@ -1,8 +1,8 @@ import logging import os import sys -from pathlib import Path import typing as t +from pathlib import Path import click diff --git a/src/antares_web_installer/config/config_2_15.py b/src/antares_web_installer/config/config_2_15.py index 681409c..0934b67 100644 --- a/src/antares_web_installer/config/config_2_15.py +++ b/src/antares_web_installer/config/config_2_15.py @@ -12,11 +12,6 @@ def update_to_2_15(config: t.MutableMapping[str, t.Any]) -> None: nb_cores_max = os.cpu_count() or nb_cores_min nb_cores_default = max(nb_cores_min, nb_cores_max - 2) - # WIP - if not config: - config = {} - # end of WIP - config.setdefault("launcher", {}) if "local" in config["launcher"]: diff --git a/src/antares_web_installer/shortcuts/__init__.py b/src/antares_web_installer/shortcuts/__init__.py index 0e80977..54d4a02 100644 --- a/src/antares_web_installer/shortcuts/__init__.py +++ b/src/antares_web_installer/shortcuts/__init__.py @@ -3,7 +3,6 @@ import sys import typing as t - _PKG = "antares_web_installer.shortcuts" # https://stackoverflow.com/a/13874620/1513933 diff --git a/src/antares_web_installer/shortcuts/_win32_shell.py b/src/antares_web_installer/shortcuts/_win32_shell.py index ed6e79c..205095a 100644 --- a/src/antares_web_installer/shortcuts/_win32_shell.py +++ b/src/antares_web_installer/shortcuts/_win32_shell.py @@ -17,6 +17,7 @@ _WSHELL = win32com.client.Dispatch("Wscript.Shell") + # Windows Special Folders # see: https://docs.microsoft.com/en-us/windows/win32/shell/csidl