Commit 92a553d3 authored by Jason R. Coombs's avatar Jason R. Coombs

Add EntryPoint.resolve and deprecate most usage of EntryPoint.load. Removed EntryPoint._load.

parent 7fa87f2f
......@@ -2,6 +2,20 @@
CHANGES
=======
----
11.3
----
* Expose ``EntryPoint.resolve`` in place of EntryPoint._load, implementing the
simple, non-requiring load. Deprecated all uses of ``EntryPoint._load``
except for calling with no parameters, which is just a shortcut for
``ep.require(); ep.resolve();``.
Apps currently invoking ``ep.load(require=False)`` should instead do the
following if wanting to avoid the deprecating warning::
getattr(ep, "resolve", lambda: ep.load(require=False))()
----
11.2
----
......
......@@ -2294,19 +2294,25 @@ class EntryPoint(object):
def __repr__(self):
return "EntryPoint.parse(%r)" % str(self)
def load(self, require=True, env=None, installer=None):
if require:
self.require(env, installer)
else:
def load(self, require=True, *args, **kwargs):
"""
Require packages for this EntryPoint, then resolve it.
"""
if not require or args or kwargs:
warnings.warn(
"`require` parameter is deprecated. Use "
"EntryPoint._load instead.",
"Parameters to load are deprecated. Call .resolve and "
".require separately.",
DeprecationWarning,
stacklevel=2,
)
return self._load()
if require:
self.require(*args, **kwargs)
return self.resolve()
def _load(self):
def resolve(self):
"""
Resolve the entry point from its module and attrs.
"""
module = __import__(self.module_name, fromlist=['__name__'], level=0)
try:
return functools.reduce(getattr, self.attrs, module)
......
......@@ -172,4 +172,4 @@ class test(Command):
if val is None:
return
parsed = EntryPoint.parse("x=" + val)
return parsed._load()()
return parsed.resolve()()
......@@ -434,7 +434,7 @@ class Distribution(_Distribution):
for ep in pkg_resources.iter_entry_points('distutils.commands'):
if ep.name not in self.cmdclass:
# don't require extras as the commands won't be invoked
cmdclass = ep._load()
cmdclass = ep.resolve()
self.cmdclass[ep.name] = cmdclass
return _Distribution.print_commands(self)
......
......@@ -415,5 +415,5 @@ def test_default_revctrl():
"""
ep_def = 'svn_cvs = setuptools.command.sdist:_default_revctrl'
ep = pkg_resources.EntryPoint.parse(ep_def)
res = ep._load()
res = ep.resolve()
assert hasattr(res, '__iter__')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment