Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from pkg_resources to importlib.metadata #90

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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