Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/SK-944 + SK-934 | Add flag for deleting the virtual env #661

Merged
merged 19 commits into from
Sep 2, 2024

Conversation

sowmyasris
Copy link
Contributor

@sowmyasris sowmyasris commented Jul 19, 2024

"keep-venv" flag is added to run command
Default is set to True, removing the virtual environment after every command
Can be set to False, to reuse the environment for executing other commands
Tested with mnist-pytorch example

Added test cases for Fedn cli commans train, validate, startup, verifying version, controller start

Added Gunicorn server as production server if the debug is set to False

@github-actions github-actions bot added minor feature New feature or request labels Jul 19, 2024
@sowmyasris sowmyasris requested a review from Wrede July 19, 2024 08:02
@sowmyasris sowmyasris changed the title Feature/sk 944 | Add flag for deleting the virtual env Feature/sk-944 | Add flag for deleting the virtual env Jul 19, 2024
@sowmyasris sowmyasris changed the title Feature/sk-944 | Add flag for deleting the virtual env Feature / SK-944 | Add flag for deleting the virtual env Jul 19, 2024
@sowmyasris sowmyasris changed the title Feature / SK-944 | Add flag for deleting the virtual env Feature/SK-944 | Add flag for deleting the virtual env Jul 19, 2024
fedn/cli/run_cmd.py Outdated Show resolved Hide resolved

@run_cmd.command("build")
@click.option("-p", "--path", required=True, help="Path to package directory containing fedn.yaml")
@click.option("-v", "--venv", default=True,type=bool,required=False, help="flag if set to False doesn't remove venv")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add space after ",", are you not using ruff in your IDE?

Copy link
Contributor Author

@sowmyasris sowmyasris Jul 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I am using ruff in my IDE

fedn/cli/run_cmd.py Outdated Show resolved Hide resolved
logging the behaviour of venv not found
changed the import
test cases for CLI command train,validate,startup,controller start and version
@sowmyasris sowmyasris requested a review from sztoor July 26, 2024 11:32
Copy link
Member

@Wrede Wrede left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good! Some changes requested

@@ -46,20 +53,18 @@ def run_cmd(ctx):
@run_cmd.command("validate")
@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("-o", "--output", required=True, help="Path to write the output JSON containing validation metrics")
@click.option("-v", "--remove-venv", default=True, type=bool, required=False, help="flag if set to False doesn't remove venv")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use is_flag=True here, since it's bool. It will be a better UX

if dispatcher.python_env_path:
logger.info(f"Removing virtualenv {dispatcher.python_env_path}")
shutil.rmtree(dispatcher.python_env_path)
if remove_venv:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps move this if statement to a separate function that can be used within each subcommand? A lot of redundancy now

pyproject.toml Outdated
@@ -31,6 +31,7 @@ requires-python = '>=3.8,<3.13'
dependencies = [
"requests",
"urllib3>=1.26.4",
"gunicorn>=20.0.4,<21.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reason for the upper limit?

fedn/network/api/server.py Outdated Show resolved Hide resolved
@Wrede Wrede changed the title Feature/SK-944 | Add flag for deleting the virtual env Feature/SK-944 + SK-934 | Add flag for deleting the virtual env Aug 12, 2024
def run_gunicorn(app, workers=4):
workers=os.cpu_count()
options = {
"bind": "127.0.0.1:8000", # Specify the bind address and port here
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hard coded host and port, should use host and port from config file, see debug case

fedn/network/api/gunicorn_app.py Outdated Show resolved Hide resolved
@sowmyasris sowmyasris requested a review from Wrede August 13, 2024 14:11
Copy link
Member

@Wrede Wrede left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more changes required

@@ -54,7 +61,7 @@ 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", default=True, type=bool, required=False, help="flag if set to False doesn't remove venv")
@click.option("-v", "--remove-venv", is_flag=True, default=True,required=False, help="flag if set to False doesn't remove venv")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need default=True when is_flag=True

shutil.rmtree(dispatcher.python_env_path)
else:
logger.warning("No virtualenv found to remove.")
print(remove_venv)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove print

def run_gunicorn(app, workers=4):
workers=os.cpu_count()
def run_gunicorn(app, host,port,workers=4):
bind_address=str(host)+":"+str(port)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is ok but a better way is:

bind_address = f"{host}:{port}"

fedn/network/api/server.py Outdated Show resolved Hide resolved
@sowmyasris sowmyasris requested a review from Wrede August 14, 2024 11:47
Copy link
Member

@Wrede Wrede left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic is very confusing, the flag can be called keep-venv which is by default true. then in the logic for the variable you can do:

if not keep_venv:
delete_virtual_environment(dispatcher)

In other words don't do the check if keep_venv is True or False in the function.

fedn/cli/run_cmd.py Outdated Show resolved Hide resolved
@sowmyasris sowmyasris requested a review from Wrede August 19, 2024 09:40
app.run(debug=debug, port=port, host=host)


config = get_controller_config()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent wrong?

Copy link
Member

@Wrede Wrede left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check indent

@Wrede Wrede merged commit df222ea into master Sep 2, 2024
17 of 18 checks passed
@Wrede Wrede deleted the feature/SK-944 branch September 2, 2024 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request minor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants