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

Add support for %load_ext kedro #4406

Merged
merged 14 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Implemented `KedroDataCatalog.to_config()` method that converts the catalog instance into a configuration format suitable for serialization.
* Improve OmegaConfigLoader performance.
* Replaced `trufflehog` with `detect-secrets` for detecting secrets within a code base.
* Added support for `%load_ext kedro`.

## Bug fixes and other changes
* Added validation to ensure dataset versions consistency across catalog.
Expand Down
7 changes: 7 additions & 0 deletions kedro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import sys
import warnings
from typing import Any

__version__ = "0.19.10"

Expand All @@ -29,3 +30,9 @@ class KedroPythonVersionWarning(UserWarning):
or set the PYTHONWARNINGS environment variable accordingly.""",
KedroPythonVersionWarning,
)


def load_ipython_extension(ipython: Any) -> None:
astrojuanlu marked this conversation as resolved.
Show resolved Hide resolved
import kedro.ipython

kedro.ipython.load_ipython_extension(ipython)
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ layers = [
]
ignore_imports = [
"kedro.runner.task -> kedro.framework.project",
"kedro.framework.hooks.specs -> kedro.framework.context"
"kedro.framework.hooks.specs -> kedro.framework.context",
"kedro -> kedro.ipython"
]

[[tool.importlinter.contracts]]
Expand All @@ -188,6 +189,9 @@ modules = [
"kedro.pipeline",
"kedro.io"
]
ignore_imports = [
"kedro -> kedro.ipython"
]

[[tool.importlinter.contracts]]
name = "Config cannot import Runner et al"
Expand Down
11 changes: 11 additions & 0 deletions tests/ipython/test_ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@ def test_line_magic_with_invalid_arguments(self, mocker, ipython):
):
ipython.magic("reload_kedro --invalid_arg=dummy")

def test_ipython_kedro_extension_alias(self, mocker, ipython):
mock_ipython_extension = mocker.patch(
"kedro.ipython.load_ipython_extension", autospec=True
)
# Ensure that `kedro` is not loaded initially
assert "kedro" not in ipython.extension_manager.loaded
ipython.magic("load_ext kedro")
mock_ipython_extension.assert_called_once_with(ipython)
# Ensure that `kedro` extension has been loaded
assert "kedro" in ipython.extension_manager.loaded


class TestProjectPathResolution:
def test_only_path_specified(self):
Expand Down
Loading