From 0583d7a21d451e645278ef610f36ef7147188108 Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Thu, 4 Jan 2024 15:31:20 +0000 Subject: [PATCH 01/13] Add check for if starter is used Signed-off-by: Ahdra Merali --- kedro/framework/cli/starters.py | 7 +++++-- tests/framework/cli/test_starters.py | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/kedro/framework/cli/starters.py b/kedro/framework/cli/starters.py index 20e0916775..9dd0b196bf 100644 --- a/kedro/framework/cli/starters.py +++ b/kedro/framework/cli/starters.py @@ -851,9 +851,12 @@ def _create_project(template_path: str, cookiecutter_args: dict[str, Any]): f"\nYour project '{project_name}' has been created in the directory \n{result_path}\n" ) - # we can use starters without tools: + # End here if a starter was used + if template_path != TEMPLATE_PATH: + return + if tools is not None: - if tools == "['None']": # TODO: This should be a list + if tools == "['None']": click.secho( "You have selected no project tools", fg="green", diff --git a/tests/framework/cli/test_starters.py b/tests/framework/cli/test_starters.py index f64b7ba245..75de605a3d 100644 --- a/tests/framework/cli/test_starters.py +++ b/tests/framework/cli/test_starters.py @@ -865,6 +865,7 @@ def test_no_hint(self, fake_kedro_cli): "To skip the interactive flow you can run `kedro new` with\nkedro new --name= --tools= --example=" not in result.output ) + assert "You have selected" not in result.output _assert_template_ok(result) _clean_up_project(Path("./new-kedro-project")) From 89c196f89846d4189b18f491741b1302087ba635 Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Thu, 4 Jan 2024 16:09:34 +0000 Subject: [PATCH 02/13] Move messages to access starter_alias Signed-off-by: Ahdra Merali --- kedro/framework/cli/starters.py | 55 ++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/kedro/framework/cli/starters.py b/kedro/framework/cli/starters.py index 9dd0b196bf..94f5e25da2 100644 --- a/kedro/framework/cli/starters.py +++ b/kedro/framework/cli/starters.py @@ -299,7 +299,35 @@ def new( # noqa: PLR0913 _create_project(project_template, cookiecutter_args) - if prompts_required and not config_path and not starter_alias: + # End here if a starter was used + if starter_alias: + return + + # Print tools and example selection + tools = extra_context.get("tools") + example_pipeline = extra_context.get("example_pipeline") + + if tools is not None: + if tools == "['None']": + click.secho( + "You have selected no project tools", + fg="green", + ) + else: + click.secho( + f"You have selected the following project tools: {tools}", + fg="green", + ) + + if example_pipeline is not None: + if example_pipeline: + click.secho( + "It has been created with an example pipeline.", + fg="green", + ) + + # If interactive flow used, print hint + if prompts_required and not config_path: click.secho( "\nTo skip the interactive flow you can run `kedro new` with" "\nkedro new --name= --tools= --example=", @@ -843,36 +871,13 @@ def _create_project(template_path: str, cookiecutter_args: dict[str, Any]): _clean_pycache(Path(result_path)) extra_context = cookiecutter_args["extra_context"] project_name = extra_context.get("project_name", "New Kedro Project") - tools = extra_context.get("tools") - example_pipeline = extra_context.get("example_pipeline") + # Print success message click.secho( "\nCongratulations!" f"\nYour project '{project_name}' has been created in the directory \n{result_path}\n" ) - # End here if a starter was used - if template_path != TEMPLATE_PATH: - return - - if tools is not None: - if tools == "['None']": - click.secho( - "You have selected no project tools", - fg="green", - ) - else: - click.secho( - f"You have selected the following project tools: {tools}", - fg="green", - ) - - if example_pipeline is not None: - if example_pipeline: - click.secho( - "It has been created with an example pipeline.", - fg="green", - ) class _Prompt: From e9e50004e7cfcaa137bf685606774e6d6f5f0ec6 Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Thu, 4 Jan 2024 16:13:17 +0000 Subject: [PATCH 03/13] Lint Signed-off-by: Ahdra Merali --- kedro/framework/cli/starters.py | 1 - 1 file changed, 1 deletion(-) diff --git a/kedro/framework/cli/starters.py b/kedro/framework/cli/starters.py index 94f5e25da2..d6ac93a130 100644 --- a/kedro/framework/cli/starters.py +++ b/kedro/framework/cli/starters.py @@ -879,7 +879,6 @@ def _create_project(template_path: str, cookiecutter_args: dict[str, Any]): ) - class _Prompt: """Represent a single CLI prompt for `kedro new`""" From af02d9098d7936415b4f2eb38cbf59f5bfb3c378 Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Thu, 4 Jan 2024 16:17:54 +0000 Subject: [PATCH 04/13] Lint again Signed-off-by: Ahdra Merali --- kedro/framework/cli/starters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kedro/framework/cli/starters.py b/kedro/framework/cli/starters.py index d6ac93a130..bff88ccf7b 100644 --- a/kedro/framework/cli/starters.py +++ b/kedro/framework/cli/starters.py @@ -212,7 +212,7 @@ def starter(): @click.option("--tools", "-t", "selected_tools", help=TOOLS_ARG_HELP) @click.option("--name", "-n", "project_name", help=NAME_ARG_HELP) @click.option("--example", "-e", "example_pipeline", help=EXAMPLE_ARG_HELP) -def new( # noqa: PLR0913 +def new( # noqa: PLR0912,PLR0913 config_path, starter_alias, selected_tools, From af8e236bcb25f2cff3aa6622b12775bb0645f513 Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Thu, 4 Jan 2024 16:27:29 +0000 Subject: [PATCH 05/13] Alternative: pass through starter in config Signed-off-by: Ahdra Merali --- kedro/framework/cli/starters.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kedro/framework/cli/starters.py b/kedro/framework/cli/starters.py index 9dd0b196bf..061b7fb275 100644 --- a/kedro/framework/cli/starters.py +++ b/kedro/framework/cli/starters.py @@ -485,6 +485,10 @@ def _get_extra_context( # noqa: PLR0913 or None in case the flag wasn't used. project_name: a string containing the value for the --name flag, or None in case the flag wasn't used. + example_pipeline: a string containing the value for the --example flag, + or None in case the flag wasn't used + starter_alias: a string containing the value for the --starter flag, or + None in case the flag wasn't used Returns: the prompts_required dictionary, with all the redundant information removed. @@ -498,6 +502,9 @@ def _get_extra_context( # noqa: PLR0913 prompts_required, cookiecutter_context ) + if starter_alias: + extra_context["starter_alias"] = starter_alias + # Format extra_context.setdefault("kedro_version", version) @@ -852,7 +859,7 @@ def _create_project(template_path: str, cookiecutter_args: dict[str, Any]): ) # End here if a starter was used - if template_path != TEMPLATE_PATH: + if extra_context.get("starter_alias"): return if tools is not None: From 4e357090214960f411bd7bc533a1ecfef6c06df5 Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Mon, 8 Jan 2024 04:40:47 +0000 Subject: [PATCH 06/13] Resolve quick TODO Signed-off-by: Ahdra Merali --- kedro/framework/cli/starters.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kedro/framework/cli/starters.py b/kedro/framework/cli/starters.py index 93992e2a10..ba03822f94 100644 --- a/kedro/framework/cli/starters.py +++ b/kedro/framework/cli/starters.py @@ -31,7 +31,6 @@ command_with_verbosity, ) -# TODO(lrcouto): Insert actual link to the documentation (Visit: kedro.org/{insert-documentation} to find out more about these tools.). TOOLS_ARG_HELP = """ Select which tools you'd like to include. By default, none are included.\n @@ -48,6 +47,8 @@ kedro new --tools=lint,test,log,docs,data,pyspark,viz (or any subset of these options)\n kedro new --tools=all\n kedro new --tools=none + +For more information on using tools, see https://docs.kedro.org/en/latest/starters/new_project_tools.html """ CONFIG_ARG_HELP = """Non-interactive mode, using a configuration yaml file. This file must supply the keys required by the template's prompts.yml. When not using a starter, From 3fe920b46cc87871db3ca56b06dd7d9249751ea8 Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Mon, 8 Jan 2024 05:26:01 +0000 Subject: [PATCH 07/13] Lint Signed-off-by: Ahdra Merali --- kedro/framework/cli/starters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kedro/framework/cli/starters.py b/kedro/framework/cli/starters.py index ba03822f94..320722c29b 100644 --- a/kedro/framework/cli/starters.py +++ b/kedro/framework/cli/starters.py @@ -236,7 +236,7 @@ def starter(): @click.option("--tools", "-t", "selected_tools", help=TOOLS_ARG_HELP) @click.option("--name", "-n", "project_name", help=NAME_ARG_HELP) @click.option("--example", "-e", "example_pipeline", help=EXAMPLE_ARG_HELP) -def new( # noqa: PLR0912,PLR0913 +def new( # noqa: PLR0913 config_path, starter_alias, selected_tools, From 1dc32c9198edf98c94cc4d2afb8f4886c25a20b6 Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Wed, 10 Jan 2024 15:06:31 +0000 Subject: [PATCH 08/13] Move flag input validation into separate function Signed-off-by: Ahdra Merali --- kedro/framework/cli/starters.py | 40 ++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/kedro/framework/cli/starters.py b/kedro/framework/cli/starters.py index 320722c29b..da6ff175be 100644 --- a/kedro/framework/cli/starters.py +++ b/kedro/framework/cli/starters.py @@ -131,6 +131,23 @@ class KedroStarterSpec: # noqa: too-few-public-methods } +def _validate_flag_inputs(flag_inputs): + if flag_inputs.get("checkout") and not flag_inputs.get("starter"): + raise KedroCliError("Cannot use the --checkout flag without a --starter value.") + + if flag_inputs.get("directory") and not flag_inputs.get("starter"): + raise KedroCliError( + "Cannot use the --directory flag without a --starter value." + ) + + if (flag_inputs.get("tools") or flag_inputs.get("example")) and flag_inputs.get( + "starter" + ): + raise KedroCliError( + "Cannot use the --starter flag with the --example and/or --tools flag." + ) + + def _validate_regex(pattern_name, text): VALIDATION_PATTERNS = { "yes_no": { @@ -247,19 +264,16 @@ def new( # noqa: PLR0913 **kwargs, ): """Create a new kedro project.""" - if checkout and not starter_alias: - raise KedroCliError("Cannot use the --checkout flag without a --starter value.") - - if directory and not starter_alias: - raise KedroCliError( - "Cannot use the --directory flag without a --starter value." - ) - - if (selected_tools or example_pipeline) and starter_alias: - raise KedroCliError( - "Cannot use the --starter flag with the --example and/or --tools flag." - ) - + flag_inputs = { + "config": config_path, + "starter": starter_alias, + "tools": selected_tools, + "name": project_name, + "checkout": checkout, + "directory": directory, + "example": example_pipeline, + } + _validate_flag_inputs(flag_inputs) starters_dict = _get_starters_dict() if starter_alias in starters_dict: From 7160bcd3246fdecc46c3fefea40ba1f6858bd8e4 Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Wed, 10 Jan 2024 15:08:40 +0000 Subject: [PATCH 09/13] Remove redundant condition Signed-off-by: Ahdra Merali --- kedro/framework/cli/starters.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kedro/framework/cli/starters.py b/kedro/framework/cli/starters.py index da6ff175be..6ad63da874 100644 --- a/kedro/framework/cli/starters.py +++ b/kedro/framework/cli/starters.py @@ -341,10 +341,9 @@ def new( # noqa: PLR0913 if starter_alias: return - # If not a starter, print tools and example selection - if not starter_alias: - _print_tools_selection(extra_context.get("tools")) - _print_example_selection(extra_context.get("example_pipeline")) + # When not a starter, print tools and example selection + _print_tools_selection(extra_context.get("tools")) + _print_example_selection(extra_context.get("example_pipeline")) # If interactive flow used, print hint if prompts_required and not config_path: From 5500b956ab5e5e35da0b647a8a6da8c369cbb8bc Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Wed, 10 Jan 2024 15:12:04 +0000 Subject: [PATCH 10/13] Change latest docs links to point to stable Signed-off-by: Ahdra Merali --- kedro/framework/cli/starters.py | 4 ++-- kedro/framework/project/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kedro/framework/cli/starters.py b/kedro/framework/cli/starters.py index 6ad63da874..e97b89a5d4 100644 --- a/kedro/framework/cli/starters.py +++ b/kedro/framework/cli/starters.py @@ -48,7 +48,7 @@ kedro new --tools=all\n kedro new --tools=none -For more information on using tools, see https://docs.kedro.org/en/latest/starters/new_project_tools.html +For more information on using tools, see https://docs.kedro.org/en/stable/starters/new_project_tools.html """ CONFIG_ARG_HELP = """Non-interactive mode, using a configuration yaml file. This file must supply the keys required by the template's prompts.yml. When not using a starter, @@ -875,7 +875,7 @@ def _create_project(template_path: str, cookiecutter_args: dict[str, Any]): template_path: The path to the cookiecutter template to create the project. It could either be a local directory or a remote VCS repository supported by cookiecutter. For more details, please see: - https://cookiecutter.readthedocs.io/en/latest/usage.html#generate-your-project + https://cookiecutter.readthedocs.io/en/stable/usage.html#generate-your-project cookiecutter_args: Arguments to pass to cookiecutter. Raises: diff --git a/kedro/framework/project/__init__.py b/kedro/framework/project/__init__.py index 85eafc37c9..8f507df5e4 100644 --- a/kedro/framework/project/__init__.py +++ b/kedro/framework/project/__init__.py @@ -327,7 +327,7 @@ def find_pipelines() -> dict[str, Pipeline]: # noqa: PLR0912 can modify the mapping generated by the ``find_pipelines`` function. For more information on the pipeline registry and autodiscovery, see - https://kedro.readthedocs.io/en/latest/nodes_and_pipelines/pipeline_registry.html + https://kedro.readthedocs.io/en/stable/nodes_and_pipelines/pipeline_registry.html Returns: A generated mapping from pipeline names to ``Pipeline`` objects. From b2d92f58bab8f87b549aea7b36a8d9773555e703 Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Wed, 10 Jan 2024 16:23:39 +0000 Subject: [PATCH 11/13] Avoid merge conflict with 3490 Signed-off-by: Ahdra Merali --- kedro/framework/cli/starters.py | 10 +++++----- tests/framework/cli/test_starters.py | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/kedro/framework/cli/starters.py b/kedro/framework/cli/starters.py index e97b89a5d4..1b71427751 100644 --- a/kedro/framework/cli/starters.py +++ b/kedro/framework/cli/starters.py @@ -131,7 +131,7 @@ class KedroStarterSpec: # noqa: too-few-public-methods } -def _validate_flag_inputs(flag_inputs): +def _validate_flag_inputs(flag_inputs: dict[str, Any]): if flag_inputs.get("checkout") and not flag_inputs.get("starter"): raise KedroCliError("Cannot use the --checkout flag without a --starter value.") @@ -205,7 +205,7 @@ def _validate_selected_tools(selected_tools): sys.exit(1) -def _print_tools_selection(selected_tools): +def _print_tools_selection(selected_tools: str | None): if selected_tools is not None: if selected_tools == "['None']": click.secho( @@ -219,7 +219,7 @@ def _print_tools_selection(selected_tools): ) -def _print_example_selection(example_pipeline): +def _print_example_selection(example_pipeline: bool | None): if example_pipeline is not None: if example_pipeline: click.secho( @@ -321,7 +321,7 @@ def new( # noqa: PLR0913 extra_context = _get_extra_context( prompts_required=prompts_required, config_path=config_path, - cookiecutter_context=cookiecutter_context, + cookiecutter_context=cookiecutter_context, # type: ignore selected_tools=selected_tools, project_name=project_name, example_pipeline=example_pipeline, @@ -343,7 +343,7 @@ def new( # noqa: PLR0913 # When not a starter, print tools and example selection _print_tools_selection(extra_context.get("tools")) - _print_example_selection(extra_context.get("example_pipeline")) + _print_example_selection(extra_context.get("example_pipeline")) # type: ignore # If interactive flow used, print hint if prompts_required and not config_path: diff --git a/tests/framework/cli/test_starters.py b/tests/framework/cli/test_starters.py index 75de605a3d..add8976333 100644 --- a/tests/framework/cli/test_starters.py +++ b/tests/framework/cli/test_starters.py @@ -220,6 +220,8 @@ def _assert_template_ok( if "y" in example_pipeline.lower(): assert "It has been created with an example pipeline." in result.output + else: + assert "It has been created with an example pipeline." not in result.output generated_files = [ p for p in full_path.rglob("*") if p.is_file() and p.name != ".DS_Store" From 3c72ba5e8201eea163627f37b345247b2477d9ca Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Thu, 11 Jan 2024 15:03:24 +0000 Subject: [PATCH 12/13] Add return type hints Signed-off-by: Ahdra Merali --- kedro/framework/cli/starters.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kedro/framework/cli/starters.py b/kedro/framework/cli/starters.py index 3f44d72b37..7b3e293078 100644 --- a/kedro/framework/cli/starters.py +++ b/kedro/framework/cli/starters.py @@ -131,7 +131,7 @@ class KedroStarterSpec: # noqa: too-few-public-methods } -def _validate_flag_inputs(flag_inputs: dict[str, Any]): +def _validate_flag_inputs(flag_inputs: dict[str, Any]) -> None: if flag_inputs.get("checkout") and not flag_inputs.get("starter"): raise KedroCliError("Cannot use the --checkout flag without a --starter value.") @@ -205,7 +205,7 @@ def _validate_selected_tools(selected_tools): sys.exit(1) -def _print_tools_selection(selected_tools: str | None): +def _print_tools_selection(selected_tools: str | None) -> None: if selected_tools is not None: if selected_tools == "['None']": click.secho( @@ -219,7 +219,7 @@ def _print_tools_selection(selected_tools: str | None): ) -def _print_example_selection(example_pipeline: bool | None): +def _print_example_selection(example_pipeline: bool | None) -> None: if example_pipeline is not None: if example_pipeline: click.secho( From 12ba18cd82766ccc36cf0fecbe69ff081549ef0d Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Thu, 11 Jan 2024 15:13:48 +0000 Subject: [PATCH 13/13] Apply suggestions from code review - consolidate printing Signed-off-by: Ahdra Merali --- kedro/framework/cli/starters.py | 40 ++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/kedro/framework/cli/starters.py b/kedro/framework/cli/starters.py index 7b3e293078..7fbe4f5ad6 100644 --- a/kedro/framework/cli/starters.py +++ b/kedro/framework/cli/starters.py @@ -205,7 +205,10 @@ def _validate_selected_tools(selected_tools): sys.exit(1) -def _print_tools_selection(selected_tools: str | None) -> None: +def _print_selection_and_prompt_info( + selected_tools: str | None, example_pipeline: bool | None, interactive: bool +) -> None: + # Confirm tools selection if selected_tools is not None: if selected_tools == "['None']": click.secho( @@ -218,8 +221,7 @@ def _print_tools_selection(selected_tools: str | None) -> None: fg="green", ) - -def _print_example_selection(example_pipeline: bool | None) -> None: + # Confirm example selection if example_pipeline is not None: if example_pipeline: click.secho( @@ -227,6 +229,14 @@ def _print_example_selection(example_pipeline: bool | None) -> None: fg="green", ) + # Give hint for skipping interactive flow + if interactive: + click.secho( + "\nTo skip the interactive flow you can run `kedro new` with" + "\nkedro new --name= --tools= --example=", + fg="green", + ) + # noqa: missing-function-docstring @click.group(context_settings=CONTEXT_SETTINGS, name="Kedro") @@ -337,21 +347,15 @@ def new( # noqa: PLR0913 _create_project(project_template, cookiecutter_args) - # End here if a starter was used - if starter_alias: - return - - # When not a starter, print tools and example selection - _print_tools_selection(extra_context.get("tools")) - _print_example_selection(extra_context.get("example_pipeline")) # type: ignore - - # If interactive flow used, print hint - if prompts_required and not config_path: - click.secho( - "\nTo skip the interactive flow you can run `kedro new` with" - "\nkedro new --name= --tools= --example=", - fg="green", - ) + # If not a starter, print tools and example selection + if not starter_alias: + # If interactive flow used, print hint + interactive_flow = prompts_required and not config_path + _print_selection_and_prompt_info( + extra_context.get("tools"), + extra_context.get("example_pipeline"), + interactive_flow, + ) # type: ignore @starter.command("list")