Skip to content

Commit

Permalink
Fix micropkg manifest section in pyproject.toml (#2119)
Browse files Browse the repository at this point in the history
Signed-off-by: Merel Theisen <merel.theisen@quantumblack.com>
  • Loading branch information
merelcht authored Dec 14, 2022
1 parent 45027f9 commit f72b346
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
## Major features and improvements

## Bug fixes and other changes
* Fix bug where `micropkg` manifest section in `pyproject.toml` isn't recognised as allowed configuration.

## Breaking changes to the API

Expand Down
12 changes: 6 additions & 6 deletions docs/source/kedro_project_setup/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Both `pip install kedro` and `conda install -c conda-forge kedro` install the co
When you create a project, you then introduce additional dependencies for the tasks it performs.

## Project-specific dependencies
You can specify a project's exact dependencies in the `src/requirements.txt` file to make it easier for you and others to run your project in the future,
and to avoid version conflicts downstream. This can be achieved with the help of [`pip-tools`](https://pypi.org/project/pip-tools/).
You can specify a project's exact dependencies in the `src/requirements.txt` file to make it easier for you and others to run your project in the future,
and to avoid version conflicts downstream. This can be achieved with the help of [`pip-tools`](https://pypi.org/project/pip-tools/).
To install `pip-tools` in your virtual environment, run the following command:
```bash
pip install pip-tools
Expand All @@ -18,10 +18,10 @@ To add or remove dependencies to a project, edit the `src/requirements.txt` file
pip-compile --output-file=<project_root>/src/requirements.txt --input-file=<project_root>/src/requirements.txt
```

This will [pip compile](https://github.com/jazzband/pip-tools#example-usage-for-pip-compile) the requirements listed in
the `src/requirements.txt` file into a `src/requirements.lock` that specifies a list of pinned project dependencies
(those with a strict version). You can also use this command with additional CLI arguments such as `--generate-hashes`
to use `pip`'s Hash Checking Mode or `--upgrade-package` to update specific packages to the latest or specific versions.
This will [pip compile](https://github.com/jazzband/pip-tools#example-usage-for-pip-compile) the requirements listed in
the `src/requirements.txt` file into a `src/requirements.lock` that specifies a list of pinned project dependencies
(those with a strict version). You can also use this command with additional CLI arguments such as `--generate-hashes`
to use `pip`'s Hash Checking Mode or `--upgrade-package` to update specific packages to the latest or specific versions.
[Check out the `pip-tools` documentation](https://pypi.org/project/pip-tools/) for more information.

```{note}
Expand Down
2 changes: 1 addition & 1 deletion docs/source/nodes_and_pipelines/micro_packaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ You can pull a micro-package from a tar file by executing `kedro micropkg pull <
* To place parameters from a different config environment, run `kedro micropkg pull <micropkg_name> --env <env_name>`
* Unit tests in `src/tests/<micropkg_name>`
* Kedro will also parse any requirements packaged with the micro-package and add them to project level `requirements.in`.
* It is advised to compile an updated list of requirements after pulling a micro-package using [`pip-compile`](https://pypi.org/project/pip-tools/).
* It is advised to compile an updated list of requirements after pulling a micro-package using [`pip-compile`](https://pypi.org/project/pip-tools/).

```{note}
If a micro-package has embedded requirements and a project `requirements.in` file does not already exist, it will be generated based on the project `requirements.txt` before appending the micro-package requirements.
Expand Down
19 changes: 19 additions & 0 deletions features/micropkg.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Feature: Micro-package target in new project

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

@fresh_venv
Scenario: Package a micro-package
When I execute the kedro command "micropkg package pipelines.data_science"
Then I should get a successful exit code
And I should get a message including "'project_dummy.pipelines.data_science' packaged!"

@fresh_venv
Scenario: Package a micro-package from manifest
Given I have micro-packaging settings in pyproject.toml
When I execute the kedro command "micropkg package --all"
Then I should get a successful exit code
And I should get a message including "Packaged 'pipelines.data_science' micro-package!"
14 changes: 14 additions & 0 deletions features/steps/cli_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import shutil
import textwrap
from pathlib import Path
from time import time

Expand Down Expand Up @@ -621,3 +622,16 @@ def check_cell_conversion(context: behave.runner.Context):
/ "hello_world.py"
)
assert "Hello World!" in converted_file.read_text()


@given("I have micro-packaging settings in pyproject.toml")
def add_micropkg_to_pyproject_toml(context: behave.runner.Context):
pyproject_toml_path = context.root_project_dir / "pyproject.toml"
project_toml_str = textwrap.dedent(
"""
[tool.kedro.micropkg.package]
"pipelines.data_science" = {alias = "ds"}
"""
)
with pyproject_toml_path.open(mode="a") as file:
file.write(project_toml_str)
2 changes: 1 addition & 1 deletion kedro/framework/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _get_project_metadata(project_path: Union[str, Path]) -> ProjectMetadata:
metadata_dict["source_dir"] = source_dir
metadata_dict["config_file"] = pyproject_toml
metadata_dict["project_path"] = project_path
metadata_dict.pop("pipeline", {}) # don't include micro-packaging specs
metadata_dict.pop("micropkg", {}) # don't include micro-packaging specs

try:
return ProjectMetadata(**metadata_dict)
Expand Down

0 comments on commit f72b346

Please sign in to comment.