From 06a42556ac999ae46c9b3e42b22369f8cda50bfa Mon Sep 17 00:00:00 2001 From: Luigi Giugliano Date: Wed, 18 Dec 2024 15:42:10 +0100 Subject: [PATCH 01/11] Added parameter for working with 'rc' versions --- skbase/utils/dependencies/_dependencies.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/skbase/utils/dependencies/_dependencies.py b/skbase/utils/dependencies/_dependencies.py index 2e1fda15..f64c0394 100644 --- a/skbase/utils/dependencies/_dependencies.py +++ b/skbase/utils/dependencies/_dependencies.py @@ -236,7 +236,9 @@ def _get_pkg_version(package_name): return pkg_env_version -def _check_python_version(obj, package=None, msg=None, severity="error"): +def _check_python_version( + obj, package=None, msg=None, severity="error", prereleases=True +): """Check if system python version is compatible with requirements of obj. Parameters @@ -259,6 +261,9 @@ def _check_python_version(obj, package=None, msg=None, severity="error"): * "none" - does not raise exception or warning function returns False if one of packages is not installed, otherwise True + prereleases: str, default = True + if include prereleases while checking, if False will not include prereleases + Returns ------- compatible : bool, whether obj is compatible with system python version @@ -276,7 +281,7 @@ def _check_python_version(obj, package=None, msg=None, severity="error"): return True try: - est_specifier = SpecifierSet(est_specifier_tag) + est_specifier = SpecifierSet(est_specifier_tag, prereleases=prereleases) except InvalidSpecifier: msg_version = ( f"wrong format for python_version tag, " From 86a0cc6de711c146c3ffeca5d0d80e9a7866fb0e Mon Sep 17 00:00:00 2001 From: Luigi Giugliano Date: Wed, 18 Dec 2024 15:46:25 +0100 Subject: [PATCH 02/11] Added to all-contributors --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 6826ad2c..da919087 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -103,6 +103,15 @@ "contributions": [ "maintenance" ] + }, + { + "login": "Abelarm", + "name": "Luigi Giugliano", + "avatar_url": "https://avatars.githubusercontent.com/u/6976921?v=4", + "profile": "https://github.com/Abelarm", + "contributions": [ + "code" + ] } ], "projectName": "skbase", From c1ffaf82e4dabe91d4c89720d13c0143cc8f632b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20Kir=C3=A1ly?= Date: Thu, 19 Dec 2024 22:51:35 +0100 Subject: [PATCH 03/11] docstring --- skbase/utils/dependencies/_dependencies.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/skbase/utils/dependencies/_dependencies.py b/skbase/utils/dependencies/_dependencies.py index f64c0394..2424b277 100644 --- a/skbase/utils/dependencies/_dependencies.py +++ b/skbase/utils/dependencies/_dependencies.py @@ -262,7 +262,10 @@ def _check_python_version( function returns False if one of packages is not installed, otherwise True prereleases: str, default = True - if include prereleases while checking, if False will not include prereleases + If True, allows prerelease versions to be considered compatible. + If False, always considers prerelease versions as incompatible, i.e., always + raises error, warning, or returns False, if the system python version is a + prerelease. Returns ------- From 64b62639d60883007dcb66487d21faab8ac837a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20Kir=C3=A1ly?= Date: Thu, 19 Dec 2024 22:53:48 +0100 Subject: [PATCH 04/11] Update _dependencies.py --- skbase/utils/dependencies/_dependencies.py | 1 + 1 file changed, 1 insertion(+) diff --git a/skbase/utils/dependencies/_dependencies.py b/skbase/utils/dependencies/_dependencies.py index 2424b277..0a6349c5 100644 --- a/skbase/utils/dependencies/_dependencies.py +++ b/skbase/utils/dependencies/_dependencies.py @@ -262,6 +262,7 @@ def _check_python_version( function returns False if one of packages is not installed, otherwise True prereleases: str, default = True + Whether prerelease versions are considered compatible. If True, allows prerelease versions to be considered compatible. If False, always considers prerelease versions as incompatible, i.e., always raises error, warning, or returns False, if the system python version is a From 81dbc314e9734cd9cfed8e8176d49cf1a080c77e Mon Sep 17 00:00:00 2001 From: Luigi Giugliano Date: Fri, 20 Dec 2024 12:13:08 +0100 Subject: [PATCH 05/11] minor change to mirror code from sktime --- skbase/utils/dependencies/_dependencies.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/skbase/utils/dependencies/_dependencies.py b/skbase/utils/dependencies/_dependencies.py index 0a6349c5..cf71888a 100644 --- a/skbase/utils/dependencies/_dependencies.py +++ b/skbase/utils/dependencies/_dependencies.py @@ -312,6 +312,9 @@ def _check_python_version( f" but system python version is {sys.version}." ) + if "rc" in sys_version: + msg += " This is due to the release candidate status of your system Python." + if package is not None: msg += ( f" This is due to python version requirements of the {package} package." From 2f9d3ed87d4ae261fa04f5935fc74a7e05dc282d Mon Sep 17 00:00:00 2001 From: Luigi Giugliano Date: Sat, 21 Dec 2024 13:36:51 +0100 Subject: [PATCH 06/11] Added test for --- .../tests/test_check_dependencies.py | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/skbase/utils/dependencies/tests/test_check_dependencies.py b/skbase/utils/dependencies/tests/test_check_dependencies.py index 53f1353f..ac0d297e 100644 --- a/skbase/utils/dependencies/tests/test_check_dependencies.py +++ b/skbase/utils/dependencies/tests/test_check_dependencies.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- """Tests for _check_soft_dependencies utility.""" import pytest +from unittest.mock import patch from packaging.requirements import InvalidRequirement -from skbase.utils.dependencies._dependencies import _check_soft_dependencies +from skbase.utils.dependencies import _check_soft_dependencies, _check_python_version def test_check_soft_deps(): @@ -47,3 +48,53 @@ def test_check_soft_deps(): assert _check_soft_dependencies( ("pytest", "!!numpy<~><>0.1.0"), severity="none" ) + +@patch("sktime.utils.dependencies._dependencies.sys") +@pytest.mark.parametrize( + "mock_release_version, prereleases, expect_exception", + [ + (True, True, False), + (True, False, True), + (False, False, False), + (False, True, False), + ], +) +def test_check_python_version( + mock_sys, mock_release_version, prereleases, expect_exception +): + from skbase.base import BaseObject + + if mock_release_version: + mock_sys.version = "3.8.1rc" + else: + mock_sys.version = "3.8.1" + + class DummyObjectClass(BaseObject): + _tags = { + "python_version": ">=3.7.1", # PEP 440 version specifier, e.g., ">=3.7" + "python_dependencies": None, # PEP 440 dependency strs, e.g., "pandas>=1.0" + "env_marker": None, # PEP 508 environment marker, e.g., "os_name=='posix'" + } + """Define dummy class to test set_tags.""" + + dummy_object_instance = DummyObjectClass() + + try: + _check_python_version(dummy_object_instance, prereleases=prereleases) + except ModuleNotFoundError as exception: + expected_msg = ( + f"{type(dummy_object_instance).__name__} requires python version " + f"to be {dummy_object_instance.get_tags()['python_version']}, " + f"but system python version is {mock_sys.version}. " + "This is due to the release candidate status of your system Python." + ) + + if not expect_exception or not exception.msg == expected_msg: + # Throw Error since exception is not expected or has not the correct message + assert False, ( + "ModuleNotFoundError should be NOT raised by:", + f"\n\t - mock_release_version: {mock_release_version},", + f"\n\t - prereleases: {prereleases},", + f"\nERROR MESSAGE: {exception.msg}", + ) + From e764cdb9ce59dba84b2a948c57de2fba9d45b2c4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 21 Dec 2024 12:37:13 +0000 Subject: [PATCH 07/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- skbase/utils/dependencies/tests/test_check_dependencies.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/skbase/utils/dependencies/tests/test_check_dependencies.py b/skbase/utils/dependencies/tests/test_check_dependencies.py index ac0d297e..f2bd3532 100644 --- a/skbase/utils/dependencies/tests/test_check_dependencies.py +++ b/skbase/utils/dependencies/tests/test_check_dependencies.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- """Tests for _check_soft_dependencies utility.""" -import pytest from unittest.mock import patch + +import pytest from packaging.requirements import InvalidRequirement -from skbase.utils.dependencies import _check_soft_dependencies, _check_python_version +from skbase.utils.dependencies import _check_python_version, _check_soft_dependencies def test_check_soft_deps(): @@ -49,6 +50,7 @@ def test_check_soft_deps(): ("pytest", "!!numpy<~><>0.1.0"), severity="none" ) + @patch("sktime.utils.dependencies._dependencies.sys") @pytest.mark.parametrize( "mock_release_version, prereleases, expect_exception", @@ -97,4 +99,3 @@ class DummyObjectClass(BaseObject): f"\n\t - prereleases: {prereleases},", f"\nERROR MESSAGE: {exception.msg}", ) - From 9eca953d1373367dfc670cf00d48d16d55d7ad63 Mon Sep 17 00:00:00 2001 From: Luigi Giugliano Date: Sat, 21 Dec 2024 13:38:43 +0100 Subject: [PATCH 08/11] Improved assert error --- skbase/utils/dependencies/tests/test_check_dependencies.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skbase/utils/dependencies/tests/test_check_dependencies.py b/skbase/utils/dependencies/tests/test_check_dependencies.py index f2bd3532..c126f685 100644 --- a/skbase/utils/dependencies/tests/test_check_dependencies.py +++ b/skbase/utils/dependencies/tests/test_check_dependencies.py @@ -93,7 +93,7 @@ class DummyObjectClass(BaseObject): if not expect_exception or not exception.msg == expected_msg: # Throw Error since exception is not expected or has not the correct message - assert False, ( + raise AssertionError( "ModuleNotFoundError should be NOT raised by:", f"\n\t - mock_release_version: {mock_release_version},", f"\n\t - prereleases: {prereleases},", From 9792d2645322d5ceaeae9f8fdafcf975fb4e6f45 Mon Sep 17 00:00:00 2001 From: Luigi Giugliano Date: Sat, 21 Dec 2024 13:41:00 +0100 Subject: [PATCH 09/11] Improved assert error, bit pedantic this pre-commit --- skbase/utils/dependencies/tests/test_check_dependencies.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skbase/utils/dependencies/tests/test_check_dependencies.py b/skbase/utils/dependencies/tests/test_check_dependencies.py index c126f685..3bcb4fc0 100644 --- a/skbase/utils/dependencies/tests/test_check_dependencies.py +++ b/skbase/utils/dependencies/tests/test_check_dependencies.py @@ -98,4 +98,4 @@ class DummyObjectClass(BaseObject): f"\n\t - mock_release_version: {mock_release_version},", f"\n\t - prereleases: {prereleases},", f"\nERROR MESSAGE: {exception.msg}", - ) + ) from exception From 5e39683e914201450415447d189a157602ef603f Mon Sep 17 00:00:00 2001 From: Luigi Giugliano Date: Sat, 21 Dec 2024 16:47:22 +0100 Subject: [PATCH 10/11] Aligning with sktime test --- skbase/utils/dependencies/tests/test_check_dependencies.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skbase/utils/dependencies/tests/test_check_dependencies.py b/skbase/utils/dependencies/tests/test_check_dependencies.py index 3bcb4fc0..58bd9aa1 100644 --- a/skbase/utils/dependencies/tests/test_check_dependencies.py +++ b/skbase/utils/dependencies/tests/test_check_dependencies.py @@ -91,7 +91,7 @@ class DummyObjectClass(BaseObject): "This is due to the release candidate status of your system Python." ) - if not expect_exception or not exception.msg == expected_msg: + if not expect_exception or exception.msg != expected_msg: # Throw Error since exception is not expected or has not the correct message raise AssertionError( "ModuleNotFoundError should be NOT raised by:", From b0359c24639f1043a779ae1839433e8152c490b2 Mon Sep 17 00:00:00 2001 From: Luigi Giugliano Date: Thu, 26 Dec 2024 16:30:23 +0100 Subject: [PATCH 11/11] Fixing paste and not edit error --- skbase/utils/dependencies/tests/test_check_dependencies.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skbase/utils/dependencies/tests/test_check_dependencies.py b/skbase/utils/dependencies/tests/test_check_dependencies.py index 58bd9aa1..bbb51737 100644 --- a/skbase/utils/dependencies/tests/test_check_dependencies.py +++ b/skbase/utils/dependencies/tests/test_check_dependencies.py @@ -51,7 +51,7 @@ def test_check_soft_deps(): ) -@patch("sktime.utils.dependencies._dependencies.sys") +@patch("skbase.utils.dependencies._dependencies.sys") @pytest.mark.parametrize( "mock_release_version, prereleases, expect_exception", [