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 kedro commands work from inside subdirectories in project #3683

Merged
merged 9 commits into from
Mar 7, 2024

Conversation

ankatiyar
Copy link
Contributor

@ankatiyar ankatiyar commented Mar 5, 2024

Description

Fix #1831

Development notes

  • Move _find_kedro_project() and _is_project() to kedro.utils so it can be used both by KedroCLI and kedro.ipython extension
  • Update _find_kedro_project() to use Path.parents
  • Update project_path for KedroCLI and KedroSession to use _find_kedro_project()
  • Added e2e test for this change

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

ankatiyar and others added 2 commits March 5, 2024 13:34
@ankatiyar ankatiyar linked an issue Mar 5, 2024 that may be closed by this pull request
Signed-off-by: Ankita Katiyar <ankitakatiyar2401@gmail.com>
Signed-off-by: Ankita Katiyar <ankitakatiyar2401@gmail.com>
Signed-off-by: Ankita Katiyar <ankitakatiyar2401@gmail.com>
Signed-off-by: Ankita Katiyar <ankitakatiyar2401@gmail.com>
@ankatiyar ankatiyar changed the title [Draft] Make kedro commands work from inside subdirectories in project Make kedro commands work from inside subdirectories in project Mar 5, 2024
Signed-off-by: Ankita Katiyar <ankitakatiyar2401@gmail.com>
@ankatiyar ankatiyar marked this pull request as ready for review March 6, 2024 10:07
@ankatiyar ankatiyar requested a review from merelcht as a code owner March 6, 2024 10:07
@ankatiyar ankatiyar requested a review from noklam March 6, 2024 10:07
@datajoely
Copy link
Contributor

Super good push!

Possibly a different ticket - but it would be nice to catch some of the common within project commands (which 90% of the time will be run) and say something useful like "You are not within a Kedro project directory, please navigate there to use {command}" rather than the pretty confusing error users get today...

❯ kedro run
Usage: kedro [OPTIONS] COMMAND [ARGS]...
Try 'kedro -h' for help.

Error: No such command 'run'.

@noklam
Copy link
Contributor

noklam commented Mar 6, 2024

@datajoely #3680

Copy link
Contributor

@noklam noklam left a comment

Choose a reason for hiding this comment

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

I did a manual test with arbitary deep directory with kedro run,kedro ipython, all works well. This is such a small change but big improvement in the developer experience.

It checks all the parents, which I think it's good. Alternatively we are try to traverse the directory up, we run into risks that we execute other kedro project accidentally.

image

Out of scope:

@rashidakanchwala I test viz command and it's failing.
image

@noklam noklam self-requested a review March 6, 2024 15:51
@noklam
Copy link
Contributor

noklam commented Mar 6, 2024

Since this breaks kedro-viz, I also send a question in Slack. In some sense we may consider this as a breaking change, mainly to plugin developer. Though I don't think this should stop us from releasing this in 0.19, but just in case we should check with some plugin developers particularly if they rely on the fact that command are running from project root.

@ravi-kumar-pilla
Copy link
Contributor

Since this breaks kedro-viz, I also send a question in Slack. In some sense we may consider this as a breaking change, mainly to plugin developer. Though I don't think this should stop us from releasing this in 0.19, but just in case we should check with some plugin developers particularly if they rely on the fact that command are running from project root.

Hi Nok, Currently the commands kedro viz run and kedro viz build default to current working directory as Kedro project path. We are introducing an option for --project-path in kedro viz run here. We can also plan on extending this to other cli commands. Thank you

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.

The implementation looks all good and I've tested it successfully as well 👍 I agree with @noklam that even though it can be considered breaking, it should be shipped in the 0.19.x series.

On the viz issue we could either change the logic there, or at the least make the error message clearer when running Viz in a subdirectory.

@@ -104,7 +105,9 @@ def __init__( # noqa: PLR0913
save_on_close: bool = False,
conf_source: str | None = None,
):
self._project_path = Path(project_path or Path.cwd()).resolve()
self._project_path = Path(
project_path or _find_kedro_project(Path.cwd()).resolve() or Path.cwd()
Copy link
Member

Choose a reason for hiding this comment

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

Previously we called .resolve() on all options project_path as well as Path.cwd() and now only on _find_kedro_project(Path.cwd()).resolve(), why did that change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated!

@@ -1,6 +1,7 @@
# Upcoming Release 0.19.4

## Major features and improvements
* Kedro commands now work from any subdirectory within a Kedro project.
Copy link
Member

Choose a reason for hiding this comment

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

_is_project and _find_kedro_project are private methods, but it might be worth mentioning in the release notes section "Breaking changes to the API" that these were moved to kedro.utils, just in case people are using them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated!

ankatiyar and others added 2 commits March 7, 2024 10:28
Signed-off-by: Ankita Katiyar <ankitakatiyar2401@gmail.com>
Signed-off-by: Ankita Katiyar <110245118+ankatiyar@users.noreply.github.com>
@ankatiyar ankatiyar requested a review from merelcht March 7, 2024 10:29
Copy link
Contributor

@noklam noklam left a comment

Choose a reason for hiding this comment

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

Nice change! It makes working with Kedro in terminal so much smoother.

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! 😄

@ankatiyar ankatiyar merged commit a22bc32 into main Mar 7, 2024
34 checks passed
@ankatiyar ankatiyar deleted the kedro-commands-in-subdirectories branch March 7, 2024 15:58
@astrojuanlu
Copy link
Member

Wow, this was so fast I didn't even have time to review it. Well done everyone ❤️

@noklam
Copy link
Contributor

noklam commented Mar 8, 2024

run-kedro-anywhere

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.

Make kedro project commands work from any directory inside a project
6 participants