@@ -130,10 +130,6 @@ def _from_text(cls, text):
130130 config .read_string (text )
131131 return cls ._from_config (config )
132132
133- @classmethod
134- def _from_text_for (cls , text , dist ):
135- return (ep ._for (dist ) for ep in cls ._from_text (text ))
136-
137133 def _for (self , dist ):
138134 self .dist = dist
139135 return self
@@ -155,35 +151,42 @@ def __reduce__(self):
155151 (self .name , self .value , self .group ),
156152 )
157153
154+ def matches (self , ** params ):
155+ attrs = (getattr (self , param ) for param in params )
156+ return all (map (operator .eq , params .values (), attrs ))
157+
158158
159159class EntryPoints (tuple ):
160160 """
161- An immutable collection of EntryPoint objects, retrievable by name .
161+ An immutable collection of selectable EntryPoint objects.
162162 """
163163
164164 __slots__ = ()
165165
166- def __getitem__ (self , name ) -> EntryPoint :
166+ def __getitem__ (self , name ) -> Union [ EntryPoint , 'EntryPoints' ] :
167167 try :
168- return next (ep for ep in self if ep .name == name )
169- except Exception :
168+ match = next (iter (self .select (name = name )))
169+ return match
170+ except StopIteration :
171+ if name in self .groups :
172+ return self ._group_getitem (name )
170173 raise KeyError (name )
171174
175+ def _group_getitem (self , name ):
176+ """
177+ For backward compatability, supply .__getitem__ for groups.
178+ """
179+ msg = "GroupedEntryPoints.__getitem__ is deprecated for groups. Use select."
180+ warnings .warn (msg , DeprecationWarning )
181+ return self .select (group = name )
182+
183+ def select (self , ** params ):
184+ return EntryPoints (ep for ep in self if ep .matches (** params ))
185+
172186 @property
173187 def names (self ):
174188 return set (ep .name for ep in self )
175189
176-
177- class GroupedEntryPoints (tuple ):
178- """
179- An immutable collection of EntryPoint objects, retrievable by group.
180- """
181-
182- __slots__ = ()
183-
184- def __getitem__ (self , group ) -> EntryPoints :
185- return EntryPoints (ep for ep in self if ep .group == group )
186-
187190 @property
188191 def groups (self ):
189192 return set (ep .group for ep in self )
@@ -193,9 +196,13 @@ def get(self, group, default=None):
193196 For backward compatibility, supply .get
194197 """
195198 is_flake8 = any ('flake8' in str (frame ) for frame in inspect .stack ())
196- msg = "GroupedEntryPoints.get is deprecated. Just use __getitem__ ."
199+ msg = "GroupedEntryPoints.get is deprecated. Use select ."
197200 is_flake8 or warnings .warn (msg , DeprecationWarning )
198- return self [group ] or default
201+ return self .select (group = group ) or default
202+
203+ @classmethod
204+ def _from_text_for (cls , text , dist ):
205+ return cls (ep ._for (dist ) for ep in EntryPoint ._from_text (text ))
199206
200207
201208class PackagePath (pathlib .PurePosixPath ):
@@ -353,8 +360,7 @@ def version(self):
353360
354361 @property
355362 def entry_points (self ):
356- eps = EntryPoint ._from_text_for (self .read_text ('entry_points.txt' ), self )
357- return GroupedEntryPoints (eps )
363+ return EntryPoints ._from_text_for (self .read_text ('entry_points.txt' ), self )
358364
359365 @property
360366 def files (self ):
@@ -687,13 +693,13 @@ def version(distribution_name):
687693 return distribution (distribution_name ).version
688694
689695
690- def entry_points ():
696+ def entry_points (** params ):
691697 """Return EntryPoint objects for all installed packages.
692698
693699 :return: EntryPoint objects for all installed packages.
694700 """
695701 eps = itertools .chain .from_iterable (dist .entry_points for dist in distributions ())
696- return GroupedEntryPoints (eps )
702+ return EntryPoints (eps ). select ( ** params )
697703
698704
699705def files (distribution_name ):
0 commit comments