mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Merge pull request #2963 from gotmax23/load_entry
replace pkg_resources.load_entry_point
This commit is contained in:
commit
59bbcdc2d5
1
THANKS
1
THANKS
@ -168,6 +168,7 @@ Stephen DiCato <Locker537@gmail.com>
|
||||
Stephen Holsapple <sholsapp@gmail.com>
|
||||
Steven Cummings <estebistec@gmail.com>
|
||||
Sébastien Fievet <zyegfryed@gmail.com>
|
||||
Tal Einat <532281+taleinat@users.noreply.github.com>
|
||||
Talha Malik <talham7391@hotmail.com>
|
||||
TedWantsMore <TedWantsMore@gmx.com>
|
||||
Teko012 <112829523+Teko012@users.noreply.github.com>
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -11,7 +11,7 @@ try:
|
||||
except ImportError:
|
||||
raise RuntimeError("eventlet worker requires eventlet 0.24.1 or higher")
|
||||
else:
|
||||
from pkg_resources import parse_version
|
||||
from packaging.version import parse as parse_version
|
||||
if parse_version(eventlet.__version__) < parse_version('0.24.1'):
|
||||
raise RuntimeError("eventlet worker requires eventlet 0.24.1 or higher")
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ try:
|
||||
except ImportError:
|
||||
raise RuntimeError("gevent worker requires gevent 1.4 or higher")
|
||||
else:
|
||||
from pkg_resources import parse_version
|
||||
from packaging.version import parse as parse_version
|
||||
if parse_version(gevent.__version__) < parse_version('1.4'):
|
||||
raise RuntimeError("gevent worker requires gevent 1.4 or higher")
|
||||
|
||||
|
||||
7
setup.py
7
setup.py
@ -71,11 +71,8 @@ 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',
|
||||
]
|
||||
|
||||
extras_require = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user