Skip to content

Commit

Permalink
Merge pull request #177 from jwodder/importlib-metadata
Browse files Browse the repository at this point in the history
Replace pkg_resource with importlib.metadata
  • Loading branch information
yarikoptic committed Apr 13, 2021
2 parents a5cd404 + c292f32 commit 076c56f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 8 additions & 4 deletions duecredit/versions.py
Expand Up @@ -9,12 +9,16 @@
"""Module to help maintain a registry of versions for external modules etc
"""
import sys
import pkg_resources
from os import linesep
from six import string_types

from distutils.version import StrictVersion, LooseVersion

try:
from importlib.metadata import version as metadata_version
except ImportError:
from importlib_metadata import version as metadata_version


# To depict an unknown version, which can't be compared by mistake etc
class UnknownVersion:
Expand Down Expand Up @@ -57,15 +61,15 @@ def _deduce_version(klass, module):
version = ".".join(str(x) for x in version)

if not version:
# Try pkg_resources
# Try importlib.metadata
# module name might be different, and I found no way to
# deduce it for citeproc which comes from "citeproc-py"
# distribution
modname = module.__name__
try:
version = pkg_resources.get_distribution(
version = metadata_version(
{'citeproc': 'citeproc-py'}.get(modname, modname)
).version
)
except Exception:
pass # oh well - no luck either

Expand Down
7 changes: 6 additions & 1 deletion setup.py
Expand Up @@ -90,7 +90,12 @@ def find_packages(path, prefix):
version=__version__,
packages=list(find_packages([PACKAGE_ABSPATH], PACKAGE)),
scripts=[],
install_requires=['requests', 'citeproc-py>=0.4', 'six'],
install_requires=[
'requests',
'citeproc-py>=0.4',
'six',
'importlib-metadata; python_version<"3.8"',
],
extras_require={
'tests': [
'pytest',
Expand Down

0 comments on commit 076c56f

Please sign in to comment.