Skip to content

Commit

Permalink
Add deprecation warning to get_pkg_version (#3947)
Browse files Browse the repository at this point in the history
* Add deprecation warning to get_pkg_version

Signed-off-by: Merel Theisen <[email protected]>
  • Loading branch information
merelcht authored Jun 12, 2024
1 parent 25e8f49 commit 7963b61
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions kedro/framework/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.")
Expand Down
10 changes: 9 additions & 1 deletion tests/framework/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7963b61

Please sign in to comment.