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

Use click features for project creation prompts #4387

Merged
merged 33 commits into from
Jan 27, 2025
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9bb3361
Test prompt change
lrcouto Dec 17, 2024
10dbea5
Test adding default value
lrcouto Dec 17, 2024
9b4a9a7
Change other prompts
lrcouto Dec 17, 2024
73180ca
Move prompting logic to the inside of new function
lrcouto Dec 18, 2024
48934d5
fix name default
lrcouto Dec 18, 2024
3f184a8
Merge branch 'main' into click-validation-options
lrcouto Jan 13, 2025
75456b7
Merge branch 'main' into click-validation-options
lrcouto Jan 13, 2025
601b02f
Add auxiliary function for converting numbers to tools
lrcouto Jan 13, 2025
8305cae
Merge branch 'main' into click-validation-options
lrcouto Jan 14, 2025
05b7479
Merge branch 'main' into click-validation-options
lrcouto Jan 14, 2025
7b71418
Normalize whitespaces in test outputs
lrcouto Jan 14, 2025
d0af3d3
Merge branch 'main' into click-validation-options
lrcouto Jan 15, 2025
7aade5b
Merge branch 'main' into click-validation-options
lrcouto Jan 15, 2025
0ce0219
Prevent prompts from happening when a config file is used
lrcouto Jan 15, 2025
6d37aed
move click prompting to replace cookiecutter's
lrcouto Jan 16, 2025
893415d
Remove reduntant variables
lrcouto Jan 16, 2025
f8cc6c3
Fix more tests
lrcouto Jan 16, 2025
c1e96df
All unit tests passing
lrcouto Jan 16, 2025
eae9d5a
Merge branch 'main' into click-validation-options
lrcouto Jan 16, 2025
1d7af53
Revert unnecessary changes on tests
lrcouto Jan 16, 2025
0ac3d2b
remove reduntant leftover code
lrcouto Jan 16, 2025
d8a6b6f
remove reduntant leftover code
lrcouto Jan 16, 2025
f9534ee
Set up prompt appearance
lrcouto Jan 17, 2025
f777d09
Revert default to unformatted
lrcouto Jan 18, 2025
da38e1a
Merge branch 'main' into click-validation-options
lrcouto Jan 21, 2025
6cc3e15
Switch yes/no CLI prompts to click validation
lrcouto Jan 21, 2025
e71e015
Lint
lrcouto Jan 21, 2025
5828415
Use click.Choice for telemetry, rest as our own function
lrcouto Jan 21, 2025
0923ca4
Merge branch 'main' into click-validation-options
lrcouto Jan 22, 2025
8eec43b
Change example validation back to what it was initially
lrcouto Jan 22, 2025
20e5fe7
Merge branch 'main' into click-validation-options
lrcouto Jan 22, 2025
d821596
Revert verification to _Prompt.validate
lrcouto Jan 27, 2025
c4aec14
Merge branch 'click-validation-options' of github.com:kedro-org/kedro…
lrcouto Jan 27, 2025
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
Prev Previous commit
Next Next commit
Lint
Signed-off-by: Laura Couto <laurarccouto@gmail.com>
lrcouto committed Jan 21, 2025
commit e71e015a3737cab0cf99cd4951dda49e9c1d6174
26 changes: 20 additions & 6 deletions kedro/framework/cli/starters.py
Original file line number Diff line number Diff line change
@@ -196,11 +196,13 @@ def _validate_flag_inputs(flag_inputs: dict[str, Any]) -> None:
)


def _validate_yes_no(ctx, param, value) -> None:
def _validate_yes_no(ctx: Any, param: Any, value: Any) -> Any | None:
if value is None:
return None
if not re.match(r"(?i)^\s*(y|yes|n|no)\s*$", value, flags=re.X):
raise click.BadParameter(f"'{value}' is an invalid value for {param}. It must contain only y, n, YES, or NO (case insensitive).")
raise click.BadParameter(
f"'{value}' is an invalid value for {param}. It must contain only y, n, YES, or NO (case insensitive)."
)
return value


@@ -332,8 +334,20 @@ def starter() -> None:
"selected_tools",
help=TOOLS_ARG_HELP,
)
@click.option("--example", "-e", "example_pipeline", help=EXAMPLE_ARG_HELP, callback=_validate_yes_no)
@click.option("--telemetry", "-tc", "telemetry_consent", help=TELEMETRY_ARG_HELP, callback=_validate_yes_no)
@click.option(
"--example",
"-e",
"example_pipeline",
help=EXAMPLE_ARG_HELP,
callback=_validate_yes_no,
)
@click.option(
"--telemetry",
"-tc",
"telemetry_consent",
help=TELEMETRY_ARG_HELP,
callback=_validate_yes_no,
)
def new( # noqa: PLR0913
config_path: str,
starter_alias: str,
@@ -1030,11 +1044,11 @@ def __str__(self) -> str:
return f"\n{prompt_text}\n"

@property
def user_input(self):
def user_input(self) -> str:
return self._user_input

@user_input.setter
def user_input(self, input):
def user_input(self, input: str) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's clear enough now that this is doing validation 🤔 I have a slight preference to keeping the validate() method as before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, the other way is more explicit.

"""Validate and set the user input."""
if self.regexp and not re.match(self.regexp, input):
message = f"'{input}' is an invalid value for {(self.title).lower()}."
5 changes: 1 addition & 4 deletions tests/framework/cli/test_starters.py
Original file line number Diff line number Diff line change
@@ -1678,10 +1678,7 @@ def test_flag_value_is_invalid(self, fake_kedro_cli):
repo_name = "new-kedro-project"
assert result.exit_code == 2

assert (
"'wrong' is an invalid value"
in result.output
)
assert "'wrong' is an invalid value" in result.output
assert (
" It must contain only y, n, YES, or NO (case insensitive)."
in result.output