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

Fix --tools=all not working properly #3361

Merged
merged 29 commits into from
Dec 8, 2023
Merged

Conversation

SajidAlamQB
Copy link
Contributor

@SajidAlamQB SajidAlamQB commented Nov 29, 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

Related to: #3334

When you use --tools=all or --tools all in kedro new directly you don't get all addons as expected.
You can also see in the message:

You have selected the following tools:

Development notes

The problem looks to be coming from _convert_tool_names_to_numbers.

def _convert_addon_names_to_numbers(selected_add_ons_flag: str | None) -> str | None:
"""Prepares add-on selection from the CLI input to the correct format
to be put in the project configuration, if it exists.
Replaces add-on strings with the corresponding prompt number.
Args:
selected_add_ons_flag: a string containing the value for the --addons flag,
or None in case the flag wasn't used, i.e. lint,docs.
Returns:
String with the numbers corresponding to the desired add_ons, or
None in case the --addons flag was not used.
"""
if selected_add_ons_flag is None:
return None
addons = []
for addon in selected_add_ons_flag.lower().split(","):
addon_short_name = addon.strip()
if addon_short_name in ADD_ONS_SHORTNAME_TO_NUMBER:
addons.append(ADD_ONS_SHORTNAME_TO_NUMBER[addon_short_name])
return ",".join(addons)

We don't have a check for the "all" flag. We should probably also have "none" check here as well.

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

@SajidAlamQB SajidAlamQB self-assigned this Nov 29, 2023
@SajidAlamQB SajidAlamQB linked an issue Nov 29, 2023 that may be closed by this pull request
SajidAlamQB and others added 3 commits November 30, 2023 00:59
Signed-off-by: lrcouto <laurarccouto@gmail.com>
Signed-off-by: Ahdra Merali <ahdra.merali@quantumblack.com>
Signed-off-by: lrcouto <laurarccouto@gmail.com>
Signed-off-by: Ahdra Merali <ahdra.merali@quantumblack.com>
Signed-off-by: lrcouto <laurarccouto@gmail.com>
@lrcouto lrcouto marked this pull request as ready for review November 30, 2023 04:54
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.

Do we have any tests that should have caught this?

@SajidAlamQB SajidAlamQB changed the title Fix --addons=all not working properly Fix --tools=all not working properly Nov 30, 2023
@deepyaman
Copy link
Member

Do we have any tests that should have caught this?

+1 was going to say the same thing, then saw @merelcht already did :D

@SajidAlamQB
Copy link
Contributor Author

Do we have any tests that should have caught this?

Yes, I believe we have the tests already, @lrcouto, found that this problem wasn't originally picked up by the tests as it was using the faulty function which shouldn't be a problem now that it's fixed. Right @lrcouto?

if selected_tools.lower() == "none":
return ""
if selected_tools.lower() == "all":
return ",".join(TOOLS_SHORTNAME_TO_NUMBER.values())
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we just need to update the TOOLS_SHORTNAME_TO_NUMBER dictionary? Put "none" and "all" there? Or it will break something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking this as well but it feels a bit weird as "all" and "none" aren't tools.

@AhdraMeraliQB
Copy link
Contributor

Do we have any tests that should have caught this?

Yes, I believe we have the tests already, @lrcouto, found that this problem wasn't originally picked up by the tests as it was using the faulty function which shouldn't be a problem now that it's fixed. Right @lrcouto?

😬 The unchecked point of failure is a little concerning

I noticed in test_starters.py we only really test the helper function _parse_tools_input. I think we can mitigate something like this again by testing the others as well - would it be in scope to add some quick unit tests for _parse_yes_no_to_bool and _validate_selection, as well as _convert_tools_names_to_numbers?

@SajidAlamQB
Copy link
Contributor Author

I noticed in test_starters.py we only really test the helper function _parse_tools_input. I think we can mitigate something like this again by testing the others as well - would it be in scope to add some quick unit tests for _parse_yes_no_to_bool and _validate_selection, as well as _convert_tools_names_to_numbers?

Sounds good to me 👍

Copy link
Contributor

@DimedS DimedS left a comment

Choose a reason for hiding this comment

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

Thanks, @lrcouto and @SajidAlamQB , great work!

Copy link
Contributor

@AhdraMeraliQB AhdraMeraliQB left a comment

Choose a reason for hiding this comment

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

Love the new tests, just a few comments:

@@ -1324,3 +1324,92 @@ def test_invalid_names(self, fake_kedro_cli, name):
"Kedro project names must contain only alphanumeric symbols, spaces, underscores and hyphens and be at least 2 characters long"
in result.output
)


class TestParseYesNoToBools:
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we move the tests for parse_tools_input into their own class as well? For consistency

def test_validate_selection_invalid_single_tool(self):
tools = ["8"]
with pytest.raises(SystemExit):
_validate_selection(tools)
Copy link
Contributor

@AhdraMeraliQB AhdraMeraliQB Dec 5, 2023

Choose a reason for hiding this comment

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

Could we add an assert for the correct error message? E.g the implementation for test_parse_tools_invalid_selection

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.

LGTM! 👍

@SajidAlamQB SajidAlamQB enabled auto-merge (squash) December 8, 2023 13:26
@SajidAlamQB SajidAlamQB enabled auto-merge (squash) December 8, 2023 13:57
@SajidAlamQB SajidAlamQB merged commit 074d5e1 into develop Dec 8, 2023
30 checks passed
@SajidAlamQB SajidAlamQB deleted the bugfix/addons=all-fix branch December 8, 2023 14:09
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.

--addons=all doesn't behave as expected
6 participants