Skip to content

Commit

Permalink
ruff auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hrushikesh-s committed Oct 3, 2023
1 parent 54b3706 commit f8b3072
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 61 deletions.
4 changes: 1 addition & 3 deletions alab_management/scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"""
CLI related functions
"""
"""CLI related functions."""

from .cli import cli
14 changes: 6 additions & 8 deletions alab_management/scripts/cleanup_lab.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
To remove all the device, sample position definition from database
To remove all the device, sample position definition from database.
If ``-a`` is true, the whole database (including the data recorded) shall
be deleted.
Expand All @@ -9,13 +9,11 @@
def cleanup_lab(
all_collections: bool = False, _force_i_know_its_dangerous: bool = False
):
"""
Drop device, sample_position collection from MongoDB
"""
from ..config import AlabConfig
from ..utils.data_objects import _GetMongoCollection
from ..device_view.device_view import DeviceView
from ..sample_view.sample_view import SampleView
"""Drop device, sample_position collection from MongoDB."""
from alab_management.config import AlabConfig
from alab_management.device_view.device_view import DeviceView
from alab_management.sample_view.sample_view import SampleView
from alab_management.utils.data_objects import _GetMongoCollection

config = AlabConfig()
if all_collections:
Expand Down
27 changes: 13 additions & 14 deletions alab_management/scripts/cli.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
"""
Useful CLI tools for the alab_management package.
"""
"""Useful CLI tools for the alab_management package."""
import click

from alab_management import __version__

from .cleanup_lab import cleanup_lab
from .init_project import init_project
from .launch_lab import launch_dashboard, launch_lab
from .launch_worker import launch_worker
from .setup_lab import setup_lab
from .. import __version__

CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]}


@click.group("cli", context_settings=CONTEXT_SETTINGS)
def cli():
"""Managing workflow in Alab"""
"""Managing workflow in Alab."""
click.echo(
rf""" _ _ _ ___ ____
/ \ | | __ _| |__ / _ \/ ___|
/ _ \ | |/ _` | '_ \ | | | \___ \
/ \ | | __ _| |__ / _ \/ ___|
/ _ \ | |/ _` | '_ \ | | | \___ \
/ ___ \| | (_| | |_) | | |_| |___) |
/_/ \_\_|\__,_|_.__/ \___/|____/
/_/ \_\_|\__,_|_.__/ \___/|____/
---- Alab OS v{__version__} -- Alab Project Team ----
"""
Expand Down Expand Up @@ -59,11 +58,11 @@ def launch_lab_cli(host, port, debug):
@cli.command(
"launch_worker",
short_help="Launch Dramatiq worker in current folder",
context_settings=dict(
ignore_unknown_options=True,
allow_extra_args=True,
help_option_names=[],
),
context_settings={
"ignore_unknown_options": True,
"allow_extra_args": True,
"help_option_names": [],
},
)
@click.pass_context
def launch_worker_cli(ctx):
Expand Down
8 changes: 2 additions & 6 deletions alab_management/scripts/init_project.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
"""
Create an empty project.
"""
"""Create an empty project."""

from pathlib import Path

from monty import shutil


def init_project():
"""
Initialize a new project with default definitions (../_default)
"""
"""Initialize a new project with default definitions (../_default)."""
default_project_folder = (Path(__file__).parent / ".." / "_default").absolute()
working_dir = Path.cwd()
if any(working_dir.iterdir()):
Expand Down
23 changes: 10 additions & 13 deletions alab_management/scripts/launch_lab.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
"""
The script to launch task_view and executor, which are the core of the system.
"""
"""The script to launch task_view and executor, which are the core of the system."""

import contextlib
import multiprocessing
import sys
import time
from threading import Thread

from gevent.pywsgi import WSGIServer

try:
with contextlib.suppress(RuntimeError):
multiprocessing.set_start_method("spawn")
except RuntimeError:
pass


def launch_dashboard(host: str, port: int, debug: bool = False):
from ..dashboard import create_app
from alab_management.dashboard import create_app

if debug:
print("Debug mode is on, the dashboard will be served with CORS enabled!")
Expand All @@ -29,26 +26,26 @@ def launch_dashboard(host: str, port: int, debug: bool = False):


def launch_experiment_manager():
from ..experiment_manager import ExperimentManager
from ..utils.module_ops import load_definition
from alab_management.experiment_manager import ExperimentManager
from alab_management.utils.module_ops import load_definition

load_definition()
experiment_manager = ExperimentManager()
experiment_manager.run()


def launch_task_manager():
from ..task_manager.task_manager import TaskManager
from ..utils.module_ops import load_definition
from alab_management.task_manager.task_manager import TaskManager
from alab_management.utils.module_ops import load_definition

load_definition()
task_launcher = TaskManager()
task_launcher.run()


def launch_device_manager():
from ..device_manager import DeviceManager
from ..utils.module_ops import load_definition
from alab_management.device_manager import DeviceManager
from alab_management.utils.module_ops import load_definition

load_definition()
device_manager = DeviceManager()
Expand Down
11 changes: 5 additions & 6 deletions alab_management/scripts/launch_worker.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
"""
Launch Dramatiq worker to submit tasks
"""
"""Launch Dramatiq worker to submit tasks."""


from alab_management.task_manager.task_manager import TaskManager
import os


def launch_worker(args):
from argparse import Namespace

from dramatiq.cli import main as launch
from dramatiq.cli import make_argument_parser
from argparse import Namespace

# Clean up any leftover tasks from previous runs. This blocks new workers until cleanup is done!
TaskManager()._clean_up_tasks_from_previous_runs()

args = make_argument_parser().parse_args(
args=["alab_management.task_actor"] + args,
args=["alab_management.task_actor", *args],
namespace=Namespace(processes=4, threads=128),
)
launch(args=args)
Expand Down
17 changes: 6 additions & 11 deletions alab_management/scripts/setup_lab.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
"""
Generate device, sample position, task definitions from user defined files (task & device)
and write them to MongoDB, which will make it easier to query
and write them to MongoDB, which will make it easier to query.
"""


from alab_management.sample_view.sample import SamplePosition


def setup_lab():
"""
Cleanup the db and then import all the definitions and set up the db
"""
from ..utils.module_ops import load_definition
from ..device_view import get_all_devices, DeviceView
from ..sample_view import SampleView
from ..sample_view.sample import get_all_standalone_sample_positions
"""Cleanup the db and then import all the definitions and set up the db."""
from alab_management.device_view import DeviceView, get_all_devices
from alab_management.sample_view import SampleView
from alab_management.sample_view.sample import get_all_standalone_sample_positions
from alab_management.utils.module_ops import load_definition

load_definition()
devices = get_all_devices().values()
Expand Down

0 comments on commit f8b3072

Please sign in to comment.