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

Extend tools selection syntax #3394

Merged
merged 7 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 10 additions & 2 deletions kedro/framework/cli/starters.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,11 +758,19 @@ def _validate_config_file_inputs(config: dict[str, str]):

input_tools = config.get("tools", "none")
tools_validation_config = {
"regex_validator": r"^(all|none|(( )*\d*(,\d*)*(,( )*\d*)*( )*|( )*((\d+-\d+)|(\d+ - \d+))( )*))$",
"regex_validator": r"""^(
all|none| # A: "all" or "none" or
(\ *\d+ # B: any number of spaces followed by one or more digits
(\ *-\ *\d+)? # C: zero or one instances of: a hyphen followed by one or more digits, spaces allowed
(\ *,\ *\d+(\ *-\ *\d+)?)* # D: any number of instances of: a comma followed by B and C, spaces allowed
\ *)?) # E: zero or one instances of (B,C,D) as empty strings are also permissible
$""",
"error_message": f"'{input_tools}' is an invalid value for project tools. Please select valid options for tools using comma-separated values, ranges, or 'all/none'.",
}

if not re.match(tools_validation_config["regex_validator"], input_tools.lower()):
if not re.match(
tools_validation_config["regex_validator"], input_tools.lower(), flags=re.X
):
message = tools_validation_config["error_message"]
click.secho(message, fg="red", err=True)
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion kedro/templates/project/prompts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tools:
7) Kedro-Viz: Kedro's native visualisation tool

Which tools would you like to include in your project? [1-7/1,3/all/none]:
regex_validator: "^(all|none|(( )*\\d*(,\\d*)*(,( )*\\d*)*( )*|( )*((\\d+-\\d+)|(\\d+ - \\d+))( )*))$"
regex_validator: "^(all|none|(( )*\\d+( *- *\\d+)?( *, *\\d+( *- *\\d+)?)*( )*)?)$"
error_message: |
Invalid input. Please select valid options for project tools using comma-separated values, ranges, or 'all/none'.

Expand Down
16 changes: 14 additions & 2 deletions tests/framework/cli/test_starters.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,8 +967,14 @@ class TestToolsAndExampleFromUserPrompts:
"6",
"7",
"none",
"",
"2,3,4",
"3-5",
"1,2,4-6",
"1,2,4-6,7",
"4-6,7",
"1, 2 ,4 - 6, 7",
"1-3, 5-7",
"all",
"1, 2, 3",
" 1, 2, 3 ",
Expand All @@ -991,7 +997,7 @@ def test_valid_tools_and_example(self, fake_kedro_cli, tools, example_pipeline):

@pytest.mark.parametrize(
"bad_input",
["bad input", "-1", "3-"],
["bad input", "-1", "3-", "1 1"],
)
def test_invalid_tools(self, fake_kedro_cli, bad_input):
result = CliRunner().invoke(
Expand Down Expand Up @@ -1079,8 +1085,14 @@ class TestToolsAndExampleFromConfigFile:
"6",
"7",
"none",
"",
"2,3,4",
"3-5",
"1,2,4-6",
"1,2,4-6,7",
"4-6,7",
"1, 2 ,4 - 6, 7",
"1-3,5-7",
"all",
"1, 2, 3",
" 1, 2, 3 ",
Expand Down Expand Up @@ -1108,7 +1120,7 @@ def test_valid_tools_and_example(self, fake_kedro_cli, tools, example_pipeline):

@pytest.mark.parametrize(
"bad_input",
["bad input", "-1", "3-"],
["bad input", "-1", "3-", "1 1"],
)
def test_invalid_tools(self, fake_kedro_cli, bad_input):
"""Test project created from config."""
Expand Down