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

Make project creation flow parse add-ons consistently #3265

Merged
merged 15 commits into from
Nov 3, 2023

Conversation

noklam
Copy link
Contributor

@noklam noklam commented Nov 3, 2023

NOTE: Kedro datasets are moving from kedro.extras.datasets to a separate kedro-datasets package in
kedro-plugins repository. Any changes to the dataset implementations
should be done by opening a pull request in that repository.

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 @merelcht

  • Rename config -> extra_context to reflect what it does
  • Refactor the 3 way conversion between lint -> 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

  • Read the contributing guidelines
  • Signed off each commit with a Developer Certificate of Origin (DCO)
  • Opened this PR as a 'Draft Pull Request' if it is work-in-progress
  • Updated the documentation to reflect the code changes
  • Added a description of this change in the RELEASE.md file
  • Added tests to cover my changes
  • Checked if this change will affect Kedro-Viz, and if so, communicated that with the Viz team

Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
…dictionary

Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
@noklam noklam changed the base branch from main to develop November 3, 2023 03:49
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
This reverts commit bf9e639.

Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
@noklam noklam changed the title Fix inconsistent logic handling cookiecutter argus Fix inconsistent logic handling cookiecutter args Nov 3, 2023
@@ -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(
Copy link
Contributor Author

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):
Copy link
Contributor Author

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):
Copy link
Contributor Author

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 <nok.lam.chan@quantumblack.com>
@noklam noklam marked this pull request as ready for review November 3, 2023 04:22
@noklam noklam requested a review from merelcht as a code owner November 3, 2023 04:22
@noklam noklam requested review from DimedS and lrcouto November 3, 2023 04:22
@noklam noklam changed the title Fix inconsistent logic handling cookiecutter args A few improvement to make project creation flow parse addon consistently Nov 3, 2023
Copy link
Member

@merelcht merelcht left a 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 😃

@deepyaman deepyaman changed the title A few improvement to make project creation flow parse addon consistently Make project creation flow parse add-ons consistently Nov 3, 2023
Copy link
Member

@deepyaman deepyaman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestions

Comment on lines 135 to 139
ADD_ONS_SHORTNAME_TO_NAME = {
short_name: NUMBER_TO_ADD_ONS_NAME[num]
for short_name, num in ADD_ONS_SHORTNAME_TO_NUMBER.items()
}

Copy link
Member

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.

Suggested change
ADD_ONS_SHORTNAME_TO_NAME = {
short_name: NUMBER_TO_ADD_ONS_NAME[num]
for short_name, num in ADD_ONS_SHORTNAME_TO_NUMBER.items()
}

Copy link
Contributor Author

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.

Comment on lines +119 to +127
ADD_ONS_SHORTNAME_TO_NUMBER = {
"lint": "1",
"test": "2",
"log": "3",
"docs": "4",
"data": "5",
"pyspark": "6",
}
NUMBER_TO_ADD_ONS_NAME = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit :)

Suggested change
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 = {

@@ -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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good found!

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""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

Copy link
Member

@deepyaman deepyaman left a 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 :)

Copy link
Contributor

@lrcouto lrcouto left a 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!

Copy link
Contributor

@SajidAlamQB SajidAlamQB left a 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 <nok.lam.chan@quantumblack.com>
@noklam noklam enabled auto-merge (squash) November 3, 2023 16:31
@noklam noklam merged commit 2ed06f5 into develop Nov 3, 2023
46 of 52 checks passed
@noklam noklam deleted the fix/inconsistent_add_ons branch November 3, 2023 16:59
@noklam noklam mentioned this pull request Nov 6, 2023
7 tasks
@noklam noklam self-assigned this Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants