Skip to content

Commit

Permalink
Migrate from pkg_resources to importlib.metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Apr 9, 2022
1 parent a551c93 commit bb3a36a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
15 changes: 4 additions & 11 deletions decorator_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,17 @@
"""

from importlib import import_module
from os import path

import pkg_resources
from django.urls import URLPattern, URLResolver, include
from django.utils.functional import cached_property


def _extract_version(package_name):
try:
# if package is installed
version = pkg_resources.get_distribution(package_name).version
except pkg_resources.DistributionNotFound:
# if not installed, so we must be in source, with ``setup.cfg`` available
from setuptools.config import read_configuration
_conf = read_configuration(path.join(
path.dirname(__file__), 'setup.cfg')
)
version = _conf['metadata']['version']
import importlib.metadata as importlib_metadata
except ImportError: # for python < 3.8
import importlib_metadata
version = importlib_metadata.version(package_name)

return tuple(int(part) for part in version.split('.') if part.isnumeric())

Expand Down
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ classifiers =
[options]
zip_safe = True
py_modules = decorator_include
install_requires = Django>=2.2
install_requires =
Django>=2.2
importlib_metadata; python_version<"3.8"
python_requires = >=3.6

[flake8]
Expand Down

0 comments on commit bb3a36a

Please sign in to comment.