-
Notifications
You must be signed in to change notification settings - Fork 36
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
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b963f4b
flag for not deleting the venv
sowmyasris 395c755
Merge branch 'master' of https://github.com/scaleoutsystems/fedn into…
sowmyasris 060907d
added flag to reuse the existing env without deleting , default is to…
sowmyasris 55e179a
fixed the build command and added the path flag
sowmyasris da5654d
changed flag to remove-venv
sowmyasris a67f1df
wrapped check yaml exist to separate method
sowmyasris 5b21200
added Gunicorn server as production server, if the debug is False in …
sowmyasris 9961836
ruff double quotes error corrected
sowmyasris 69795a1
fixed the function exxecution during import
sowmyasris 488d9f2
added gunicorn dependency in pyproject.toml
sowmyasris e8eb846
fixed the import error
sowmyasris 41d0db7
updated the code with the changes suggested
sowmyasris aa947c7
removed unused package
sowmyasris 1d353ae
changed the virtual-env flag to keep-venv and some code clean up
sowmyasris 37c9bd1
run_cmd updated with keep-venv flag
sowmyasris e67db30
code clean up
sowmyasris c685cff
Merge branch 'master' of https://github.com/scaleoutsystems/fedn into…
sowmyasris 317904c
updated help command
sowmyasris 7847b70
fixed indent issue
sowmyasris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import click | ||
|
||
from .main import main | ||
from fedn.cli.main import main | ||
|
||
|
||
@main.group("controller") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,9 @@ | |
from fedn.network.combiner.combiner import Combiner | ||
from fedn.utils.dispatcher import Dispatcher, _read_yaml_file | ||
|
||
from .client_cmd import validate_client_config | ||
from .main import main | ||
from .shared import apply_config | ||
|
||
from fedn.cli.client_cmd import validate_client_config | ||
from fedn.cli.main import main | ||
from fedn.cli.shared import apply_config | ||
|
||
def get_statestore_config_from_file(init): | ||
""":param init: | ||
|
@@ -36,7 +35,22 @@ def check_helper_config_file(config): | |
exit(-1) | ||
return helper | ||
|
||
|
||
def check_yaml_exists(path): | ||
"""Check if fedn.yaml exists in the given 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}") | ||
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: | ||
# delete the virtualenv | ||
if dispatcher.python_env_path: | ||
logger.info(f"Removing virtualenv {dispatcher.python_env_path}") | ||
shutil.rmtree(dispatcher.python_env_path) | ||
else: | ||
logger.warning("No virtualenv found to remove.") | ||
@main.group("run") | ||
@click.pass_context | ||
def run_cmd(ctx): | ||
|
@@ -46,20 +60,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", 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): | ||
def validate_cmd(ctx, path,input,output,remove_venv): | ||
"""Execute 'validate' 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) | ||
yaml_file = check_yaml_exists(path) | ||
|
||
config = _read_yaml_file(yaml_file) | ||
# Check that validate is defined in fedn.yaml under entry_points | ||
|
@@ -70,28 +82,22 @@ def validate_cmd(ctx, path,input,output): | |
dispatcher = Dispatcher(config, path) | ||
_ = dispatcher._get_or_create_python_env() | ||
dispatcher.run_cmd("validate {} {}".format(input, output)) | ||
|
||
# delete the virtualenv | ||
if dispatcher.python_env_path: | ||
logger.info(f"Removing virtualenv {dispatcher.python_env_path}") | ||
shutil.rmtree(dispatcher.python_env_path) | ||
delete_virtual_environment(remove_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("-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.pass_context | ||
def train_cmd(ctx, path,input,output): | ||
def train_cmd(ctx, path,input,output,remove_venv): | ||
"""Execute 'train' 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) | ||
yaml_file = check_yaml_exists(path) | ||
|
||
config = _read_yaml_file(yaml_file) | ||
# Check that train is defined in fedn.yaml under entry_points | ||
|
@@ -102,26 +108,21 @@ def train_cmd(ctx, path,input,output): | |
dispatcher = Dispatcher(config, path) | ||
_ = dispatcher._get_or_create_python_env() | ||
dispatcher.run_cmd("train {} {}".format(input, output)) | ||
delete_virtual_environment(remove_venv,dispatcher) | ||
|
||
# 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("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.pass_context | ||
def startup_cmd(ctx, path): | ||
def startup_cmd(ctx, path,remove_venv): | ||
"""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) | ||
yaml_file = check_yaml_exists(path) | ||
|
||
config = _read_yaml_file(yaml_file) | ||
# Check that startup is defined in fedn.yaml under entry_points | ||
|
@@ -132,27 +133,22 @@ def startup_cmd(ctx, path): | |
dispatcher = Dispatcher(config, path) | ||
_ = dispatcher._get_or_create_python_env() | ||
dispatcher.run_cmd("startup") | ||
delete_virtual_environment(remove_venv,dispatcher) | ||
|
||
# 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") | ||
@click.option("-v", "--remove-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): | ||
def build_cmd(ctx, path,remove_venv): | ||
"""Execute 'build' 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) | ||
yaml_file = check_yaml_exists(path) | ||
|
||
config = _read_yaml_file(yaml_file) | ||
# Check that build is defined in fedn.yaml under entry_points | ||
|
@@ -163,11 +159,9 @@ def build_cmd(ctx, path): | |
dispatcher = Dispatcher(config, path) | ||
_ = dispatcher._get_or_create_python_env() | ||
dispatcher.run_cmd("build") | ||
print(remove_venv) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove print |
||
delete_virtual_environment(remove_venv,dispatcher) | ||
|
||
# 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("client") | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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