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

Remove lowercase transformation in regex validation #4408

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 20 in RELEASE.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [Kedro.Spellings] Did you really mean 'Hendrik'? Raw Output: {"message": "[Kedro.Spellings] Did you really mean 'Hendrik'?", "location": {"path": "RELEASE.md", "range": {"start": {"line": 20, "column": 4}}}, "severity": "WARNING"}

Check warning on line 20 in RELEASE.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [Kedro.Spellings] Did you really mean 'Scherner'? Raw Output: {"message": "[Kedro.Spellings] Did you really mean 'Scherner'?", "location": {"path": "RELEASE.md", "range": {"start": {"line": 20, "column": 12}}}, "severity": "WARNING"}

# 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
Loading