Skip to content
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

Check if starter is used before printing tools message #3484

Merged
merged 20 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 41 additions & 24 deletions kedro/framework/cli/starters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
AhdraMeraliQB marked this conversation as resolved.
Show resolved Hide resolved
"""
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,
Expand Down Expand Up @@ -187,6 +188,29 @@ def _validate_selected_tools(selected_tools):
sys.exit(1)


def _print_tools_selection(selected_tools):
AhdraMeraliQB marked this conversation as resolved.
Show resolved Hide resolved
if selected_tools is not None:
if selected_tools == "['None']":
click.secho(
"You have selected no project tools",
fg="green",
)
else:
click.secho(
f"You have selected the following project tools: {selected_tools}",
fg="green",
)


def _print_example_selection(example_pipeline):
AhdraMeraliQB marked this conversation as resolved.
Show resolved Hide resolved
if example_pipeline is not None:
if example_pipeline:
click.secho(
"It has been created with an example pipeline.",
fg="green",
)


# noqa: missing-function-docstring
@click.group(context_settings=CONTEXT_SETTINGS, name="Kedro")
def create_cli(): # pragma: no cover
Expand Down Expand Up @@ -299,7 +323,17 @@ 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:
AhdraMeraliQB marked this conversation as resolved.
Show resolved Hide resolved
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"))
AhdraMeraliQB marked this conversation as resolved.
Show resolved Hide resolved

# 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=<your-project-name> --tools=<your-project-tools> --example=<yes/no>",
Expand Down Expand Up @@ -485,6 +519,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.
Expand Down Expand Up @@ -843,34 +881,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"
)

# we can use starters without tools:
if tools is not None:
if tools == "['None']": # TODO: This should be a list
AhdraMeraliQB marked this conversation as resolved.
Show resolved Hide resolved
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:
"""Represent a single CLI prompt for `kedro new`"""
Expand Down
1 change: 1 addition & 0 deletions tests/framework/cli/test_starters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=<your-project-name> --tools=<your-project-tools> --example=<yes/no>"
not in result.output
)
assert "You have selected" not in result.output
_assert_template_ok(result)
_clean_up_project(Path("./new-kedro-project"))

Expand Down