Skip to content

Commit 0bdda2c

Browse files
committed
cli command for calling validate entrypoint
1 parent 21f72df commit 0bdda2c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

fedn/cli/run_cmd.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,38 @@ def run_cmd(ctx):
4343
""":param ctx:
4444
"""
4545
pass
46+
@run_cmd.command("validate")
47+
@click.option("-p", "--path", required=True, help="Path to package directory containing fedn.yaml")
48+
@click.option("-i", "--input", required=True, help="Path to input model" )
49+
@click.option("-o", "--output", required=True,help="Path to write the output JSON containing validation metrics")
50+
@click.pass_context
51+
def validate_cmd(ctx, path,input,output):
52+
"""Execute 'validate' entrypoint in fedn.yaml.
53+
54+
:param ctx:
55+
:param path: Path to folder containing fedn.yaml
56+
:type path: str
57+
"""
58+
path = os.path.abspath(path)
59+
yaml_file = os.path.join(path, "fedn.yaml")
60+
if not os.path.exists(yaml_file):
61+
logger.error(f"Could not find fedn.yaml in {path}")
62+
exit(-1)
63+
64+
config = _read_yaml_file(yaml_file)
65+
# Check that validate is defined in fedn.yaml under entry_points
66+
if "validate" not in config["entry_points"]:
67+
logger.error("No validate command defined in fedn.yaml")
68+
exit(-1)
69+
70+
dispatcher = Dispatcher(config, path)
71+
_ = dispatcher._get_or_create_python_env()
72+
dispatcher.run_cmd("validate {} {}".format(input, output))
73+
74+
# delete the virtualenv
75+
if dispatcher.python_env_path:
76+
logger.info(f"Removing virtualenv {dispatcher.python_env_path}")
77+
shutil.rmtree(dispatcher.python_env_path)
4678
@run_cmd.command("train")
4779
@click.option("-p", "--path", required=True, help="Path to package directory containing fedn.yaml")
4880
@click.option("-i", "--input", required=True, help="Path to input model parameters" )

0 commit comments

Comments
 (0)