MAINT pypy compat for sklearn.show_versions
@@ -7,7 +7,6 @@ adapted from :func:`pandas.show_versions`
import platform
import sys
-from importlib.metadata import version, PackageNotFoundError
from ..utils.fixes import threadpool_info
from .. import __version__
@@ -63,6 +62,28 @@ def _get_deps_info():
"sklearn": __version__,
}
+ if sys.version_info < (3, 8):
+ # Backwards compatibility with Python < 3.8, primarily for PyPy.
+ # TODO: remove once PyPy 3.8 is available on conda-forge and
+ # therefore on our CI.
+ # https://github.com/conda-forge/conda-forge-pinning-feedstock/issues/2089
+ try:
+ from pkg_resources import get_distribution, DistributionNotFound
+
+ for modname in deps:
+ try:
+ deps_info[modname] = get_distribution(modname).version
+ except DistributionNotFound:
+ deps_info[modname] = None
+
+ except ImportError:
+ # Setuptools not installed
+ for modname in deps:
+ deps_info[modname] = None
+
+ else:
+ from importlib.metadata import version, PackageNotFoundError
+
for modname in deps:
try:
deps_info[modname] = version(modname)
