Skip to content

Commit

Permalink
&toandaominh1997 [BUG] fix dependency checkers in case of multiple di…
Browse files Browse the repository at this point in the history
…stributions available in environment, e.g., on databricks (#352)

Mirror bugfix of sktime/sktime#6986 in
preparation of deduplication refactor.
  • Loading branch information
fkiraly authored Aug 17, 2024
1 parent f960194 commit bfb1b8f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions skbase/utils/dependencies/_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sys
import warnings
from functools import lru_cache
from importlib.metadata import distributions
from inspect import isclass

from packaging.markers import InvalidMarker, Marker
Expand Down Expand Up @@ -186,9 +185,19 @@ def _get_installed_packages_private():
Same as _get_installed_packages, but internal to avoid mutating the lru_cache
by accident.
"""
from importlib.metadata import distributions, version

dists = distributions()
packages = {dist.metadata["Name"]: dist.version for dist in dists}
return packages
package_names = {dist.metadata["Name"] for dist in dists}
package_versions = {pkg_name: version(pkg_name) for pkg_name in package_names}
# developer note:
# we cannot just use distributions naively,
# because the same top level package name may appear *twice*,
# e.g., in a situation where a virtual env overrides a base env,
# such as in deployment environments like databricks.
# the "version" contract ensures we always get the version that corresponds
# to the importable distribution, i.e., the top one in the sys.path.
return package_versions


def _get_installed_packages():
Expand Down

0 comments on commit bfb1b8f

Please sign in to comment.