mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
replace pkg_resources.load_entry_point
pkg_resources is deprecated. Use the corresponding importlib.metadata interface instead. Use the stdlib version on python >= 3.8 and use the importlib_metadata backport on older versions.
This commit is contained in:
parent
b8d6b1e97c
commit
7f480daf07
@ -22,7 +22,10 @@ import time
|
||||
import traceback
|
||||
import warnings
|
||||
|
||||
import pkg_resources
|
||||
try:
|
||||
import importlib.metadata as importlib_metadata
|
||||
except ImportError:
|
||||
import importlib_metadata
|
||||
|
||||
from gunicorn.errors import AppImportError
|
||||
from gunicorn.workers import SUPPORTED_WORKERS
|
||||
@ -54,6 +57,15 @@ except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
def load_entry_point(distribution, group, name):
|
||||
dist_obj = importlib_metadata.distribution(distribution)
|
||||
eps = [ep for ep in dist_obj.entry_points
|
||||
if ep.group == group and ep.name == name]
|
||||
if not eps:
|
||||
raise ImportError("Entry point %r not found" % ((group, name),))
|
||||
return eps[0].load()
|
||||
|
||||
|
||||
def load_class(uri, default="gunicorn.workers.sync.SyncWorker",
|
||||
section="gunicorn.workers"):
|
||||
if inspect.isclass(uri):
|
||||
@ -68,7 +80,7 @@ def load_class(uri, default="gunicorn.workers.sync.SyncWorker",
|
||||
name = default
|
||||
|
||||
try:
|
||||
return pkg_resources.load_entry_point(dist, section, name)
|
||||
return load_entry_point(dist, section, name)
|
||||
except Exception:
|
||||
exc = traceback.format_exc()
|
||||
msg = "class uri %r invalid or not found: \n\n[%s]"
|
||||
@ -85,7 +97,7 @@ def load_class(uri, default="gunicorn.workers.sync.SyncWorker",
|
||||
break
|
||||
|
||||
try:
|
||||
return pkg_resources.load_entry_point(
|
||||
return load_entry_point(
|
||||
"gunicorn", section, uri
|
||||
)
|
||||
except Exception:
|
||||
|
||||
6
setup.py
6
setup.py
@ -70,11 +70,7 @@ class PyTestCommand(TestCommand):
|
||||
|
||||
|
||||
install_requires = [
|
||||
# We depend on functioning pkg_resources.working_set.add_entry() and
|
||||
# pkg_resources.load_entry_point(). These both work as of 3.0 which
|
||||
# is the first version to support Python 3.4 which we require as a
|
||||
# floor.
|
||||
'setuptools>=3.0',
|
||||
'importlib_metadata; python_version<"3.8"',
|
||||
'packaging',
|
||||
]
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user