Skip to content

Commit

Permalink
Deprecate project_version and add add_ons to ProjectMetadata (#…
Browse files Browse the repository at this point in the history
…3222)

* remove project version

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>

* ammend release note

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>

* fixt test

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>

* fix startup test

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>

---------

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
  • Loading branch information
noklam authored Oct 24, 2023
1 parent 60f676e commit 05f1473
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 51 deletions.
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Renamed the `data_sets()` method in `Pipeline` and all references to it to `datasets()`.
* Renamed the `create_default_data_set()` method in the `Runner` to `create_default_dataset()`.
* Renamed all other uses of `data_set` and `data_sets` in the codebase to `dataset` and `datasets` respectively.
* Remove deprecated `project_version` from `ProjectMetadata`.

### DataSets
* Removed `kedro.extras.datasets` and tests.
Expand Down
24 changes: 5 additions & 19 deletions kedro/framework/startup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
"""This module provides metadata for a Kedro project."""
import os
import sys
import warnings
from pathlib import Path
from typing import NamedTuple, Union

import anyconfig

from kedro import KedroDeprecationWarning
from kedro import __version__ as kedro_version
from kedro.framework.project import configure_project

Expand All @@ -21,9 +19,9 @@ class ProjectMetadata(NamedTuple):
package_name: str
project_name: str
project_path: Path
project_version: str
source_dir: Path
kedro_init_version: str
add_ons: list


def _version_mismatch_error(kedro_init_version) -> str:
Expand Down Expand Up @@ -89,35 +87,23 @@ def _get_project_metadata(project_path: Union[str, Path]) -> ProjectMetadata:
f"configuration parameters."
) from exc

mandatory_keys = ["package_name", "project_name"]
mandatory_keys = ["package_name", "project_name", "kedro_init_version"]
missing_keys = [key for key in mandatory_keys if key not in metadata_dict]
if missing_keys:
raise RuntimeError(f"Missing required keys {missing_keys} from '{_PYPROJECT}'.")

# Temporary solution to keep project_version backwards compatible to be removed in 0.19.0
if "project_version" in metadata_dict:
warnings.warn(
"project_version in pyproject.toml is deprecated, use kedro_init_version instead",
KedroDeprecationWarning,
)
metadata_dict["kedro_init_version"] = metadata_dict["project_version"]
elif "kedro_init_version" in metadata_dict:
metadata_dict["project_version"] = metadata_dict["kedro_init_version"]
else:
raise RuntimeError(
f"Missing required key kedro_init_version from '{_PYPROJECT}'."
)

mandatory_keys.append("kedro_init_version")
# check the match for major and minor version (skip patch version)
if (
metadata_dict["kedro_init_version"].split(".")[:2]
!= kedro_version.split(".")[:2]
):
raise ValueError(_version_mismatch_error(metadata_dict["kedro_init_version"]))

# Default settings
source_dir = Path(metadata_dict.get("source_dir", "src")).expanduser()
source_dir = (project_path / source_dir).resolve()
metadata_dict["add_ons"] = metadata_dict.get("add_ons")

metadata_dict["source_dir"] = source_dir
metadata_dict["config_file"] = pyproject_toml
metadata_dict["project_path"] = project_path
Expand Down
14 changes: 7 additions & 7 deletions tests/framework/cli/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ def dummy_config(fake_root_dir, fake_metadata):
@fixture(scope="module")
def fake_metadata(fake_root_dir):
metadata = ProjectMetadata(
fake_root_dir / REPO_NAME / "pyproject.toml",
PACKAGE_NAME,
"CLI Testing Project",
fake_root_dir / REPO_NAME,
kedro_version,
fake_root_dir / REPO_NAME / "src",
kedro_version,
config_file=fake_root_dir / REPO_NAME / "pyproject.toml",
package_name=PACKAGE_NAME,
project_name="CLI Testing Project",
project_path=fake_root_dir / REPO_NAME,
kedro_init_version=kedro_version,
source_dir=fake_root_dir / REPO_NAME / "src",
add_ons=None,
)
return metadata

Expand Down
27 changes: 5 additions & 22 deletions tests/framework/test_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ def test_valid_toml_file(self, mocker):
config_file=self.project_path / "pyproject.toml",
package_name="fake_package_name",
project_name="fake_project_name",
project_version=kedro_version,
kedro_init_version=kedro_version,
project_path=self.project_path,
add_ons=None,
)
assert actual == expected

Expand All @@ -106,7 +106,7 @@ def test_valid_toml_file_with_project_version(self, mocker):
"kedro": {
"package_name": "fake_package_name",
"project_name": "fake_project_name",
"project_version": kedro_version,
"kedro_init_version": kedro_version,
}
}
}
Expand All @@ -119,9 +119,9 @@ def test_valid_toml_file_with_project_version(self, mocker):
config_file=self.project_path / "pyproject.toml",
package_name="fake_package_name",
project_name="fake_project_name",
project_version=kedro_version,
kedro_init_version=kedro_version,
project_path=self.project_path,
add_ons=None,
)
assert actual == expected

Expand Down Expand Up @@ -230,7 +230,7 @@ def test_invalid_version_for_kedro_version(self, invalid_version, mocker):
"source_dir": "source_dir",
"package_name": "fake_package_name",
"project_name": "fake_project_name",
"project_version": invalid_version,
"kedro_init_version": invalid_version,
}
}
}
Expand All @@ -243,23 +243,6 @@ def test_invalid_version_for_kedro_version(self, invalid_version, mocker):
with pytest.raises(ValueError, match=re.escape(pattern)):
_get_project_metadata(self.project_path)

def test_toml_file_has_missing_version(self, mocker):
mocker.patch.object(Path, "is_file", return_value=True)
pyproject_toml_payload = {
"tool": {
"kedro": {
"source_dir": "source_dir",
"package_name": "fake_package_name",
"project_name": "fake_project_name",
}
}
}
mocker.patch("anyconfig.load", return_value=pyproject_toml_payload)
pattern = "Missing required key kedro_init_version from 'pyproject.toml'."

with pytest.raises(RuntimeError, match=re.escape(pattern)):
_get_project_metadata(self.project_path)


class TestValidateSourcePath:
@pytest.mark.parametrize(
Expand Down Expand Up @@ -315,9 +298,9 @@ def test_bootstrap_project(self, monkeypatch, tmp_path):
"package_name": "fake_package_name",
"project_name": "fake_project_name",
"project_path": tmp_path,
"project_version": kedro_version,
"kedro_init_version": kedro_version,
"source_dir": src_dir,
"add_ons": None,
}
assert result == ProjectMetadata(**expected_metadata)
assert str(src_dir) in sys.path[0]
Expand Down
6 changes: 3 additions & 3 deletions tests/ipython/test_ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

PACKAGE_NAME = "fake_package_name"
PROJECT_NAME = "fake_project_name"
PROJECT_VERSION = "0.1"
PROJECT_INIT_VERSION = "0.1"


@pytest.fixture(autouse=True)
Expand All @@ -36,9 +36,9 @@ def fake_metadata(tmp_path):
config_file=tmp_path / "pyproject.toml",
package_name=PACKAGE_NAME,
project_name=PROJECT_NAME,
project_version=PROJECT_VERSION,
kedro_init_version=PROJECT_VERSION,
kedro_init_version=PROJECT_INIT_VERSION,
project_path=tmp_path,
add_ons=None,
)
return metadata

Expand Down

0 comments on commit 05f1473

Please sign in to comment.