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-3023] Enable plugins to extend starter-aliases default list #1592

Merged
merged 87 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
920d3dd
Taking over PR changes
noklam Jun 6, 2022
6460244
Update README
noklam Jun 6, 2022
c040cf6
Adding starters entrypoints - Fix unittest
noklam Jun 6, 2022
6f86722
Fix outdate starter alias
noklam Jun 6, 2022
af19d46
Bug fix for sorting dictionary with itemgetter
noklam Jun 7, 2022
27e8caf
Refactor variable name
noklam Jun 7, 2022
9698fd6
linter
noklam Jun 7, 2022
86288f8
Refactor entrypoints with importlib
noklam Jun 7, 2022
e1d00ae
More refactoring to simplify code
noklam Jun 7, 2022
d994b42
Refactor naming
noklam Jun 7, 2022
bcd0393
attempt to add e2etest
noklam Jun 7, 2022
2fc68fd
some more refactoring
noklam Jun 7, 2022
6390d12
Fix test and linting
noklam Jun 7, 2022
6252cd6
fix unittest
noklam Jun 7, 2022
02d434e
Fix e2etest
noklam Jun 7, 2022
52b5153
Fix unittest
noklam Jun 7, 2022
d700e3b
fix lint
noklam Jun 7, 2022
fc4c130
Fix all unittest and e2etest
noklam Jun 7, 2022
56ee39c
Merge branch 'main' into feat/enable-plugin-starter-alias
noklam Jun 8, 2022
c8a7a22
Fix more linting - line too long
noklam Jun 8, 2022
39f5440
Fix linting
noklam Jun 8, 2022
7b07bcb
refactor with a KedroStarterSpec class
noklam Jun 8, 2022
35af295
Refactor
noklam Jun 9, 2022
2321929
Merge branch 'main' into feat/enable-plugin-starter-alias
noklam Jun 9, 2022
e872146
Apply suggestions from code review
noklam Jun 10, 2022
6cf1434
Apply suggestions from code review
noklam Jun 10, 2022
ffd0d5b
Apply suggestions from code review
noklam Jun 10, 2022
8cda6cf
remove duplicated
noklam Jun 10, 2022
80f8ce6
refactor naming
noklam Jun 10, 2022
3a5b9d1
Add attrs requirements
noklam Jun 10, 2022
8c270df
More refactor to make it nice and pass tests
noklam Jun 10, 2022
eb53807
refactoring
noklam Jun 13, 2022
53ae272
Merge branch 'main' into feat/enable-plugin-starter-alias
noklam Jun 13, 2022
7e59275
Merge branch 'main' into feat/enable-plugin-starter-alias
noklam Jun 14, 2022
f318734
minor bug fix for alias not accessible if it's not a valid spec
noklam Jun 14, 2022
a342d82
Fix e2e test
noklam Jun 14, 2022
dacc575
Bug fix when no plugins is installed and get stopIteration error
noklam Jun 14, 2022
183714b
Fix linting
noklam Jun 14, 2022
1053815
Update doc
noklam Jun 14, 2022
2fbf418
update doc
noklam Jun 14, 2022
9276133
Merge branch 'main' into feat/enable-plugin-starter-alias
noklam Jun 14, 2022
7b44f70
Fix docstring
noklam Jun 14, 2022
dd24539
Apply PR reviews and refactor
noklam Jun 15, 2022
9ef6f90
Fix bug when multiple plugins installed it will only print one of the…
noklam Jun 15, 2022
e29da9c
fix pre-commit hook for attrs
noklam Jun 15, 2022
7ec8e39
Linting
noklam Jun 15, 2022
f114a36
fiz linting and minor bug
noklam Jun 15, 2022
3c7bb9a
Merge branch 'main' into feat/enable-plugin-starter-alias
noklam Jun 15, 2022
051c284
attempt to fix Import-Linter cannot be built issue
noklam Jun 16, 2022
c6b5bd3
Apply changes for Merel's review
noklam Jun 16, 2022
9111e5a
Merge branch 'main' into feat/enable-plugin-starter-alias
noklam Jun 16, 2022
af3dfac
print text when assertion fails
noklam Jun 16, 2022
a2adb82
[TEMP] - print console log for e2e
noklam Jun 17, 2022
4fbc21a
update documentation and minor refactoring
noklam Jun 17, 2022
5757c57
refactor e2etest
noklam Jun 17, 2022
fbb1533
fix linting
noklam Jun 17, 2022
c75c463
Bug fix when refactoring the argument the CLI argument isn't updated …
noklam Jun 17, 2022
dafe6ab
Consistent click message color and stricter test for plugin
noklam Jun 17, 2022
0a8f137
Update docs/source/extend_kedro/create_kedro_starters.md
noklam Jun 17, 2022
740da88
fix lint
noklam Jun 17, 2022
b18100f
Fix doclink
noklam Jun 17, 2022
6516967
Fix link
noklam Jun 20, 2022
6234ee3
Fix broken link
noklam Jun 20, 2022
04da315
Merge branch 'main' into feat/enable-plugin-starter-alias
noklam Jun 20, 2022
b87aae0
remove pypropject build
noklam Jun 20, 2022
1de52d1
Add pyproject to fix py310 window test
noklam Jun 20, 2022
611eedb
Move KedroStarterSpec to framework __init__
noklam Jun 22, 2022
99cd4e7
Fix broken doc
noklam Jun 22, 2022
92777ea
Fix linting
noklam Jun 22, 2022
5d96b71
Put framework logging into LOGGING and guard configure_logging from a…
antonymilne Jun 22, 2022
a234f84
Fix tests
antonymilne Jun 22, 2022
2b23ee1
Update kedro/config/config.py
antonymilne Jun 22, 2022
aa78c06
Take 2 with no default_logger file at all
antonymilne Jun 24, 2022
1c5fa6c
Tidy
antonymilne Jun 24, 2022
b72e916
More tidy
antonymilne Jun 24, 2022
5ea3f8c
Merge branch 'main' into fix/parallel-runner-logging
antonymilne Jun 24, 2022
de4cb59
Apply suggestions from code review
antonymilne Jun 24, 2022
1f36779
Fix up tests
antonymilne Jun 24, 2022
880bc29
More fix tests
antonymilne Jun 24, 2022
15f117e
Fix MANIFEST.in
antonymilne Jun 24, 2022
f5ccde4
Lint
antonymilne Jun 24, 2022
0abfd6a
Fix linkcheck
antonymilne Jun 24, 2022
e603ba2
Update RELEASE
antonymilne Jun 24, 2022
d5dd2ec
Merge branch 'main' into fix/parallel-runner-logging
antonymilne Jun 27, 2022
f6a4118
Revert "Move KedroStarterSpec to framework __init__"
noklam Jun 27, 2022
e44f5fb
[TEMP] - Merge branch 'fix/parallel-runner-logging' into feat/enable-…
noklam Jun 27, 2022
698bdb8
Merge branch 'main' into feat/enable-plugin-starter-alias
noklam Jun 29, 2022
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 .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ repos:
- types-requests
- types-setuptools
- types-toml
- attrs

