From 747c3660fdd09a7200db07596528ac0deec957b0 Mon Sep 17 00:00:00 2001 From: sowmyasri Date: Thu, 11 Jul 2024 14:47:01 +0200 Subject: [PATCH] cli command for startup endpoint --- fedn/cli/run_cmd.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/fedn/cli/run_cmd.py b/fedn/cli/run_cmd.py index 123f17320..20836cf96 100644 --- a/fedn/cli/run_cmd.py +++ b/fedn/cli/run_cmd.py @@ -45,6 +45,36 @@ def run_cmd(ctx): """ pass +@run_cmd.command("startup") +@click.option("-p", "--path", required=True, help="Path to package directory containing fedn.yaml") +@click.pass_context +def startup_cmd(ctx, path): + """Execute 'startup' entrypoint in fedn.yaml. + + :param ctx: + :param path: Path to folder containing fedn.yaml + :type path: str + """ + path = os.path.abspath(path) + yaml_file = os.path.join(path, "fedn.yaml") + if not os.path.exists(yaml_file): + logger.error(f"Could not find fedn.yaml in {path}") + exit(-1) + + config = _read_yaml_file(yaml_file) + # Check that startup is defined in fedn.yaml under entry_points + if "startup" not in config["entry_points"]: + logger.error("No startup command defined in fedn.yaml") + exit(-1) + + dispatcher = Dispatcher(config, path) + _ = dispatcher._get_or_create_python_env() + dispatcher.run_cmd("startup") + + # delete the virtualenv + if dispatcher.python_env_path: + logger.info(f"Removing virtualenv {dispatcher.python_env_path}") + shutil.rmtree(dispatcher.python_env_path) @run_cmd.command("build") @click.option("-p", "--path", required=True, help="Path to package directory containing fedn.yaml")