From 9f0653db1bc86ceee373b3fd0c3457c3dc5781de Mon Sep 17 00:00:00 2001 From: asmijafar20 Date: Sat, 10 Sep 2022 21:54:36 +0530 Subject: [PATCH 1/4] Nebari typer cli commands --- qhub/cli/main.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/qhub/cli/main.py b/qhub/cli/main.py index 035eeaf93a..692af1b01e 100644 --- a/qhub/cli/main.py +++ b/qhub/cli/main.py @@ -88,12 +88,19 @@ def init( @app.command() -def validate(): +def validate( + config: str = typer.Option( + "--config", + help="qhub configuration yaml file (deprecated - please pass in as -c/--config flag)", + ##required=true, + callback=verify, + ), +): """ Validate the config.yaml file. """ - print("Validate the config.yaml file") + ##print("Validate the config.yaml file") @app.command() From 83add57216dae2830f2899ebb8b5baaea5bb0507 Mon Sep 17 00:00:00 2001 From: asmijafar20 Date: Sun, 11 Sep 2022 18:59:27 +0530 Subject: [PATCH 2/4] add validate command --- qhub/cli/main.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/qhub/cli/main.py b/qhub/cli/main.py index 692af1b01e..cd0ec8f2be 100644 --- a/qhub/cli/main.py +++ b/qhub/cli/main.py @@ -3,8 +3,9 @@ from typer.core import TyperGroup from qhub.cli._init import check_cloud_provider_creds -from qhub.schema import ProviderEnum - +from qhub.schema import ProviderEnum, verify +from qhub.utils import load_yaml +import pathlib def enum_to_list(enum_cls): return [e.value for e in enum_cls] @@ -34,7 +35,7 @@ def init( ), project_name: str = typer.Option( None, - "--project-name", + "--project-name", "--project", prompt=True, # callback=project_name_convention @@ -82,17 +83,23 @@ def init( ), ): """ - Initialize the nebari-config.yaml file. + Initialize nebari-config.yaml file. """ - @app.command() def validate( - config: str = typer.Option( - "--config", - help="qhub configuration yaml file (deprecated - please pass in as -c/--config flag)", + config_filename: str = typer.Argument( + ..., + help="qhub configuration yaml file", ##required=true, + callback=load_yaml, + ), + config: str = typer.Option( + None, + "--config", + "-c", + help="qhub configuration yaml file, please pass in as -c/--config flag", callback=verify, ), ): @@ -103,12 +110,12 @@ def validate( ##print("Validate the config.yaml file") + @app.command() def render(): """ Render the config.yaml file. """ - print("Render the congig.yaml file") @app.command() From 7cc03ce13657522f378384d16cf988eefdbce042 Mon Sep 17 00:00:00 2001 From: asmijafar20 Date: Mon, 12 Sep 2022 18:48:29 +0530 Subject: [PATCH 3/4] Change validate command --- qhub/cli/main.py | 35 +++++++++++++++++++++++++---------- setup.cfg | 2 +- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/qhub/cli/main.py b/qhub/cli/main.py index cd0ec8f2be..25cb2a4052 100644 --- a/qhub/cli/main.py +++ b/qhub/cli/main.py @@ -5,7 +5,7 @@ from qhub.cli._init import check_cloud_provider_creds from qhub.schema import ProviderEnum, verify from qhub.utils import load_yaml -import pathlib +import pathlib def enum_to_list(enum_cls): return [e.value for e in enum_cls] @@ -89,25 +89,40 @@ def init( @app.command() def validate( - config_filename: str = typer.Argument( - ..., - help="qhub configuration yaml file", - ##required=true, - callback=load_yaml, - ), + config: str = typer.Option( None, "--config", "-c", - help="qhub configuration yaml file, please pass in as -c/--config flag", - callback=verify, + help="qhub configuration yaml file path, please pass in as -c/--config flag", ), + enable_commenting: bool = typer.Option( + False, + "--enable_commenting", + help="Toggle PR commenting on GitHub Actions" + ) ): """ Validate the config.yaml file. """ - ##print("Validate the config.yaml file") + #print(f"Validate the {config}") + + config_filename = pathlib.Path(config) + if not config_filename.is_file(): + raise ValueError( + f"Passed in configuration filename={config_filename} must exist." + ) + + config = load_yaml(config_filename) + + if enable_commenting: + # for PR's only + # comment_on_pr(config) + pass + else: + verify(config) + print("Successfully validated configuration") diff --git a/setup.cfg b/setup.cfg index 6ed83f96a8..314d5a97c3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -57,7 +57,7 @@ dev = [options.entry_points] console_scripts = qhub = qhub.__main__:main - nebari = qhub.cli.main.__main__ + nebari = qhub.cli.main:app [tool:pytest] norecursedirs = _build .nox .ipynb_checkpoints From 698e16c78b7782114491e60274fcb1f37be5d873 Mon Sep 17 00:00:00 2001 From: asmijafar20 Date: Mon, 12 Sep 2022 20:08:04 +0530 Subject: [PATCH 4/4] add precommit --- qhub/cli/main.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/qhub/cli/main.py b/qhub/cli/main.py index 25cb2a4052..21c3559e21 100644 --- a/qhub/cli/main.py +++ b/qhub/cli/main.py @@ -1,3 +1,5 @@ +import pathlib + import typer from click import Context from typer.core import TyperGroup @@ -5,7 +7,7 @@ from qhub.cli._init import check_cloud_provider_creds from qhub.schema import ProviderEnum, verify from qhub.utils import load_yaml -import pathlib + def enum_to_list(enum_cls): return [e.value for e in enum_cls] @@ -35,7 +37,7 @@ def init( ), project_name: str = typer.Option( None, - "--project-name", + "--project-name", "--project", prompt=True, # callback=project_name_convention @@ -87,26 +89,24 @@ def init( """ + @app.command() def validate( - config: str = typer.Option( None, - "--config", + "--config", "-c", help="qhub configuration yaml file path, please pass in as -c/--config flag", ), enable_commenting: bool = typer.Option( - False, - "--enable_commenting", - help="Toggle PR commenting on GitHub Actions" - ) + False, "--enable_commenting", help="Toggle PR commenting on GitHub Actions" + ), ): """ Validate the config.yaml file. """ - #print(f"Validate the {config}") + # print(f"Validate the {config}") config_filename = pathlib.Path(config) if not config_filename.is_file(): @@ -125,7 +125,6 @@ def validate( print("Successfully validated configuration") - @app.command() def render(): """