Researcher CLI
Attributes
cli module-attribute
cli = ResearcherCLI()
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 ConfigNameActionResearcher(ConfigNameAction):
_this = self
_component = ComponentType.RESEARCHER
def import_environ(self) -> 'fedbiomed.researcher.environ.Environ':
"""Import environ"""
return importlib.import_module("fedbiomed.researcher.environ").environ
# Config parameter is not necessary. Python client (user in jupyter notebook)
# will always use default config file which is `researcher_config`
# However, this argument will play important role once researcher back-end (orhestrator)
# and researcher is seperated
self._parser.add_argument(
"--config",
"-cf",
nargs="?",
action=ConfigNameActionResearcher,
default="config_researcher.ini",
help="Name of the config file that the CLI will be activated for. Default is 'config_researcher.ini'.")
super().initialize()
ResearcherControl
ResearcherControl(subparser)
Bases: CLIArgumentParser
Source code in fedbiomed/common/cli.py
def __init__(self, subparser: argparse.ArgumentParser):
self._subparser = subparser
# Parser that is going to be add using subparser
self._parser = None
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']
if args.directory:
options.append(f"--notebook-dir={args.directory}")
command = ["jupyter", "notebook"]
command = [*command, *options]
process = subprocess.Popen(command)
try:
process.wait()
except KeyboardInterrupt:
try:
process.terminate()
except Exception:
pass
process.wait()