Skip to content

Commit

Permalink
Remove lowercase transformation in regex validation (#4408)
Browse files Browse the repository at this point in the history
* Remove explicit transformation to lowercase prior validation

Signed-off-by: Hendrik Scherner <[email protected]>

* Update upcoming realease notes

Signed-off-by: Hendrik Scherner <[email protected]>

* End release note with dot

---------

Signed-off-by: Hendrik Scherner <[email protected]>
Co-authored-by: Merel Theisen <[email protected]>
  • Loading branch information
SchernHe and merelcht authored Jan 15, 2025
1 parent 1536a2a commit 9610e78
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions kedro/framework/cli/starters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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+)?)*( )*)?)$"
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'.
Expand Down
15 changes: 12 additions & 3 deletions tests/framework/cli/test_starters.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,19 +422,27 @@ 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",
{
"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"],
Expand All @@ -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):
Expand Down

0 comments on commit 9610e78

Please sign in to comment.