-
Notifications
You must be signed in to change notification settings - Fork 914
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
Make project creation flow parse add-ons consistently #3265
Conversation
Signed-off-by: Nok Chan <[email protected]>
Signed-off-by: Nok Chan <[email protected]>
…dictionary Signed-off-by: Nok Chan <[email protected]>
Signed-off-by: Nok Chan <[email protected]>
Signed-off-by: Nok Chan <[email protected]>
Signed-off-by: Nok Chan <[email protected]>
This reverts commit bf9e639. Signed-off-by: Nok Chan <[email protected]>
Signed-off-by: Nok Chan <[email protected]>
Signed-off-by: Nok Chan <[email protected]>
Signed-off-by: Nok Chan <[email protected]>
Signed-off-by: Nok Chan <[email protected]>
Signed-off-by: Nok Chan <[email protected]>
Signed-off-by: Nok Chan <[email protected]>
@@ -322,15 +335,15 @@ def new( # noqa: too-many-arguments | |||
shutil.rmtree(tmpdir, onerror=_remove_readonly) | |||
|
|||
# Obtain config, either from a file or from interactive user prompts. | |||
config = _get_config( | |||
extra_context = _get_extra_context( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is passed as extra_context
to cookiecutter, so I think it's better just name it extra_context
.
@@ -488,7 +494,7 @@ def _select_prompts_to_display( | |||
del prompts_required["add_ons"] | |||
|
|||
if project_name is not None: | |||
if bool(re.match(r"^[\w -]{2,}$", project_name)) is False: | |||
if not re.match(r"^[\w -]{2,}$", project_name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the boolean expression is not needed. re.match
either return an object or None
@@ -68,25 +69,6 @@ def _make_cli_prompt_input_without_name( | |||
return "\n".join([add_ons, repo_name, python_package]) | |||
|
|||
|
|||
def _convert_addon_names_to_numbers(selected_addons: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function is actually more explicit than the _get_addons_from_cli_input
. It is only used in test originally, I've rename the original function and remove this from test.
Signed-off-by: Nok Chan <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @noklam ! These improvements make it a lot easier to follow the code, especially the changes you made to have ADD_ONS_SHORTNAME_TO_NUMBER
and NUMBER_TO_ADD_ONS_NAME
dicts 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor suggestions
kedro/framework/cli/starters.py
Outdated
ADD_ONS_SHORTNAME_TO_NAME = { | ||
short_name: NUMBER_TO_ADD_ONS_NAME[num] | ||
for short_name, num in ADD_ONS_SHORTNAME_TO_NUMBER.items() | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This seems unnecessary? You can just use list(ADD_ONS_SHORTNAME_TO_NUMBER)
below.
ADD_ONS_SHORTNAME_TO_NAME = { | |
short_name: NUMBER_TO_ADD_ONS_NAME[num] | |
for short_name, num in ADD_ONS_SHORTNAME_TO_NUMBER.items() | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah actually initially I was thinking I can skip the number and just convert from the short name to the longer one. It's a bit tricky and since there are other PR working on this I don't want to create too much merge conflict.
I took your suggestion and remove this extra dict for now, will revisit.
ADD_ONS_SHORTNAME_TO_NUMBER = { | ||
"lint": "1", | ||
"test": "2", | ||
"log": "3", | ||
"docs": "4", | ||
"data": "5", | ||
"pyspark": "6", | ||
} | ||
NUMBER_TO_ADD_ONS_NAME = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit :)
ADD_ONS_SHORTNAME_TO_NUMBER = { | |
"lint": "1", | |
"test": "2", | |
"log": "3", | |
"docs": "4", | |
"data": "5", | |
"pyspark": "6", | |
} | |
NUMBER_TO_ADD_ONS_NAME = { | |
ADD_ON_SHORTNAME_TO_NUMBER = { | |
"lint": "1", | |
"test": "2", | |
"log": "3", | |
"docs": "4", | |
"data": "5", | |
"pyspark": "6", | |
} | |
NUMBER_TO_ADD_ON_NAME = { |
kedro/framework/cli/starters.py
Outdated
@@ -213,13 +226,13 @@ def _validate_range(start, end): | |||
|
|||
def _validate_selection(add_ons: list[str]): | |||
for add_on in add_ons: | |||
if int(add_on) < 1 or int(add_on) > len(ADD_ONS_DICT): | |||
if int(add_on) < 1 or int(add_on) > len(NUMBER_TO_ADD_ONS_NAME): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if int(add_on) < 1 or int(add_on) > len(NUMBER_TO_ADD_ONS_NAME): | |
if add_on not in NUMBER_TO_ADD_ON_NAME: |
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good found!
kedro/framework/cli/starters.py
Outdated
prompts_required: dict, | ||
config_path: str, | ||
cookiecutter_context: OrderedDict, | ||
selected_addons: str, | ||
project_name: str, | ||
) -> dict[str, str]: | ||
"""Generates a config dictionary to be used to generate cookiecutter args, based | ||
"""Generates a config dictionary that will be passed to cookiecutters as `extra_context`, based |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Generates a config dictionary that will be passed to cookiecutters as `extra_context`, based | |
"""Generates a config dictionary that will be passed to cookiecutter as `extra_context`, based |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, let me approve with the change requests, so I don't end up blocking :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd implement Deepyaman's suggestions, but other than that it looks nice! It's easier to read now, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @noklam!
Signed-off-by: Nok Chan <[email protected]>
Description
Address Point 2 in #3264, I found some opportunities to improve the code.
Development notes
There are many conversion between
lint
->1
->Linting
, sometimes they are not used consistently. This PR mainly address this and fixed some other minor thing, I have commented with inline PR comments. Cc @lrcouto @merelchtconfig
->extra_context
to reflect what it doeslint
->1
->Linting
into constants.Developer Certificate of Origin
We need all contributions to comply with the Developer Certificate of Origin (DCO). All commits must be signed off by including a
Signed-off-by
line in the commit message. See our wiki for guidance.If your PR is blocked due to unsigned commits, then you must follow the instructions under "Rebase the branch" on the GitHub Checks page for your PR. This will retroactively add the sign-off to all unsigned commits and allow the DCO check to pass.
Checklist
RELEASE.md
file