Skip to content

Commit

Permalink
Replace the 00-kedro-init.py script with the Kedro IPython extensio…
Browse files Browse the repository at this point in the history
…n for new projects (#1194)
  • Loading branch information
idanov authored Jul 29, 2021
1 parent 5ca2fca commit 7613dec
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 173 deletions.
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Added support for dependency management at a modular pipeline level. When a pipeline with `requirements.txt` is packaged, its dependencies are embedded in the modular pipeline wheel file. Upon pulling the pipeline, Kedro will append dependencies to the project's `requirements.in`. More information is available in [our documentation](https://kedro.readthedocs.io/en/stable/06_nodes_and_pipelines/03_modular_pipelines.html#package-a-modular-pipeline).
* Added support for bulk packaging modular pipelines using `kedro pipeline package --all` and `pyproject.toml`.
* Removed `cli.py` from the Kedro project template. By default all CLI commands, including `kedro run`, are now defined on the Kedro framework side. These can be overridden in turn by a plugin or a `cli.py` file in your project. A packaged Kedro project will respect the same hierarchy when executed with `python -m my_package`.
* Removed `.ipython/profile_default/startup/` from the Kedro project template in favour of `.ipython/profile_default/ipython_config.py` and the `kedro.extras.extensions.ipython`.

## Bug fixes and other changes

Expand Down
3 changes: 1 addition & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,9 @@
"https://zenodo.org/badge/latestdoi/182067506",
"https://eternallybored.org/misc/wget/",
"https://arrow.apache.org/docs/python/generated/pyarrow.Table.html#pyarrow.Table.from_pandas",
"https://www.oracle.com/java/technologies/javase-downloads.html", # "forbidden" url
"https://www.oracle.com/java/technologies/javase-downloads.html", # "forbidden" url
"https://towardsdatascience.com/the-importance-of-layered-thinking-in-data-engineering-a09f685edc71",
"https://medium.com/quantumblack/beyond-the-notebook-and-into-the-data-science-framework-revolution-a7fd364ab9c4",

]

# retry before render a link broken (fix for "too many requests")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c.InteractiveShellApp.extensions.append("kedro.extras.extensions.ipython")

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ After this, if you'd like to update your project requirements, please update `sr

## How to work with Kedro and notebooks

> Note: Using `kedro jupyter` or `kedro ipython` to run your notebook provides these variables in scope: `context`, `catalog`, and `startup_error`.
> Note: Using `kedro jupyter` or `kedro ipython` to run your notebook provides these variables in scope: `context`, `catalog`, and `session`.
### Jupyter
To use Jupyter notebooks in your Kedro project, you need to install Jupyter:
Expand Down
27 changes: 19 additions & 8 deletions kedro/extras/extensions/ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@
from IPython import get_ipython
from IPython.core.magic import needs_local_scope, register_line_magic

project_path = Path.cwd()
catalog = None
context = None
session = None
startup_path = Path.cwd()
project_path = startup_path


def _remove_cached_modules(package_name):
Expand All @@ -61,6 +59,17 @@ def _clear_hook_manager():
hook_manager.unregister(name=name, plugin=plugin) # pragma: no cover


def _find_kedro_project(current_dir): # pragma: no cover
from kedro.framework.startup import _is_project

while current_dir != current_dir.parent:
if _is_project(current_dir):
return current_dir
current_dir = current_dir.parent

return None


def reload_kedro(path, env: str = None, extra_params: Dict[str, Any] = None):
"""Line magic which reloads all Kedro default variables."""

Expand All @@ -70,10 +79,6 @@ def reload_kedro(path, env: str = None, extra_params: Dict[str, Any] = None):
from kedro.framework.session.session import _activate_session
from kedro.framework.startup import bootstrap_project

global context
global catalog
global session

_clear_hook_manager()

path = path or project_path
Expand Down Expand Up @@ -115,9 +120,15 @@ def init_kedro(path=""):

def load_ipython_extension(ipython):
"""Main entry point when %load_ext is executed"""

global project_path
global startup_path

ipython.register_magic_function(init_kedro, "line")
ipython.register_magic_function(reload_kedro, "line", "reload_kedro")

project_path = _find_kedro_project(startup_path)

try:
reload_kedro(project_path)
except (ImportError, ModuleNotFoundError):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c.InteractiveShellApp.extensions.append("kedro.extras.extensions.ipython")

This file was deleted.

0 comments on commit 7613dec

Please sign in to comment.