From 910fa7166726446baa69863bd9418f97d643ba63 Mon Sep 17 00:00:00 2001 From: Hendrik Scherner Date: Thu, 9 Jan 2025 09:30:36 +0100 Subject: [PATCH 1/3] Remove explicit transformation to lowercase prior validation Signed-off-by: Hendrik Scherner --- kedro/framework/cli/starters.py | 3 +-- kedro/templates/project/prompts.yml | 2 +- tests/framework/cli/test_starters.py | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/kedro/framework/cli/starters.py b/kedro/framework/cli/starters.py index f7082311db..0d3b54c8ec 100644 --- a/kedro/framework/cli/starters.py +++ b/kedro/framework/cli/starters.py @@ -1005,8 +1005,7 @@ def __str__(self) -> str: def validate(self, user_input: str) -> None: """Validate a given prompt value against the regex validator""" - - if self.regexp and not re.match(self.regexp, user_input.lower()): + if self.regexp and not re.match(self.regexp, user_input): message = f"'{user_input}' is an invalid value for {(self.title).lower()}." click.secho(message, fg="red", err=True) click.secho(self.error_message, fg="red", err=True) diff --git a/kedro/templates/project/prompts.yml b/kedro/templates/project/prompts.yml index c6f8608b28..a4f7621464 100644 --- a/kedro/templates/project/prompts.yml +++ b/kedro/templates/project/prompts.yml @@ -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+)?)*( )*)?)$" + regex_validator: "(?i)^(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'. diff --git a/tests/framework/cli/test_starters.py b/tests/framework/cli/test_starters.py index 87c434dfd1..a1852c75af 100644 --- a/tests/framework/cli/test_starters.py +++ b/tests/framework/cli/test_starters.py @@ -422,7 +422,15 @@ def test_empty_prompts(self, fake_kedro_cli): _assert_template_ok(result) _clean_up_project(Path("./new-kedro-project")) - def test_custom_prompt_valid_input(self, fake_kedro_cli): + @pytest.mark.parametrize( + "regex, valid_value", + [ + ("^\\w+(-*\\w+)*$", "my-value"), + ("^[A-Z_]+", "MY-VALUE"), + ("^\\d+$", "123"), + ], + ) + def test_custom_prompt_valid_input(self, fake_kedro_cli, regex, valid_value): shutil.copytree(TEMPLATE_PATH, "template") _write_yaml( Path("template") / "prompts.yml", @@ -430,11 +438,11 @@ def test_custom_prompt_valid_input(self, fake_kedro_cli): "project_name": {"title": "Project Name"}, "custom_value": { "title": "Custom Value", - "regex_validator": "^\\w+(-*\\w+)*$", + "regex_validator": regex, }, }, ) - custom_input = "\n".join(["my-project", "My Project"]) + custom_input = "\n".join([valid_value, "My Project"]) result = CliRunner().invoke( fake_kedro_cli, ["new", "--starter", "template"], @@ -446,6 +454,7 @@ def test_custom_prompt_valid_input(self, fake_kedro_cli): repo_name="my-project", python_package="my_project", ) + _clean_up_project(Path("./my-project")) def test_custom_prompt_for_essential_variable(self, fake_kedro_cli): From 075e0d7d0a17ac8ebbce04cf786ecd7da1d4e7f5 Mon Sep 17 00:00:00 2001 From: Hendrik Scherner Date: Tue, 14 Jan 2025 08:47:07 +0100 Subject: [PATCH 2/3] Update upcoming realease notes Signed-off-by: Hendrik Scherner --- RELEASE.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/RELEASE.md b/RELEASE.md index f522b029b8..fd218cd65b 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -11,10 +11,13 @@ * Added `node` import to the pipeline template. * Update error message when executing kedro run without pipeline. * Safeguard hooks when user incorrectly registers a hook class in settings.py. +* Remove lowercase transformation in regex validation ## Breaking changes to the API ## Documentation changes + ## Community contributions +* [Hendrik Scherner](https://github.com/SchernHe) # Release 0.19.10 From 9f4066dc5fee0983eb577a58f7bfb2f638e8c0de Mon Sep 17 00:00:00 2001 From: Hendrik Scherner Date: Tue, 14 Jan 2025 15:35:00 +0100 Subject: [PATCH 3/3] End release note with dot --- RELEASE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASE.md b/RELEASE.md index 595c999cc8..49fb42d94c 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -12,7 +12,7 @@ * Update error message when executing kedro run without pipeline. * Safeguard hooks when user incorrectly registers a hook class in settings.py. * Fixed parsing paths with query and fragment. -* Remove lowercase transformation in regex validation +* Remove lowercase transformation in regex validation. ## Breaking changes to the API ## Documentation changes