Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Synchronize dependency checker with sktime counterpart #490

Merged
merged 5 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@
"maintenance"
]
},
{
"login": "meraldoantonio",
"name": "Meraldo Antonio",
"avatar_url": "https://avatars.githubusercontent.com/u/37468543?v=4",
"profile": "https://github.com/meraldoantonio",
"contributions": [
"bug"
]
},
{
"login": "szepeviktor",
"name": "Viktor Szépe",
Expand Down
37 changes: 21 additions & 16 deletions skpro/utils/_maint/_show_versions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3 -u
# License: BSD 3 clause

"""Utility methods to print system info for debugging.

adapted from :func:`sklearn.show_versions`
adapted from
:func: `sklearn.show_versions`
"""

__author__ = ["mloning", "fkiraly"]
Expand All @@ -15,8 +15,7 @@


def _get_sys_info():
"""
System information.
"""System information.

Return
------
Expand All @@ -37,28 +36,33 @@ def _get_sys_info():
# dependencies to print versions of, by default
DEFAULT_DEPS_TO_SHOW = [
"pip",
"skpro",
"skbase",
"sktime",
"sklearn",
"skbase",
"numpy",
"scipy",
"pandas",
"matplotlib",
"joblib",
"numba",
"tabulate",
"uncertainties",
"statsmodels",
"pmdarima",
"statsforecast",
"tsfresh",
"tslearn",
"torch",
"tensorflow",
"tensorflow_probability",
]


def _get_deps_info(deps=None):
"""
Overview of the installed version of main dependencies.
"""Overview of the installed version of main dependencies.

Parameters
----------
deps : optional, list of strings with import names
if None, behaves as deps = ["skpro"]
if None, behaves as deps = ["sktime"]

Returns
-------
Expand All @@ -68,10 +72,10 @@ def _get_deps_info(deps=None):
of the import as present in the current python environment
"""
if deps is None:
deps = ["skpro"]
deps = ["sktime"]

def get_version(module):
return module.__version__
return getattr(module, "__version__", None)

deps_info = {}

Expand All @@ -81,16 +85,17 @@ def get_version(module):
mod = sys.modules[modname]
else:
mod = importlib.import_module(modname)
ver = get_version(mod)
deps_info[modname] = ver
except ImportError:
deps_info[modname] = None
else:
ver = get_version(mod)
deps_info[modname] = ver

return deps_info


def show_versions():
"""Print python version, OS version, skpro version, selected dependency versions.
"""Print python version, OS version, sktime version, selected dependency versions.

Pretty prints:

Expand Down
31 changes: 28 additions & 3 deletions skpro/utils/_maint/tests/test_show_versions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Tests for the show_versions utility."""
import pathlib
import uuid

from skpro.utils._maint._show_versions import (
DEFAULT_DEPS_TO_SHOW,
Expand All @@ -18,16 +20,39 @@ def test_deps_info():
"""Test that _get_deps_info returns package/version dict as per contract."""
deps_info = _get_deps_info()
assert isinstance(deps_info, dict)
assert set(deps_info.keys()) == {"skpro"}
assert set(deps_info.keys()) == {"sktime"}

deps_info_default = _get_deps_info(DEFAULT_DEPS_TO_SHOW)
assert isinstance(deps_info_default, dict)
assert set(deps_info_default.keys()) == set(DEFAULT_DEPS_TO_SHOW)

PKG_IMPORT_ALIAS = {"scikit-learn": "sklearn", "scikit-base": "skbase"}
KEY_ALIAS = {"sklearn": "scikit-learn", "skbase": "scikit-base"}

for key in DEFAULT_DEPS_TO_SHOW:
key_is_available = _check_soft_dependencies(key, severity="none")
pkg_name = KEY_ALIAS.get(key, key)
key_is_available = _check_soft_dependencies(
pkg_name,
severity="none",
package_import_alias=PKG_IMPORT_ALIAS,
)
assert (deps_info_default[key] is None) != key_is_available
if key_is_available:
assert _check_soft_dependencies(f"{key}=={deps_info_default[key]}")
assert _check_soft_dependencies(
f"{pkg_name}=={deps_info_default[key]}",
package_import_alias=PKG_IMPORT_ALIAS,
)
deps_single_key = _get_deps_info([key])
assert set(deps_single_key.keys()) == {key}


def test_deps_info_deps_missing_package_present_directory():
"""Test that _get_deps_info does not fail if a dependency is missing."""
dummy_package_name = uuid.uuid4().hex

dummy_folder_path = pathlib.Path(dummy_package_name)
dummy_folder_path.mkdir()

assert _get_deps_info([dummy_package_name]) == {dummy_package_name: None}

dummy_folder_path.rmdir()
Loading