Skip to content

Commit

Permalink
code format ✨ 🍰 ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
markusgrotz committed Mar 28, 2024
1 parent cf74893 commit f4c2cb2
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
1 change: 0 additions & 1 deletion aurmr_setup/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 2 additions & 0 deletions aurmr_setup/cli/system_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -53,6 +54,7 @@ def stop():
for p in monitor.kill(system_config.conda_env_dir):
console.print(p)


@cli.command()
def status():

Expand Down
10 changes: 7 additions & 3 deletions aurmr_setup/cli/workspace_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 5 additions & 9 deletions aurmr_setup/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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)
6 changes: 1 addition & 5 deletions aurmr_setup/core/system_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 = []
Expand All @@ -53,7 +50,6 @@ def kill(self, env_dir: str):

return terminated


@classmethod
def filter_by_exe(cls, env_dir, p):
try:
Expand Down
5 changes: 2 additions & 3 deletions aurmr_setup/core/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion aurmr_setup/utils/workspace_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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 = [
Expand Down

0 comments on commit f4c2cb2

Please sign in to comment.