- repo: https://github.com/asottile/blacken-docs
rev: v1.12.1
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test-no-spark:
pytest tests --no-cov --ignore tests/extras/datasets/spark --numprocesses 4 --dist loadfile

e2e-tests:
behave
behave --no-capture

pip-compile:
pip-compile -q -o -
Expand Down
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Added `abfss` to list of cloud protocols, enabling abfss paths.
* Kedro now uses the [Rich](https://github.com/Textualize/rich) library to format terminal logs and tracebacks.
* The file `conf/base/logging.yml` is now optional. See [our documentation](https://kedro.readthedocs.io/en/0.18.2/logging/logging.html) for details.
* Introduced a `kedro.starters` entry point. This enables plugins to create custom starter aliases used by `kedro starter list` and `kedro new`.

## Bug fixes and other changes
* Bumped `pyyaml` upper bound to make Kedro compatible with the [pyodide](https://pyodide.org/en/stable/usage/loading-packages.html#micropip) stack.
Expand Down
4 changes: 4 additions & 0 deletions docs/source/extend_kedro/create_kedro_starters.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ Here is the layout of the project as a Cookiecutter template:
├── setup.py
└── tests
```

```{note}
You can add an alias by creating a plugin using [`kedro.starters` entry point](../plugin.md#extend-starter-aliases), which will allows you to do `kedro new --starter=your_starters` and shows up on shows up on `kedro starter list`.
noklam marked this conversation as resolved.
Show resolved Hide resolved
```
25 changes: 25 additions & 0 deletions docs/source/extend_kedro/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,31 @@ Once the plugin is installed, you can run it as follows:
kedro to_json
```

## Extend starter aliases
It is possible to extend the list of starter aliases built into Kedro. This means that a [custom Kedro starter](create_kedro_starters.md) can be used directly through the `starter` argument in `kedro new` rather than needing to explicitly provide the `template` and `directory` arguments. A custom starter alias behaves in the same way as an official Kedro starter alias and is also picked up by `kedro starter list`.

You need to extend the starters by providing a list of `KedroStarterSpec`, in this example it is defined in a file called `plugin.py`.
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to mention where this file should be, e.g. src/.....


```python
starters = [
KedroStarterSpec(
alias="test_plugin_starter",
template_path="https://github.com/kedro-org/kedro-starters/",
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work? We have git+https://github.com/kedro-org/kedro-starters.git in the source code?

Edit: just tried it and it does!

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should be consistent about how we do it though. Probably URL to a git repo is a bit nicer than the git+ address.

directory="pandas-iris",
)
]

The `directory` argument is optional and should be used when you have multiple templates in one repository as for the [official kedro-starters](https://github.com/kedro-org/kedro-starters). If you only have one template, your top-level directory will be treated as the template. You can take the [pandas-iris](https://github.com/kedro-org/kedro-starters/tree/main/pandas-iris) example for reference.
```

In your `setup.py`, you need to register the specifications to `kedro.starters`.

```python
setup(
entry_points={"kedro.starters": ["starter = plugin:starters"]},
)
```

## Working with `click`

Commands must be provided as [`click` `Groups`](https://click.palletsprojects.com/en/7.x/api/#click.Group)
Expand Down
2 changes: 1 addition & 1 deletion features/activate_nbstripout.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Feature: Activate_nbstripout target in new project

Scenario: Check nbstripout git post commit hook functionality
Given I have prepared a config file
And I have run a non-interactive kedro new with starter
And I have run a non-interactive kedro new with starter "default"
And I have added a test jupyter notebook
And I have initialized a git repository
And I have added the project directory to staging
Expand Down
2 changes: 1 addition & 1 deletion features/build_docs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Feature: build-docs target in new project
@fresh_venv
Scenario: Execute build-docs target
Given I have prepared a config file
And I have run a non-interactive kedro new with starter
And I have run a non-interactive kedro new with starter "default"
And I have updated kedro requirements
And I have installed the project dependencies
When I execute the kedro command "build-docs"
Expand Down
2 changes: 1 addition & 1 deletion features/build_reqs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Feature: build-reqs target in new project
@fresh_venv
Scenario: Execute build-reqs target
Given I have prepared a config file
And I have run a non-interactive kedro new with starter
And I have run a non-interactive kedro new with starter "default"
And I have updated kedro requirements
And I have executed the kedro command "build-reqs"
When I add scrapy>=1.7.3 to the requirements
Expand Down
2 changes: 1 addition & 1 deletion features/info.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: Run kedro info
Background:
Given I have prepared a config file
And I have run a non-interactive kedro new with starter
And I have run a non-interactive kedro new with starter "default"

Scenario: Plugins are installed and detected by kedro info
Given I have installed the test plugin
Expand Down
2 changes: 1 addition & 1 deletion features/ipython.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Feature: IPython target in new project

Scenario: Execute ipython target
Given I have prepared a config file
And I have run a non-interactive kedro new with starter
And I have run a non-interactive kedro new with starter "default"
When I execute the kedro command "ipython"
Then I should get a message including "An enhanced Interactive Python"
And I should get a message including "Kedro project project-dummy"
Expand Down
2 changes: 1 addition & 1 deletion features/jupyter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Feature: Jupyter targets in new project

Background:
Given I have prepared a config file
And I have run a non-interactive kedro new with starter
And I have run a non-interactive kedro new with starter "default"

Scenario: Execute jupyter-notebook target
When I execute the kedro jupyter command "notebook --no-browser"
Expand Down
2 changes: 1 addition & 1 deletion features/load_context.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: Custom Kedro project
Background:
Given I have prepared a config file
And I have run a non-interactive kedro new with starter
And I have run a non-interactive kedro new with starter "default"

Scenario: Update the source directory to be nested
When I move the package to "src/nested"
Expand Down
12 changes: 9 additions & 3 deletions features/new_project.feature
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
Feature: New Kedro project
Background:
Given I have prepared a config file

Scenario: Create a new kedro project without example code
Given I have prepared a config file
When I run a non-interactive kedro new without starter
Then the expected project directories and files should be created
And the pipeline should contain no nodes

Scenario: Create a new kedro project with example code
Given I have prepared a config file
When I run a non-interactive kedro new with starter
When I run a non-interactive kedro new with starter "default"
Then the expected project directories and files should be created
And the pipeline should contain nodes

Scenario: Plugins are installed and create a new kedro project with custom plugin starter
Given I have installed the test plugin
When I run a non-interactive kedro new with starter "test_plugin_starter"
Then the expected project directories and files should be created
And the pipeline should contain nodes
2 changes: 1 addition & 1 deletion features/package.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Feature: Package target in new project

Background:
Given I have prepared a config file
And I have run a non-interactive kedro new with starter
And I have run a non-interactive kedro new with starter "default"
And I have installed the project dependencies

@fresh_venv
Expand Down
10 changes: 5 additions & 5 deletions features/run.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ Feature: Run Project
Local environment should be used by default when no env option is specified.

Given I have prepared a config file
And I have run a non-interactive kedro new with starter
And I have run a non-interactive kedro new with starter "default"
When I execute the kedro command "run"
Then I should get a successful exit code
And the logs should show that 4 nodes were run

Scenario: Run parallel runner with default python entry point with example code
Given I have prepared a config file
And I have run a non-interactive kedro new with starter
And I have run a non-interactive kedro new with starter "default"
When I execute the kedro command "run --runner=ParallelRunner"
Then I should get a successful exit code
And the logs should show that "split_data" was run
Expand All @@ -30,23 +30,23 @@ Feature: Run Project

Scenario: Run kedro run with config file
Given I have prepared a config file
And I have run a non-interactive kedro new with starter
And I have run a non-interactive kedro new with starter "default"
And I have prepared a run_config file with config options
When I execute the kedro command "run --config run_config.yml"
Then I should get a successful exit code
And the logs should show that 1 nodes were run

Scenario: Run kedro run with config file and override option
Given I have prepared a config file
And I have run a non-interactive kedro new with starter
And I have run a non-interactive kedro new with starter "default"
And I have prepared a run_config file with config options
When I execute the kedro command "run --config run_config.yml --pipeline __default__"
Then I should get a successful exit code
And the logs should show that 4 nodes were run

Scenario: Run kedro run with extra parameters
Given I have prepared a config file
And I have run a non-interactive kedro new with starter
And I have run a non-interactive kedro new with starter "default"
When I execute the kedro command "run --params extra1:1,extra2:value2"
Then I should get a successful exit code
And the logs should show that 4 nodes were run
9 changes: 9 additions & 0 deletions features/starter.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Feature: List Kedro Starters
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Feature: List Kedro Starters
Feature: List Kedro starters


Scenario: List all starters with custom starters from plugin
Given I have prepared a config file
And I have installed the test plugin
And I have run a non-interactive kedro new with starter "default"
When I execute the kedro command "starter list"
Then I should get a successful exit code
And I should get a message including "test_plugin_starter"
14 changes: 8 additions & 6 deletions features/steps/cli_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,21 @@ def add_test_jupyter_nb(context):
test_nb_fh.write(TEST_JUPYTER_ORG)


@given("I have run a non-interactive kedro new with starter")
@when("I run a non-interactive kedro new with starter")
def create_project_with_starter(context):
@given('I have run a non-interactive kedro new with starter "{starter}"')
@when('I run a non-interactive kedro new with starter "{starter}"')
def create_project_with_starter(context, starter):
Copy link
Member

Choose a reason for hiding this comment

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

Could the default for starter be None so we don't have to add "default" to all tests, or does that not work for the behave tests?

"""Behave step to run kedro new given the config I previously created."""
starter_dir = Path(__file__).parent / "test_starter"
if starter == "default":
starter = Path(__file__).parent / "test_starter"

res = run(
[
context.kedro,
"new",
"-c",
str(context.config_file),
"--starter",
str(starter_dir),
str(starter),
],
env=context.env,
cwd=context.temp_dir,
Expand Down Expand Up @@ -468,7 +470,7 @@ def check_correct_nodes_run(context, node):
"Expected the following message segment to be printed on stdout: "
f"{expected_log_line},\nbut got {stdout}"
)
assert expected_log_line in info_log.read_text()
assert expected_log_line in info_log.read_text(), info_log.read_text()


@then("I should get a successful exit code")
Expand Down
11 changes: 10 additions & 1 deletion features/steps/test_plugin/plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Dummy plugin with simple hook implementations."""
import logging

from kedro.framework.cli.starters import KedroStarterSpec
from kedro.framework.hooks import hook_impl

logger = logging.getLogger(__name__)
Expand All @@ -11,8 +12,16 @@ class MyPluginHook:
@hook_impl
def after_catalog_created(
self, catalog
): # pylint: disable=unused-argument,no-self-use
): # pylint: disable=unused-argument, no-self-use
logger.info("Reached after_catalog_created hook")


starters = [
KedroStarterSpec(
"test_plugin_starter",
template_path="https://github.com/kedro-org/kedro-starters/",
directory="pandas-iris",
)
]

hooks = MyPluginHook()
7 changes: 5 additions & 2 deletions features/steps/test_plugin/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
setup(
name="test_plugin",
version="0.1",
description="Dummy plugin with hook implementations",
description="Dummy plugin with hook implementations and custom starters",
packages=find_packages(),
entry_points={"kedro.hooks": ["test_plugin = plugin:hooks"]},
entry_points={
"kedro.hooks": ["test_plugin = plugin:hooks"],
"kedro.starters": ["starter = plugin:starters"],
},
)
2 changes: 1 addition & 1 deletion features/test.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Feature: Test target in new project

Background:
Given I have prepared a config file
And I have run a non-interactive kedro new with starter
And I have run a non-interactive kedro new with starter "default"

Scenario: Execute successful test in new project
When I execute the kedro command "test"
Expand Down
6 changes: 3 additions & 3 deletions kedro/framework/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from typing import Sequence

import click
import importlib_metadata

# pylint: disable=unused-import
import kedro.config.default_logger # noqa
Expand All @@ -29,6 +28,7 @@
ENTRY_POINT_GROUPS,
CommandCollection,
KedroCliError,
_get_entry_points,
load_entry_points,
)
from kedro.framework.startup import _is_project, bootstrap_project
Expand Down Expand Up @@ -67,8 +67,8 @@ def info():

plugin_versions = {}
plugin_entry_points = defaultdict(set)
for plugin_entry_point, group in ENTRY_POINT_GROUPS.items():
for entry_point in importlib_metadata.entry_points().select(group=group):
for plugin_entry_point in ENTRY_POINT_GROUPS:
for entry_point in _get_entry_points(plugin_entry_point):
module_name = entry_point.module.split(".")[0]
plugin_versions[module_name] = entry_point.dist.version
plugin_entry_points[module_name].add(plugin_entry_point)
Expand Down
2 changes: 1 addition & 1 deletion kedro/framework/cli/micropkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def _package_micropkgs_from_manifest(metadata: ProjectMetadata) -> None:
@click.pass_obj # this will pass the metadata as first argument
def package_micropkg(
metadata: ProjectMetadata, module_path, env, alias, destination, all_flag
): # pylint: disable=too-many-arguments
):
"""Package up a modular pipeline or micro-package as a Python source distribution."""
if not module_path and not all_flag:
click.secho(
Expand Down
Loading