Skip to content

Commit

Permalink
feat: allow notebook and managed notebook version (#58)
Browse files Browse the repository at this point in the history
## Describe your changes

## Issue ticket number and link

## Checklist before requesting a review
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] If it is a core feature, I have added thorough tests.
  • Loading branch information
michalmrazek authored Oct 10, 2022
2 parents 65904b3 + dfbff4e commit 7b90840
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/wanna/cli/plugins/common_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
5 changes: 3 additions & 2 deletions src/wanna/cli/plugins/job_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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"),
Expand Down
15 changes: 10 additions & 5 deletions src/wanna/cli/plugins/managed_notebook_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
"""
Expand All @@ -67,14 +69,15 @@ 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
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:
"""
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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)
13 changes: 9 additions & 4 deletions src/wanna/cli/plugins/notebook_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
"""
Expand All @@ -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
Expand Down Expand Up @@ -137,20 +139,22 @@ 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
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",
Expand All @@ -170,14 +174,15 @@ 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
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:
"""
Expand All @@ -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)
9 changes: 5 additions & 4 deletions src/wanna/cli/plugins/pipeline_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"),
Expand All @@ -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"),
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 7b90840

Please sign in to comment.