@@ -128,12 +128,21 @@ class EntryPoint(
128
128
See `the packaging docs on entry points
129
129
<https://packaging.python.org/specifications/entry-points/>`_
130
130
for more information.
131
+
132
+ >>> ep = EntryPoint(
133
+ ... name=None, group=None, value='package.module:attr [extra1, extra2]')
134
+ >>> ep.module
135
+ 'package.module'
136
+ >>> ep.attr
137
+ 'attr'
138
+ >>> ep.extras
139
+ ['extra1', 'extra2']
131
140
"""
132
141
133
142
pattern = re .compile (
134
143
r'(?P<module>[\w.]+)\s*'
135
- r'(:\s*(?P<attr>[\w.]+))? \s*'
136
- r'(?P<extras>\[.*\])? \s*$'
144
+ r'(:\s*(?P<attr>[\w.]+)\s*)? '
145
+ r'(( ?P<extras>\[.*\])\s*)? $'
137
146
)
138
147
"""
139
148
A regular expression describing the syntax for an entry point,
@@ -176,7 +185,7 @@ def attr(self):
176
185
@property
177
186
def extras (self ):
178
187
match = self .pattern .match (self .value )
179
- return list ( re .finditer (r'\w+' , match .group ('extras' ) or '' ) )
188
+ return re .findall (r'\w+' , match .group ('extras' ) or '' )
180
189
181
190
def _for (self , dist ):
182
191
self .dist = dist
@@ -200,6 +209,25 @@ def __reduce__(self):
200
209
)
201
210
202
211
def matches (self , ** params ):
212
+ """
213
+ EntryPoint matches the given parameters.
214
+
215
+ >>> ep = EntryPoint(group='foo', name='bar', value='bing:bong [extra1, extra2]')
216
+ >>> ep.matches(group='foo')
217
+ True
218
+ >>> ep.matches(name='bar', value='bing:bong [extra1, extra2]')
219
+ True
220
+ >>> ep.matches(group='foo', name='other')
221
+ False
222
+ >>> ep.matches()
223
+ True
224
+ >>> ep.matches(extras=['extra1', 'extra2'])
225
+ True
226
+ >>> ep.matches(module='bing')
227
+ True
228
+ >>> ep.matches(attr='bong')
229
+ True
230
+ """
203
231
attrs = (getattr (self , param ) for param in params )
204
232
return all (map (operator .eq , params .values (), attrs ))
205
233
@@ -236,6 +264,8 @@ class DeprecatedList(list):
236
264
1
237
265
"""
238
266
267
+ __slots__ = ()
268
+
239
269
_warn = functools .partial (
240
270
warnings .warn ,
241
271
"EntryPoints list interface is deprecated. Cast to list if needed." ,
@@ -648,7 +678,7 @@ def _read_dist_info_reqs(self):
648
678
649
679
def _read_egg_info_reqs (self ):
650
680
source = self .read_text ('requires.txt' )
651
- return source and self ._deps_from_requires_text (source )
681
+ return None if source is None else self ._deps_from_requires_text (source )
652
682
653
683
@classmethod
654
684
def _deps_from_requires_text (cls , source ):
@@ -669,16 +699,25 @@ def _convert_egg_info_reqs_to_simple_reqs(sections):
669
699
def make_condition (name ):
670
700
return name and f'extra == "{ name } "'
671
701
672
- def parse_condition (section ):
702
+ def quoted_marker (section ):
673
703
section = section or ''
674
704
extra , sep , markers = section .partition (':' )
675
705
if extra and markers :
676
706
markers = f'({ markers } )'
677
707
conditions = list (filter (None , [markers , make_condition (extra )]))
678
708
return '; ' + ' and ' .join (conditions ) if conditions else ''
679
709
710
+ def url_req_space (req ):
711
+ """
712
+ PEP 508 requires a space between the url_spec and the quoted_marker.
713
+ Ref python/importlib_metadata#357.
714
+ """
715
+ # '@' is uniquely indicative of a url_req.
716
+ return ' ' * ('@' in req )
717
+
680
718
for section in sections :
681
- yield section .value + parse_condition (section .name )
719
+ space = url_req_space (section .value )
720
+ yield section .value + space + quoted_marker (section .name )
682
721
683
722
684
723
class DistributionFinder (MetaPathFinder ):
@@ -741,14 +780,13 @@ def __new__(cls, root):
741
780
742
781
def __init__ (self , root ):
743
782
self .root = root
744
- self .base = os .path .basename (self .root ).lower ()
745
783
746
784
def joinpath (self , child ):
747
785
return pathlib .Path (self .root , child )
748
786
749
787
def children (self ):
750
788
with suppress (Exception ):
751
- return os .listdir (self .root or '' )
789
+ return os .listdir (self .root or '. ' )
752
790
with suppress (Exception ):
753
791
return self .zip_children ()
754
792
return []
0 commit comments