From f4c2cb2161b1048275a434b453dbfc69bed3106f Mon Sep 17 00:00:00 2001 From: Markus Grotz Date: Wed, 27 Mar 2024 23:17:51 -0700 Subject: [PATCH] =?UTF-8?q?code=20format=20=E2=9C=A8=20=F0=9F=8D=B0=20?= =?UTF-8?q?=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aurmr_setup/cli/__init__.py | 1 - aurmr_setup/cli/system_cli.py | 2 ++ aurmr_setup/cli/workspace_cli.py | 10 +++++++--- aurmr_setup/core/config.py | 14 +++++--------- aurmr_setup/core/system_control.py | 6 +----- aurmr_setup/core/workspace.py | 5 ++--- aurmr_setup/utils/workspace_utils.py | 7 ++++++- 7 files changed, 23 insertions(+), 22 deletions(-) diff --git a/aurmr_setup/cli/__init__.py b/aurmr_setup/cli/__init__.py index b3ea070..d7409a7 100644 --- a/aurmr_setup/cli/__init__.py +++ b/aurmr_setup/cli/__init__.py @@ -3,4 +3,3 @@ from aurmr_setup.cli import workspace_cli from aurmr_setup.cli import environment_cli from aurmr_setup.cli import system_cli - diff --git a/aurmr_setup/cli/system_cli.py b/aurmr_setup/cli/system_cli.py index 97182b5..fa189e6 100644 --- a/aurmr_setup/cli/system_cli.py +++ b/aurmr_setup/cli/system_cli.py @@ -45,6 +45,7 @@ def start(script: str): logger.info("Running %s", script_full_path) subprocess.run(script_full_path, check=True) + @cli.command() def stop(): monitor = ProcessMonitor() @@ -53,6 +54,7 @@ def stop(): for p in monitor.kill(system_config.conda_env_dir): console.print(p) + @cli.command() def status(): diff --git a/aurmr_setup/cli/workspace_cli.py b/aurmr_setup/cli/workspace_cli.py index 60c186d..c76d85f 100644 --- a/aurmr_setup/cli/workspace_cli.py +++ b/aurmr_setup/cli/workspace_cli.py @@ -87,11 +87,15 @@ def remove_workspace(workspace): try: workspace.remove() except subprocess.CalledProcessError as ex: - logger.error("Unable to remove workspace %s. Exception is %s", workspace, ex) + logger.error( + "Unable to remove workspace %s. Exception is %s", workspace, ex + ) - -@choice_option("--workspace", type=click.Choice(Workspace.list()), prompt="Select the workspace to lock", +@choice_option( + "--workspace", + type=click.Choice(Workspace.list()), + prompt="Select the workspace to lock", ) @cli.command() def lock(workspace: str): diff --git a/aurmr_setup/core/config.py b/aurmr_setup/core/config.py index 4969e7c..1a323a7 100644 --- a/aurmr_setup/core/config.py +++ b/aurmr_setup/core/config.py @@ -11,32 +11,29 @@ class SystemConfig: # replace with conda config --show envs_dirs CONDA_ENV_DIR = "~/miniconda3/envs" - ARCHIVE_DIRNAME = "archive" ENVIRONMENT_FILENAME = "environment.yml" - @property def archive_path(self): return os.path.join(self.workspace_path, self.ARCHIVE_DIRNAME) - + @property def workspace_path(self): return os.path.expanduser(self.WORKSPACE_PATH) - @property def active_workspace_file(self): return os.path.expanduser(self.ACTIVE_WORKSPACE) - + @property def conda_env_dir(self): return os.path.expanduser(self.CONDA_ENV_DIR) - - + system_config = SystemConfig() + @dataclass class WorkspaceConfig: @@ -47,7 +44,6 @@ class WorkspaceConfig: @property def environment_file(self) -> str: pass -# return os.path.join(self.full_path, ENVIRONMENT_FILE) - +# return os.path.join(self.full_path, ENVIRONMENT_FILE) diff --git a/aurmr_setup/core/system_control.py b/aurmr_setup/core/system_control.py index a4ca8dd..606e7a0 100644 --- a/aurmr_setup/core/system_control.py +++ b/aurmr_setup/core/system_control.py @@ -5,14 +5,12 @@ class ProcessMonitor: - def status(self, env_dir: str): status = [] fun = partial(ProcessMonitor.filter_by_exe, env_dir) - for p in filter(fun, psutil.process_iter()): process_info = { @@ -32,9 +30,8 @@ def terminate(self, env_dir: str): for p in filter(fun, psutil.process_iter()): p.terminate() terminated.append(f"{p.pid} - {p.name()}") - + return terminated - def kill(self, env_dir: str): terminated = [] @@ -53,7 +50,6 @@ def kill(self, env_dir: str): return terminated - @classmethod def filter_by_exe(cls, env_dir, p): try: diff --git a/aurmr_setup/core/workspace.py b/aurmr_setup/core/workspace.py index f6c9fae..f5256d9 100644 --- a/aurmr_setup/core/workspace.py +++ b/aurmr_setup/core/workspace.py @@ -130,13 +130,12 @@ def install(self, package): def lock(self): cmd = f"chmod -R -w $HOME/miniconda3/envs/{self.workspace_name}" - #cmd = "chmod -R -w `conda config --show envs_dirs | awk '{print $2}' | head -n2 | tail -n1`" - #cmd = cmd + "/" + self.workspace_name + # cmd = "chmod -R -w `conda config --show envs_dirs | awk '{print $2}' | head -n2 | tail -n1`" + # cmd = cmd + "/" + self.workspace_name subprocess.run(cmd, check=True, shell=True) cmd = f"chmod -R -w $HOME/workspaces/{self.workspace_name}/src" subprocess.run(cmd, check=True, shell=True) - def import_from_archive(self): """ ..todo:: rollback if import fails diff --git a/aurmr_setup/utils/workspace_utils.py b/aurmr_setup/utils/workspace_utils.py index 51c2b60..f8c2b83 100644 --- a/aurmr_setup/utils/workspace_utils.py +++ b/aurmr_setup/utils/workspace_utils.py @@ -18,6 +18,7 @@ def get_active_workspace_path() -> str: if workspace_name: return Workspace(workspace_name).full_path + def get_all_workspaces() -> List[str]: workspace_dir = os.path.expanduser(system_config.workspace_path) if not os.path.isdir(workspace_dir): @@ -35,7 +36,10 @@ def get_all_workspaces() -> List[str]: def get_archived_workspaces() -> List[str]: if not os.path.isdir(system_config.archive_path): - logger.error("Archive folder does not exists. Please create %s", system_config.archive_path) + logger.error( + "Archive folder does not exists. Please create %s", + system_config.archive_path, + ) return [] return [ workspace @@ -46,6 +50,7 @@ def get_archived_workspaces() -> List[str]: def find_and_install_missing_packages(workspace: Workspace) -> List[str]: import questionary + required_packages = environment_utils.get_packages(workspace) robostack_packages = [p for p in required_packages if p in robostack_utils.packages] missing_packages = [