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:
One question here, we tend to do the breaking change later in `develop` to avoid the code diverge too much. At the same time should we add the `deprecated` warnings earlier in 0.19 to inform user?

This is not important for this particular issue, because I think no one use it (hopefully), but it is a valid question for what should we do in general?
> should we add the deprecated warnings earlier in 0.19 to inform user?

Yes
Do we need a subticket for deprecation? Or this is ready to go in backlog
grooming.

On Thu, 11 Apr 2024, 15:32 Juan Luis Cano Rodríguez, <
***@***.***> wrote:

> should we add the deprecated warnings earlier in 0.19 to inform user?
>
> Yes
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/kedro-org/kedro/issues/3789#issuecomment-2049834401>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AELAWL6RQQZNPW2IXZXHCFDY42NJXAVCNFSM6AAAAABF4VKBCOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBZHAZTINBQGE>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>

I'd say let's rename this ticket to "Deprecate `get_pkg_version`" and groom it
Actually the tests are obsoleted and we should remove it altogether `class TestCliUtils` in `test_cli.py`. 
Funny bit of insight found in the source code of `kedro-mlflow`:

```
            # if it is a local relative path, make it absolute
            # .resolve() does not work well on windows
            # .absolute is undocumented and have known bugs
            # Path.cwd() / uri is the recommend way by core developpers.
            # See : https://discuss.python.org/t/pathlib-absolute-vs-resolve/2573/6
```

Not sure how up to date it is though (the thread is from 2019).



Patch:
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.")


Test patch:
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)