From dfbff4ea841a61ebe40d67ed0f69c981ecd1e768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Mr=C3=A1zek?= Date: Mon, 10 Oct 2022 10:44:39 +0200 Subject: [PATCH] feat: allow notebook and managed notebook version --- src/wanna/cli/plugins/common_options.py | 4 ++++ src/wanna/cli/plugins/job_plugin.py | 5 +++-- src/wanna/cli/plugins/managed_notebook_plugin.py | 15 ++++++++++----- src/wanna/cli/plugins/notebook_plugin.py | 13 +++++++++---- src/wanna/cli/plugins/pipeline_plugin.py | 9 +++++---- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/wanna/cli/plugins/common_options.py b/src/wanna/cli/plugins/common_options.py index acdaf11..e1956bd 100644 --- a/src/wanna/cli/plugins/common_options.py +++ b/src/wanna/cli/plugins/common_options.py @@ -35,3 +35,7 @@ def instance_name_option(instance_type: str, operation: str, help: str = None): or f"Specify only one {instance_type} from your wanna-ml yaml configuration to {operation}. " f"Choose 'all' to {operation} all {instance_type}s.", ) + + +def version_option(instance_type: str): + return typer.Option("dev", "--version", "-v", help=f"{instance_type} version") diff --git a/src/wanna/cli/plugins/job_plugin.py b/src/wanna/cli/plugins/job_plugin.py index ca03242..44f9a51 100644 --- a/src/wanna/cli/plugins/job_plugin.py +++ b/src/wanna/cli/plugins/job_plugin.py @@ -8,6 +8,7 @@ instance_name_option, profile_name_option, push_mode_option, + version_option, wanna_file_option, ) from wanna.core.deployment.models import PushMode @@ -51,7 +52,7 @@ def build( def push( file: Path = wanna_file_option, profile_name: str = profile_name_option, - version: str = typer.Option(..., "--version", "-v", help="Job version"), + version: str = version_option(instance_type="job"), instance_name: str = instance_name_option("job", "push"), mode: PushMode = push_mode_option, ) -> None: @@ -68,7 +69,7 @@ def push( def run( file: Path = wanna_file_option, profile_name: str = profile_name_option, - version: str = typer.Option(..., "--version", "-v", help="Job version"), + version: str = version_option(instance_type="job"), instance_name: str = instance_name_option("job", "run"), hp_params: Path = typer.Option(None, "--hp-params", "-hp", help="Path to the params file in yaml format"), sync: bool = typer.Option(False, "--sync", "-s", help="Runs the job in sync mode"), diff --git a/src/wanna/cli/plugins/managed_notebook_plugin.py b/src/wanna/cli/plugins/managed_notebook_plugin.py index 1ed55ac..bc89cda 100644 --- a/src/wanna/cli/plugins/managed_notebook_plugin.py +++ b/src/wanna/cli/plugins/managed_notebook_plugin.py @@ -8,6 +8,7 @@ instance_name_option, profile_name_option, push_mode_option, + version_option, wanna_file_option, ) from wanna.core.deployment.models import PushMode @@ -55,6 +56,7 @@ def create( file: Path = wanna_file_option, profile_name: str = profile_name_option, instance_name: str = instance_name_option("managed_notebook", "create"), + version: str = version_option(instance_type="managed notebook"), mode: PushMode = push_mode_option, ) -> None: """ @@ -67,7 +69,7 @@ def create( """ config = load_config_from_yaml(file, gcp_profile_name=profile_name) workdir = pathlib.Path(file).parent.resolve() - nb_service = ManagedNotebookService(config=config, workdir=workdir) + nb_service = ManagedNotebookService(config=config, workdir=workdir, version=version) nb_service.create(instance_name, push_mode=mode) @staticmethod @@ -75,6 +77,7 @@ def sync( file: Path = wanna_file_option, profile_name: str = profile_name_option, force: bool = typer.Option(False, "--force", help="Synchronisation without prompt"), + version: str = version_option(instance_type="managed notebook"), mode: PushMode = push_mode_option, ) -> None: """ @@ -87,7 +90,7 @@ def sync( """ config = load_config_from_yaml(file, gcp_profile_name=profile_name) workdir = pathlib.Path(file).parent.resolve() - nb_service = ManagedNotebookService(config=config, workdir=workdir) + nb_service = ManagedNotebookService(config=config, workdir=workdir, version=version) nb_service.sync(force=force, push_mode=mode) @staticmethod @@ -115,20 +118,22 @@ def report( def build( file: Path = wanna_file_option, profile_name: str = profile_name_option, + version: str = version_option(instance_type="managed notebook"), ) -> None: """ Validates build of notebooks as they are defined in wanna.yaml. """ config = load_config_from_yaml(file, gcp_profile_name=profile_name) workdir = pathlib.Path(file).parent.resolve() - nb_service = ManagedNotebookService(config=config, workdir=workdir) + nb_service = ManagedNotebookService(config=config, workdir=workdir, version=version) nb_service.build() @staticmethod def push( file: Path = wanna_file_option, profile_name: str = profile_name_option, - instance_name: str = instance_name_option("notebook", "push"), + instance_name: str = instance_name_option("managed notebook", "push"), + version: str = version_option(instance_type="managed notebook"), mode: PushMode = typer.Option( PushMode.containers, "--mode", @@ -148,5 +153,5 @@ def push( config = load_config_from_yaml(file, gcp_profile_name=profile_name) workdir = pathlib.Path(file).parent.resolve() - nb_service = ManagedNotebookService(config=config, workdir=workdir) + nb_service = ManagedNotebookService(config=config, workdir=workdir, version=version) nb_service.push(instance_name=instance_name) diff --git a/src/wanna/cli/plugins/notebook_plugin.py b/src/wanna/cli/plugins/notebook_plugin.py index 67da865..b4c0828 100644 --- a/src/wanna/cli/plugins/notebook_plugin.py +++ b/src/wanna/cli/plugins/notebook_plugin.py @@ -9,6 +9,7 @@ instance_name_option, profile_name_option, push_mode_option, + version_option, wanna_file_option, ) from wanna.core.deployment.models import PushMode @@ -58,6 +59,7 @@ def create( profile_name: str = profile_name_option, instance_name: str = instance_name_option("notebook", "create"), owner: Optional[str] = typer.Option(None, "--owner", "-o", help=""), + version: str = version_option(instance_type="notebook"), mode: PushMode = push_mode_option, ) -> None: """ @@ -70,7 +72,7 @@ def create( """ config = load_config_from_yaml(file, gcp_profile_name=profile_name) workdir = pathlib.Path(file).parent.resolve() - nb_service = NotebookService(config=config, workdir=workdir, owner=owner) + nb_service = NotebookService(config=config, workdir=workdir, owner=owner, version=version) nb_service.create(instance_name, push_mode=mode) @staticmethod @@ -137,13 +139,14 @@ def report( def build( file: Path = wanna_file_option, profile_name: str = profile_name_option, + version: str = version_option(instance_type="notebook"), ) -> None: """ Validates build of notebooks as they are defined in wanna.yaml """ config = load_config_from_yaml(file, gcp_profile_name=profile_name) workdir = pathlib.Path(file).parent.resolve() - nb_service = NotebookService(config=config, workdir=workdir) + nb_service = NotebookService(config=config, workdir=workdir, version=version) nb_service.build() @staticmethod @@ -151,6 +154,7 @@ def push( file: Path = wanna_file_option, profile_name: str = profile_name_option, instance_name: str = instance_name_option("notebook", "push"), + version: str = version_option(instance_type="notebook"), mode: PushMode = typer.Option( PushMode.containers, "--mode", @@ -170,7 +174,7 @@ def push( config = load_config_from_yaml(file, gcp_profile_name=profile_name) workdir = pathlib.Path(file).parent.resolve() - nb_service = NotebookService(config=config, workdir=workdir) + nb_service = NotebookService(config=config, workdir=workdir, version=version) nb_service.push(instance_name=instance_name) @staticmethod @@ -178,6 +182,7 @@ def sync( file: Path = wanna_file_option, profile_name: str = profile_name_option, force: bool = typer.Option(False, "--force", help="Synchronisation without prompt"), + version: str = version_option(instance_type="notebook"), mode: PushMode = push_mode_option, ) -> None: """ @@ -190,5 +195,5 @@ def sync( """ config = load_config_from_yaml(file, gcp_profile_name=profile_name) workdir = pathlib.Path(file).parent.resolve() - nb_service = NotebookService(config=config, workdir=workdir) + nb_service = NotebookService(config=config, workdir=workdir, version=version) nb_service.sync(force=force, push_mode=mode) diff --git a/src/wanna/cli/plugins/pipeline_plugin.py b/src/wanna/cli/plugins/pipeline_plugin.py index 138416c..b93584b 100644 --- a/src/wanna/cli/plugins/pipeline_plugin.py +++ b/src/wanna/cli/plugins/pipeline_plugin.py @@ -8,6 +8,7 @@ instance_name_option, profile_name_option, push_mode_option, + version_option, wanna_file_option, ) from wanna.core.deployment.models import PushMode @@ -35,7 +36,7 @@ def __init__(self) -> None: @staticmethod def build( - version: str = typer.Option("dev", "--version", "-v", help="Pipeline version"), + version: str = version_option(instance_type="pipeline"), file: Path = wanna_file_option, profile_name: str = profile_name_option, instance_name: str = instance_name_option("pipeline", "compile"), @@ -51,7 +52,7 @@ def build( @staticmethod def push( - version: str = typer.Option(..., "--version", "-v", help="Pipeline version"), + version: str = version_option(instance_type="pipeline"), file: Path = wanna_file_option, profile_name: str = profile_name_option, instance_name: str = instance_name_option("pipeline", "push"), @@ -68,7 +69,7 @@ def push( @staticmethod def deploy( - version: str = typer.Option(..., "--version", "-v", help="Pipeline version"), + version: str = version_option(instance_type="pipeline"), env: str = typer.Option("local", "--env", "-e", help="Pipeline env"), file: Path = wanna_file_option, profile_name: str = profile_name_option, @@ -85,7 +86,7 @@ def deploy( @staticmethod def run( - version: str = typer.Option("dev", "--version", "-v", help="Pipeline version"), + version: str = version_option(instance_type="pipeline notebook"), params: Path = typer.Option(None, "--params", help="Path to the params file in yaml format"), sync: bool = typer.Option(False, "--sync", "-s", help="Runs the pipeline in sync mode"), file: Path = wanna_file_option,