Skip to content

Commit

Permalink
REF: Use importlib.metadata.version in show_versions for python deps (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 authored Sep 9, 2022
1 parent c59fa54 commit 1799a5e
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions pyproj/_show_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
adapted from :func:`sklearn.utils._show_versions`
which was adapted from :func:`pandas.show_versions`
"""
import importlib
import importlib.metadata
import platform
import sys

Expand Down Expand Up @@ -85,24 +85,11 @@ def _get_deps_info():

def get_version(module):
try:
return module.__version__
except AttributeError:
return module.version
return importlib.metadata.version(module)
except importlib.metadata.PackageNotFoundError:
return None

deps_info = {}

for modname in deps:
try:
if modname in sys.modules:
mod = sys.modules[modname]
else:
mod = importlib.import_module(modname)
ver = get_version(mod)
deps_info[modname] = ver
except ImportError:
deps_info[modname] = None

return deps_info
return {dep: get_version(dep) for dep in deps}


def _print_info_dict(info_dict):
Expand Down

0 comments on commit 1799a5e

Please sign in to comment.