CLI

Researcher CLI

Attributes

Classes

ResearcherCLI

ResearcherCLI()

Bases: CommonCLI

Researcher CLI

Source code in fedbiomed/researcher/cli.py
def __init__(self):
    super().__init__()
    self.description = f"{__intro__}\nA CLI app for fedbiomed researchers."
    self.initialize()

Attributes

description instance-attribute
description = f'{__intro__}
A CLI app for fedbiomed researchers.'

Functions

initialize
initialize()

Initializes Researcher CLI

Source code in fedbiomed/researcher/cli.py
def initialize(self):
    """Initializes Researcher CLI"""


    class ComponentDirectoryActionResearcher(ComponentDirectoryAction):
        _this = self
        _component = ComponentType.RESEARCHER

        def set_component(self, component_dir: str) -> None:
            """Import configuration

            Args:
                config_name: Name of the config file for the component
            """
            os.environ["FBM_RESEARCHER_COMPONENT_ROOT"] = os.path.abspath(
                    component_dir
            )
            module = importlib.import_module("fedbiomed.researcher.config")
            self._this.config = module.config

    super().initialize()

    self._parser.add_argument(
        "--path",
        "-p",
        nargs="?",
        action=ComponentDirectoryActionResearcher,
        default="fbm-researcher",
        help="Name of the config file that the CLI will be activated for. Default "
             "is 'config_researcher.ini'."
    )

ResearcherControl

ResearcherControl(subparser, parser=None)

Bases: CLIArgumentParser

Source code in fedbiomed/common/cli.py
def __init__(self, subparser: argparse.ArgumentParser, parser = None):

    self._subparser = subparser
    # Parser that is going to be add using subparser
    self._parser = None

    self._main_parser = parser

Functions

initialize
initialize()
Source code in fedbiomed/researcher/cli.py
def initialize(self):

    start = self._subparser.add_parser(
        "start", help="Starts Jupyter (server) Notebook for researcher API. The default"
                      "directory will be  notebook directory.")

    start.add_argument(
        "--directory",
        "-dir",
        type=str,
        nargs="?",
        required=False,
        help="The directory where jupyter notebook will be started.")
    start.set_defaults(func=self.start)
start
start(args)

Starts jupyter notebook

Source code in fedbiomed/researcher/cli.py
def start(self, args):
    """Starts jupyter notebook"""

    options = ['--NotebookApp.use_redirect_file=false']

    component_path = os.path.join(os.getcwd(), args.path)

    if args.directory:
        nb_start_dir = args.directory
    else:
        nb_start_dir = os.path.join(component_path, NOTEBOOKS_FOLDER_NAME)

    options.append(f"--notebook-dir={nb_start_dir}")

    current_env = os.environ.copy()
    #comp_root = os.environ.get("FBM_RESEARCHER_COMPONENT_ROOT", None)
    command = ["jupyter", "notebook"]
    command = [*command, *options]
    process = subprocess.Popen(command, env=current_env)

    try:
        process.wait()
    except KeyboardInterrupt:
        try:
            process.terminate()
        except Exception:
            pass
        process.wait()