File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -178,7 +178,8 @@ def from_name(cls, name):
178178 metadata cannot be found.
179179 """
180180 for resolver in cls ._discover_resolvers ():
181- dists = resolver (DistributionFinder .Context (name = name ))
181+ context = DistributionFinder .Context (name = name )
182+ dists = cls ._maybe_bind (resolver , context )
182183 dist = next (dists , None )
183184 if dist is not None :
184185 return dist
@@ -200,10 +201,24 @@ def discover(cls, **kwargs):
200201 raise ValueError ("cannot accept context and kwargs" )
201202 context = context or DistributionFinder .Context (** kwargs )
202203 return itertools .chain .from_iterable (
203- resolver ( context )
204+ cls . _maybe_bind ( resolver , context )
204205 for resolver in cls ._discover_resolvers ()
205206 )
206207
208+ @staticmethod
209+ def _maybe_bind (resolver , context ):
210+ """
211+ Only bind the context to the resolver if as a callable,
212+ the resolver accepts the context parameter.
213+
214+ Workaround for
215+ https://gitlab.com/python-devs/importlib_metadata/issues/86
216+ """
217+ try : # pragma: nocover
218+ return resolver (context )
219+ except TypeError : # pragma: nocover
220+ return resolver (name = context .name , path = context .path )
221+
207222 @staticmethod
208223 def at (path ):
209224 """Return a Distribution for the indicated metadata path
Original file line number Diff line number Diff line change 22 importlib_metadata NEWS
33=========================
44
5+ 0.23
6+ ====
7+ * Added a compatibility shim to prevent failures on beta releases
8+ of Python before the signature changed to accept the
9+ "context" parameter on find_distributions. This workaround
10+ will have a limited lifespan, not to extend beyond release of
11+ Python 3.8 final.
12+
5130.22
614====
715* Renamed ``package `` parameter to ``distribution_name ``
You can’t perform that action at this time.
0 commit comments