From 9610e7850b2462593a2377afe4835e253043607b Mon Sep 17 00:00:00 2001 From: Hendrik Date: Wed, 15 Jan 2025 10:15:47 +0100 Subject: [PATCH] Remove lowercase transformation in regex validation (#4408) * Remove explicit transformation to lowercase prior validation Signed-off-by: Hendrik Scherner * Update upcoming realease notes Signed-off-by: Hendrik Scherner * End release note with dot --------- Signed-off-by: Hendrik Scherner Co-authored-by: Merel Theisen <49397448+merelcht@users.noreply.github.com> --- RELEASE.md | 3 +++ kedro/framework/cli/starters.py | 3 +-- kedro/templates/project/prompts.yml | 2 +- tests/framework/cli/test_starters.py | 15 ++++++++++++--- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index f141c29aef..49fb42d94c 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -12,10 +12,13 @@ * 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. ## Breaking changes to the API ## Documentation changes + ## Community contributions +* [Hendrik Scherner](https://github.com/SchernHe) # Release 0.19.10 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):