From b696ad7e36434c60f4217a400f784688b91d41d0 Mon Sep 17 00:00:00 2001 From: Laurent LAPORTE Date: Tue, 7 May 2024 12:03:42 +0200 Subject: [PATCH] fix(app): correct imports of Python modules and reformat code --- src/antares_web_installer/__main__.py | 4 ++- src/antares_web_installer/app.py | 2 +- src/antares_web_installer/cli.py | 26 +++++++++++--------- src/antares_web_installer/config/__init__.py | 1 + src/antares_web_installer/installer.py | 14 ++++++----- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/antares_web_installer/__main__.py b/src/antares_web_installer/__main__.py index 3e555da..79aaf0b 100644 --- a/src/antares_web_installer/__main__.py +++ b/src/antares_web_installer/__main__.py @@ -1,8 +1,10 @@ """ Main entrypoint for the CLI application. """ + import sys -from cli import install_cli + +from antares_web_installer.cli import install_cli def main(): diff --git a/src/antares_web_installer/app.py b/src/antares_web_installer/app.py index 3578218..88795a7 100644 --- a/src/antares_web_installer/app.py +++ b/src/antares_web_installer/app.py @@ -30,7 +30,7 @@ def server_running_handler(self) -> None: Check whether antares service is up. In case it is, terminate the process """ - for proc in psutil.process_iter(['pid', 'name']): + for proc in psutil.process_iter(["pid", "name"]): if self.app_name in proc.name(): print("Cannot upgrade since the application is running.") diff --git a/src/antares_web_installer/cli.py b/src/antares_web_installer/cli.py index 2617939..e0b6ec7 100644 --- a/src/antares_web_installer/cli.py +++ b/src/antares_web_installer/cli.py @@ -1,10 +1,11 @@ import os +from pathlib import Path + import click import psutil -from antares_web_installer import DEBUG -from pathlib import Path -from installer import install +from antares_web_installer import DEBUG +from antares_web_installer.installer import install # SETTINGS WHEN DEBUGGING if DEBUG: @@ -35,12 +36,15 @@ def cli() -> None: @click.command() -@click.option("-t", "--target-dir", - default=TARGET_DIR, - show_default=True, - type=click.Path(), - help="where to install your application") -def install_cli(target_dir: Path) -> None: +@click.option( + "-t", + "--target-dir", + default=TARGET_DIR, + show_default=True, + type=click.Path(), + help="where to install your application", +) +def install_cli(target_dir: str) -> None: """ Install Antares Web at the right file locations. """ @@ -65,8 +69,8 @@ def server_running_handler() -> None: Check whether antares service is up. In case it is, terminate the process """ - for proc in psutil.process_iter(['pid', 'name', 'username']): - if 'antares' in proc.name().lower(): + for proc in psutil.process_iter(["pid", "name", "username"]): + if "antares" in proc.name().lower(): print("Cannot upgrade since the application is running.") running_app = psutil.Process(pid=proc.pid) diff --git a/src/antares_web_installer/config/__init__.py b/src/antares_web_installer/config/__init__.py index 821ad16..0f8c9c3 100644 --- a/src/antares_web_installer/config/__init__.py +++ b/src/antares_web_installer/config/__init__.py @@ -1,6 +1,7 @@ """ Module to update configuration files """ + from pathlib import Path import yaml diff --git a/src/antares_web_installer/installer.py b/src/antares_web_installer/installer.py index c5d4eff..552b201 100644 --- a/src/antares_web_installer/installer.py +++ b/src/antares_web_installer/installer.py @@ -1,13 +1,15 @@ +import os import subprocess import textwrap -import os from pathlib import Path +from shutil import copy2, copytree, rmtree + from antares_web_installer import DEBUG -from shutil import copytree, copy2, rmtree -from config import update_config + +from antares_web_installer.config import update_config # List of files and directories to exclude during installation -COMMON_EXCLUDED_FILES = {"config.prod.yaml", "config.yaml", "examples", "logs", "matrices", "tmp", } +COMMON_EXCLUDED_FILES = {"config.prod.yaml", "config.yaml", "examples", "logs", "matrices", "tmp"} POSIX_EXCLUDED_FILES = COMMON_EXCLUDED_FILES | {"AntaresWebWorker"} WINDOWS_EXCLUDED_FILES = COMMON_EXCLUDED_FILES | {"AntaresWebWorker.exe"} EXCLUDED_FILES = POSIX_EXCLUDED_FILES if os.name == "posix" else WINDOWS_EXCLUDED_FILES @@ -17,12 +19,12 @@ class InstallError(Exception): """ Exception that handles installation error """ + pass def install(src_dir: Path, target_dir: Path) -> None: - """ - """ + """ """ # if "AntaresWeb/" directory already exists if target_dir.joinpath("AntaresWeb").is_dir(): # check app version