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

Update documentation to show how to use KedroSession outside of CLI mode #1713

Merged
merged 15 commits into from
Jul 22, 2022

Conversation

noklam
Copy link
Contributor

@noklam noklam commented Jul 19, 2022

Signed-off-by: Nok Chan nok.lam.chan@quantumblack.com

Description

#1583 introduce a behavioral change that was introduced in 0.18.0, this PR updated the documentation to better reflect this.

Development notes

  • update the documentation to reflect when does a user need to do bootstrap_project

bonus:

  • a more helpful message when you are not running kedro in the right directory
  • removed the duplicate code in ipython extension

Checklist

  • Read the contributing guidelines
  • 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

Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
@noklam noklam requested a review from idanov as a code owner July 19, 2022 15:09
@noklam noklam marked this pull request as draft July 19, 2022 15:27
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
@@ -58,7 +58,6 @@ def reload_kedro(

_remove_cached_modules(metadata.package_name)

configure_project(metadata.package_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 bootstrap_project method already included the configure_project, so I don't think it is needed

Copy link
Contributor

Choose a reason for hiding this comment

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

I've been meaning to do this for ages. I didn't do it before because at a glance I wasn't 100% sure whether it was intentional to have both bootstrap_project and configure_project here. Note there's a call to _remote_cached_modules in between - does that mean that actually we need to repeat the call to configure_project?

I'm very much in favour of removing this if we can, but please do double check to see that all still works correctly after removing it! Possibly there's a good reason it's there.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds like you are confident we can remove this, so please go ahead as you were before 👍

@noklam
Copy link
Contributor Author

noklam commented Jul 19, 2022

Dev notes:

  • Intended to add some helpful message denoted that user is running outside of a kedro project - found that kedro-telemetry is initializing the KedroCLI again so it causes duplicate message.

https://github.com/kedro-org/kedro-plugins/blob/5813362d304babc3434f9d8e32e63478f8b95de7/kedro-telemetry/kedro_telemetry/plugin.py#L45

@noklam noklam removed the request for review from idanov July 19, 2022 16:46
noklam added 2 commits July 20, 2022 17:26
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
@noklam
Copy link
Contributor Author

noklam commented Jul 20, 2022

image

Mostly base on @datajoely's magic, I added some more so it will attempt to find the project. If it finds a kedro project then it will print the suggested path.

The last commit could be done at a separate commit, but I find this is kinda related anyway since it's dealing with things break in "out of project" mode.

@noklam noklam marked this pull request as ready for review July 20, 2022 16:31
noklam added 2 commits July 20, 2022 17:32
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
…into fix/docs_session_create

Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
@datajoely
Copy link
Contributor

Really nice work @noklam - would you mind providing some screenshots? I'll defer any points on implementation to the rest of the group, but would love to see the user journey here.

@noklam
Copy link
Contributor Author

noklam commented Jul 20, 2022

If users are in the project directory:
Business as usual, any kedro command should work

If users are not in the project directory:

  • 'kedro' - should a message suggesting this is running outside of a project? (Not sure so i didn't change it) - it's unclear whether user are aware of the project commands, there are no error but it will just show the global command.

  • 'kedro run' or any project command - it's pretty clear user are aware of these commands but just from wrong directory, so it will fail and show the screenshot above. If a project path is found, it will just show the path, if not it will revert to a simple help message suggesting user should look for the directory where the pyproject.toml

Typing this on my phone so sorry for badly formoatted.
@datajoely

What even better maybe it should just be a copyable message

cd is_this_your_project
kedro run

@datajoely
Copy link
Contributor

I didn't realise that was a new screenshot, I thought it was mine from ages ago. Nice work!

@@ -58,7 +58,6 @@ def reload_kedro(

_remove_cached_modules(metadata.package_name)

configure_project(metadata.package_name)
Copy link
Contributor

Choose a reason for hiding this comment

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

I've been meaning to do this for ages. I didn't do it before because at a glance I wasn't 100% sure whether it was intentional to have both bootstrap_project and configure_project here. Note there's a call to _remote_cached_modules in between - does that mean that actually we need to repeat the call to configure_project?

I'm very much in favour of removing this if we can, but please do double check to see that all still works correctly after removing it! Possibly there's a good reason it's there.

self._cli_hook_manager = get_cli_hook_manager()

super().__init__(
("Global commands", self.global_groups),
("Project specific commands", self.project_groups),
)

def get_command(self, ctx: Context, cmd_name: str) -> Optional[Command]:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a huge fan of this change in principle, thank you for adding it! However, please could you split it off into a separate PR? There's a few things I think need discussing:

  • not at all sure about using black for find_project_root. Note we have something similar _find_kedro_project in the ipython extension; if that seems suitable to reuse, let's move it to some common utils file and use it here
  • more importantly, if we are inside a kedro project, just not at the top level, is there actually any reason these project commands shouldn't work? 🤔 Instead of an error message telling the user to cd can we actually just somehow make kedro work inside a project subfolder (like kedro ipython does)? But without cding to the kedro project top-level
  • if we're totally outside a kedro project, a helpful error message is great but:
    • is there some better way to check if the command is a project one without overriding get_command, e.g. check if it's in self.project_groups?
    • I don't think this formatting is "on brand" yet since we haven't moved the rest of the CLI to rich yet. Let's just do it as click.secho for now. Doing rich styling for CLI messages is a separate issue for another time (e.g. we might move to https://github.com/ewels/rich-click)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#1720 Separate PR created here, I put it in the inbox so we can discuss it a bit more.

noklam and others added 4 commits July 21, 2022 11:24
Co-authored-by: Antony Milne <49395058+AntonyMilneQB@users.noreply.github.com>
This reverts commit edda3f1.

Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
Co-authored-by: Antony Milne <49395058+AntonyMilneQB@users.noreply.github.com>
Co-authored-by: Antony Milne <49395058+AntonyMilneQB@users.noreply.github.com>
noklam added 2 commits July 21, 2022 16:46
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
Comment on lines +28 to +32
PACKAGE_NAME = "fake_page_name"
PROJECT_NAME = "fake_project_name"
PROJECT_VERSION = "0.1"


Copy link
Contributor Author

Choose a reason for hiding this comment

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

just minor refactoring since these values appears a few time.

Comment on lines -56 to -58
mocker.patch("kedro.framework.project.settings.configure")
mocker.patch("kedro.framework.session.session.validate_settings")
mocker.patch("kedro.framework.session.KedroSession._setup_logging")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AntonyMilneQB Are these actually needed? I found that they are not in the test_load_kedro_objects_extra_args test and removing them seems to have no effect, I am not sure why it is needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably not needed 👍

@@ -67,16 +70,21 @@ def my_register_pipeline():
mock_register_line_magic = mocker.patch(
"kedro.extras.extensions.ipython.register_line_magic"
)
mock_context = mocker.patch("kedro.framework.session.KedroSession.load_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.

We should use session instead

noklam added 2 commits July 21, 2022 17:29
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
@noklam noklam requested a review from antonymilne July 21, 2022 16:42
@@ -58,7 +58,6 @@ def reload_kedro(

_remove_cached_modules(metadata.package_name)

configure_project(metadata.package_name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds like you are confident we can remove this, so please go ahead as you were before 👍

Comment on lines -56 to -58
mocker.patch("kedro.framework.project.settings.configure")
mocker.patch("kedro.framework.session.session.validate_settings")
mocker.patch("kedro.framework.session.KedroSession._setup_logging")
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably not needed 👍

@noklam noklam requested review from AhdraMeraliQB and removed request for SajidAlamQB July 22, 2022 13:51
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.

Great work! Good catch on the test refactoring too!

@noklam noklam merged commit 5ae97cf into main Jul 22, 2022
@noklam noklam deleted the fix/docs_session_create branch July 22, 2022 15:38
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.

Investigate KedroSession.create: ModuleNotFoundError: No module named 'None'
4 participants