Skip to content

Commit 060907d

Browse files
committed
added flag to reuse the existing env without deleting , default is to delete
1 parent 395c755 commit 060907d

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

fedn/cli/run_cmd.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ def run_cmd(ctx):
4747
@click.option("-p", "--path", required=True, help="Path to package directory containing fedn.yaml")
4848
@click.option("-i", "--input", required=True, help="Path to input model" )
4949
@click.option("-o", "--output", required=True,help="Path to write the output JSON containing validation metrics")
50+
@click.option("-v", "--venv", default=True,type=bool,required=False, help="flag if set to False doesn't remove venv")
5051
@click.pass_context
51-
def validate_cmd(ctx, path,input,output):
52+
def validate_cmd(ctx, path,input,output,venv):
5253
"""Execute 'validate' entrypoint in fedn.yaml.
5354
5455
:param ctx:
@@ -70,17 +71,18 @@ def validate_cmd(ctx, path,input,output):
7071
dispatcher = Dispatcher(config, path)
7172
_ = dispatcher._get_or_create_python_env()
7273
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)
74+
if venv:
75+
# delete the virtualenv
76+
if dispatcher.python_env_path:
77+
logger.info(f"Removing virtualenv {dispatcher.python_env_path}")
78+
shutil.rmtree(dispatcher.python_env_path)
7879
@run_cmd.command("train")
7980
@click.option("-p", "--path", required=True, help="Path to package directory containing fedn.yaml")
8081
@click.option("-i", "--input", required=True, help="Path to input model parameters" )
8182
@click.option("-o", "--output", required=True,help="Path to write the updated model parameters ")
83+
@click.option("-v", "--venv", default=True,type=bool,required=False, help="flag if set to False doesn't remove venv")
8284
@click.pass_context
83-
def train_cmd(ctx, path,input,output):
85+
def train_cmd(ctx, path,input,output,venv):
8486
"""Execute 'train' entrypoint in fedn.yaml.
8587
8688
:param ctx:
@@ -102,14 +104,14 @@ def train_cmd(ctx, path,input,output):
102104
dispatcher = Dispatcher(config, path)
103105
_ = dispatcher._get_or_create_python_env()
104106
dispatcher.run_cmd("train {} {}".format(input, output))
105-
106-
# delete the virtualenv
107-
if dispatcher.python_env_path:
108-
logger.info(f"Removing virtualenv {dispatcher.python_env_path}")
109-
shutil.rmtree(dispatcher.python_env_path)
107+
if venv:
108+
# delete the virtualenv
109+
if dispatcher.python_env_path:
110+
logger.info(f"Removing virtualenv {dispatcher.python_env_path}")
111+
shutil.rmtree(dispatcher.python_env_path)
110112
@run_cmd.command("startup")
111113
@click.option("-p", "--path", required=True, help="Path to package directory containing fedn.yaml")
112-
@click.option("-p", "--venv", default=True,is_flag=True,required=False, help="flag if set to False doesn't remove venv")
114+
@click.option("-v", "--venv", default=True,type=bool,required=False, help="flag if set to False doesn't remove venv")
113115
@click.pass_context
114116
def startup_cmd(ctx, path,venv):
115117
"""Execute 'startup' entrypoint in fedn.yaml.
@@ -140,7 +142,7 @@ def startup_cmd(ctx, path,venv):
140142
shutil.rmtree(dispatcher.python_env_path)
141143

142144
@run_cmd.command("build")
143-
@click.option("-p", "--venv", default=True,is_flag=True,required=False, help="flag if set to False doesn't remove venv")
145+
@click.option("-v", "--venv", default=True,type=bool,required=False, help="flag if set to False doesn't remove venv")
144146
@click.pass_context
145147
def build_cmd(ctx, path,venv):
146148
"""Execute 'build' entrypoint in fedn.yaml.

0 commit comments

Comments
 (0)