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

[BUG] handles AttributeError in show_versions() when dependency lacks __version__ #5793

Merged
merged 3 commits into from Jan 20, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions sktime/utils/_maint/_show_versions.py
Expand Up @@ -75,7 +75,7 @@ def _get_deps_info(deps=None):
deps = ["sktime"]

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

deps_info = {}

Expand All @@ -85,10 +85,11 @@ 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

Expand Down
14 changes: 14 additions & 0 deletions sktime/utils/_maint/tests/test_show_versions.py
@@ -1,4 +1,6 @@
"""Tests for the show_versions utility."""
import pathlib
import uuid

from sktime.utils._maint._show_versions import (
DEFAULT_DEPS_TO_SHOW,
Expand Down Expand Up @@ -31,3 +33,15 @@ def test_deps_info():
assert _check_soft_dependencies(f"{key}=={deps_info_default[key]}")
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()