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

[KED-2768] kedro install doesn't play well with hooks #829

Closed
mzjp2 opened this issue Jul 13, 2021 · 2 comments
Closed

[KED-2768] kedro install doesn't play well with hooks #829

mzjp2 opened this issue Jul 13, 2021 · 2 comments
Labels
Issue: Bug Report 🐞 Bug that needs to be fixed

Comments

@mzjp2
Copy link
Contributor

mzjp2 commented Jul 13, 2021

Description

Pipline registry for hooks

All Kedro CLI commands go through kedro/framework/cli/cli.py::KedroCLI whose __init__ runs bootstrap_project. Kedro's bootstrap_project reads the users project metadata and imports the user settings.py file.

The users settings.py file (at least in modern Kedro versions) by default imports ProjectHooks from the users hooks.py file.

If users choose to register their pipelines via the register_pipelines hooks inside ProjectHooks class (or any other class inside hooks.py) and import their pipelines at the module-level of hooks.py to use them inside register_pipelines, this triggers a chain import from bootstrap_project that imports settings.py -> hooks.py -> imported_pipeline -> imported_pipeline/pipeline.py -> imported_pipeline/nodes.py -> third_party_library.

This is fine for pretty much all CLI commands (though can contribute to slowing CLI commands down for large projects that have many imports, for CLI commands that don't necessarily need the whole project imported to do something) since having the projects requirements installed is a sensible pre-requisite to running any of them (e.g kedro run).

However, the exception to that is kedro install and kedro build-reqs which are presumably written to help users install their requirements. That is, the starting position of using those commands is that the users don't have their project requirements installed.

Third party hooks

If users want to register a third-party hook that doesn't register itself automatically, their settings.py looks something like:

from third_party_hook import ThirdPartyHook

hooks = (ProjectHooks(), ThirdPartyHook())

which kedro install imports and runs and fails at if third_party_hook isn't already installed.

Steps to Reproduce

kedro new --starter=pandas-iris

Put a import tensorflow or import non_existent_library in data_engineering/nodes.py and then register the data engineering pipeline (or really just import it) at the top-level of your hooks.py and try running kedro install.

Expected Result

kedro install should execute and install the project requirements.

Actual Result

kedro install fails with an import error.

Your Environment

Include as many relevant details about the environment in which you experienced the bug:

  • Kedro version used (pip show kedro or kedro -V): Kedro 0.17.4
  • Python version used (python -V): Python 3.7.11
  • Operating system and version: MacOS Mojave
@mzjp2 mzjp2 added the Issue: Bug Report 🐞 Bug that needs to be fixed label Jul 13, 2021
@lorenabalan lorenabalan changed the title kedro install doesn't play well with hooks [KED-2768] kedro install doesn't play well with hooks Jul 26, 2021
@limdauto
Copy link
Contributor

limdauto commented Jul 27, 2021

Related issue in starters repo: kedro-org/kedro-starters#38. So this is not necessarily just about hooks but rather kedro install needs to evaluate settings.py and any import there from third-party dependency will break the command.

@ignacioparicio
Copy link
Contributor

I'm closing this issue as it is now solved in master as part of [KED-2768] Fix kedro install flow (#1203). Thank you @mzjp2 for the amazing write-up and please shout is you'd like to discuss this further!

austospumanto pushed a commit to austospumanto/kedro that referenced this issue Aug 24, 2021
…o-develop

Merge master into develop via merge-master-to-develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Bug Report 🐞 Bug that needs to be fixed
Projects
None yet
Development

No branches or pull requests

3 participants