From 7963b61e72cf7ac5c3db4d191097444dabd4e110 Mon Sep 17 00:00:00 2001 From: Merel Theisen <49397448+merelcht@users.noreply.github.com> Date: Wed, 12 Jun 2024 14:24:24 +0100 Subject: [PATCH] Add deprecation warning to get_pkg_version (#3947) * Add deprecation warning to get_pkg_version Signed-off-by: Merel Theisen --- RELEASE.md | 3 +++ kedro/framework/cli/utils.py | 7 +++++++ tests/framework/cli/test_cli.py | 10 +++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/RELEASE.md b/RELEASE.md index b14a51c38d..4824c264ce 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -6,6 +6,9 @@ ## Breaking changes to the API +## Upcoming deprecations for Kedro 0.20.0 +* The utility method `get_pkg_version()` is deprecated and will be removed in Kedro 0.20.0. + ## Documentation changes ## Community contributions diff --git a/kedro/framework/cli/utils.py b/kedro/framework/cli/utils.py index eda9bc005c..2d298bd770 100644 --- a/kedro/framework/cli/utils.py +++ b/kedro/framework/cli/utils.py @@ -11,6 +11,7 @@ import textwrap import traceback import typing +import warnings from collections import defaultdict from importlib import import_module from itertools import chain @@ -21,6 +22,8 @@ import importlib_metadata from omegaconf import OmegaConf +from kedro import KedroDeprecationWarning + CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]} MAX_SUGGESTIONS = 3 CUTOFF = 0.5 @@ -218,6 +221,10 @@ def get_pkg_version(reqs_path: (str | Path), package_name: str) -> str: KedroCliError: If the file specified in ``reqs_path`` does not exist or ``package_name`` was not found in that file. """ + warnings.warn( + "`get_pkg_version()` has been deprecated and will be removed in Kedro 0.20.0", + KedroDeprecationWarning, + ) reqs_path = Path(reqs_path).absolute() if not reqs_path.is_file(): raise KedroCliError(f"Given path '{reqs_path}' is not a regular file.") diff --git a/tests/framework/cli/test_cli.py b/tests/framework/cli/test_cli.py index d147a6a0d1..857e71a859 100644 --- a/tests/framework/cli/test_cli.py +++ b/tests/framework/cli/test_cli.py @@ -6,8 +6,9 @@ import click from click.testing import CliRunner from omegaconf import OmegaConf -from pytest import fixture, mark, raises +from pytest import fixture, mark, raises, warns +from kedro import KedroDeprecationWarning from kedro import __version__ as version from kedro.framework.cli import load_entry_points from kedro.framework.cli.catalog import catalog_cli @@ -245,6 +246,13 @@ def test_get_pkg_version(self, requirements_file): non_existent_file = str(requirements_file) + "-nonexistent" get_pkg_version(non_existent_file, "pandas") + def test_get_pkg_version_deprecated(self, requirements_file): + with warns( + KedroDeprecationWarning, + match=r"\`get_pkg_version\(\)\` has been deprecated", + ): + _ = get_pkg_version(requirements_file, "pandas") + def test_clean_pycache(self, tmp_path, mocker): """Test `clean_pycache` utility function""" source = Path(tmp_path)