Repository: kedro-org/kedro

Issue:
Deprecate (mark for future removal) `get_pkg_version` from the public API
## Context

              @merelcht It didn't change by #3742. 

https://github.com/kedro-org/kedro/blob/a91ccdbecb5541490b5146b6179ab4c621b9ea73/kedro/framework/cli/utils.py#L204-L218

I just check again, this function is not used anywhere in framework, but only tests. (last change is 4 years ago). Maybe at some points it was used for `kedro build-reqs`? I suggest we deprecate this function since it's a public function and move it to test.

_Originally posted by @noklam in https://github.com/kedro-org/kedro/issues/2912#issuecomment-2031643218_

Remove the function from public API and move it to test only.
            

Discussion:

Patch:
diff --git a/RELEASE.md b/RELEASE.md
index b14a51c3..4824c264 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 eda9bc00..2d298bd7 100644
--- a/kedro/framework/cli/utils.py
+++ b/kedro/framework/cli/utils.py
@@ -11,6 +11,7 @@ import sys
 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 click
 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.")


Test patch:
diff --git a/tests/framework/cli/test_cli.py b/tests/framework/cli/test_cli.py
index d147a6a0..857e71a8 100644
--- a/tests/framework/cli/test_cli.py
+++ b/tests/framework/cli/test_cli.py
@@ -6,8 +6,9 @@ from pathlib import Path
 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 @@ class TestCliUtils:
             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)