Skip to content

Commit

Permalink
changed the virtual-env flag to keep-venv and some code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
sowmyasris committed Aug 14, 2024
1 parent aa947c7 commit 1d353ae
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
30 changes: 14 additions & 16 deletions fedn/cli/run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def check_yaml_exists(path):
click.echo(f"Could not find fedn.yaml in {path}")
exit(-1)
return yaml_file
def delete_virtual_environment(remove_venv,dispatcher):
if remove_venv:
def delete_virtual_environment(keep_venv, dispatcher):
if keep_venv:
# delete the virtualenv
if dispatcher.python_env_path:
logger.info(f"Removing virtualenv {dispatcher.python_env_path}")
Expand All @@ -61,9 +61,9 @@ def run_cmd(ctx):
@click.option("-p", "--path", required=True, help="Path to package directory containing fedn.yaml")
@click.option("-i", "--input", required=True, help="Path to input model" )
@click.option("-o", "--output", required=True, help="Path to write the output JSON containing validation metrics")
@click.option("-v", "--remove-venv", is_flag=True, default=True,required=False, help="flag if set to False doesn't remove venv")
@click.option("-v", "--keep-venv", is_flag=True, default=True, required=False, help="flag if set to False doesn't remove venv")
@click.pass_context
def validate_cmd(ctx, path,input,output,remove_venv):
def validate_cmd(ctx, path, input, output, keep_venv):
"""Execute 'validate' entrypoint in fedn.yaml.
:param ctx:
Expand All @@ -82,14 +82,14 @@ def validate_cmd(ctx, path,input,output,remove_venv):
dispatcher = Dispatcher(config, path)
_ = dispatcher._get_or_create_python_env()
dispatcher.run_cmd("validate {} {}".format(input, output))
delete_virtual_environment(remove_venv,dispatcher)
delete_virtual_environment(keep_venv, dispatcher)
@run_cmd.command("train")
@click.option("-p", "--path", required=True, help="Path to package directory containing fedn.yaml")
@click.option("-i", "--input", required=True, help="Path to input model parameters" )
@click.option("-o", "--output", required=True, help="Path to write the updated model parameters ")
@click.option("-v", "--remove-venv", is_flag=True, default=True,required=False, help="flag if set to False doesn't remove venv")
@click.option("-v", "--keep-venv", is_flag=True, default=True, required=False, help="flag if set to False doesn't remove venv")
@click.pass_context
def train_cmd(ctx, path,input,output,remove_venv):
def train_cmd(ctx, path, input, output, keep_venv):
"""Execute 'train' entrypoint in fedn.yaml.
:param ctx:
Expand All @@ -108,13 +108,13 @@ def train_cmd(ctx, path,input,output,remove_venv):
dispatcher = Dispatcher(config, path)
_ = dispatcher._get_or_create_python_env()
dispatcher.run_cmd("train {} {}".format(input, output))
delete_virtual_environment(remove_venv,dispatcher)
delete_virtual_environment(keep_venv, dispatcher)

@run_cmd.command("startup")
@click.option("-p", "--path", required=True, help="Path to package directory containing fedn.yaml")
@click.option("-v", "--remove-venv", is_flag=True, default=True,required=False, help="flag if set to False doesn't remove venv")
@click.option("-v", "--keep-venv", is_flag=True, default=True, required=False, help="flag if set to False doesn't remove venv")
@click.pass_context
def startup_cmd(ctx, path,remove_venv):
def startup_cmd(ctx, path, keep_venv):
"""Execute 'startup' entrypoint in fedn.yaml.
:param ctx:
Expand All @@ -129,18 +129,17 @@ def startup_cmd(ctx, path,remove_venv):
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_virtual_environment(remove_venv,dispatcher)
delete_virtual_environment(keep_venv, dispatcher)


@run_cmd.command("build")
@click.option("-p", "--path", required=True, help="Path to package directory containing fedn.yaml")
@click.option("-v", "--remove-venv", is_flag=True, default=True,required=False, help="flag if set to False doesn't remove venv")
@click.option("-v", "--keep-venv", is_flag=True, default=True, required=False, help="flag if set to False doesn't remove venv")
@click.pass_context
def build_cmd(ctx, path,remove_venv):
def build_cmd(ctx, path, keep_venv):
"""Execute 'build' entrypoint in fedn.yaml.
:param ctx:
Expand All @@ -159,8 +158,7 @@ def build_cmd(ctx, path,remove_venv):
dispatcher = Dispatcher(config, path)
_ = dispatcher._get_or_create_python_env()
dispatcher.run_cmd("build")
print(remove_venv)
delete_virtual_environment(remove_venv,dispatcher)
delete_virtual_environment(keep_venv, dispatcher)



Expand Down
2 changes: 1 addition & 1 deletion fedn/network/api/gunicorn_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def load(self):
return self.application

def run_gunicorn(app, host,port,workers=4):
bind_address=str(host)+":"+str(port)
bind_address = f"{host}:{port}"
options = {
"bind": bind_address, # Specify the bind address and port here
"workers": workers,
Expand Down
2 changes: 1 addition & 1 deletion fedn/network/api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,6 @@ def start_server_api():
app.run(debug=debug, port=port, host=host)
else:
workers=os.cpu_count()
gunicorn_app.run_gunicorn(app,host,port,workers)
gunicorn_app.run_gunicorn(app, host, port, workers)
if __name__ == "__main__":
start_server_api()

0 comments on commit 1d353ae

Please sign in to comment.