19
19
20
20
import setuptools
21
21
from pkg_resources import (
22
- CHECKOUT_DIST , Distribution , BINARY_DIST , normalize_path , SOURCE_DIST ,
23
- Environment , find_distributions , safe_name , safe_version ,
24
- to_filename , Requirement , DEVELOP_DIST , EGG_DIST , parse_version ,
22
+ CHECKOUT_DIST ,
23
+ Distribution ,
24
+ BINARY_DIST ,
25
+ normalize_path ,
26
+ SOURCE_DIST ,
27
+ Environment ,
28
+ find_distributions ,
29
+ safe_name ,
30
+ safe_version ,
31
+ to_filename ,
32
+ Requirement ,
33
+ DEVELOP_DIST ,
34
+ EGG_DIST ,
35
+ parse_version ,
25
36
)
26
37
from distutils import log
27
38
from distutils .errors import DistutilsError
40
51
EXTENSIONS = ".tar.gz .tar.bz2 .tar .zip .tgz" .split ()
41
52
42
53
__all__ = [
43
- 'PackageIndex' , 'distros_for_url' , 'parse_bdist_wininst' ,
54
+ 'PackageIndex' ,
55
+ 'distros_for_url' ,
56
+ 'parse_bdist_wininst' ,
44
57
'interpret_distro_name' ,
45
58
]
46
59
47
60
_SOCKET_TIMEOUT = 15
48
61
49
62
_tmpl = "setuptools/{setuptools.__version__} Python-urllib/{py_major}"
50
63
user_agent = _tmpl .format (
51
- py_major = '{}.{}' .format (* sys .version_info ), setuptools = setuptools )
64
+ py_major = '{}.{}' .format (* sys .version_info ), setuptools = setuptools
65
+ )
52
66
53
67
54
68
def parse_requirement_arg (spec ):
@@ -120,13 +134,15 @@ def distros_for_location(location, basename, metadata=None):
120
134
wheel = Wheel (basename )
121
135
if not wheel .is_compatible ():
122
136
return []
123
- return [Distribution (
124
- location = location ,
125
- project_name = wheel .project_name ,
126
- version = wheel .version ,
127
- # Increase priority over eggs.
128
- precedence = EGG_DIST + 1 ,
129
- )]
137
+ return [
138
+ Distribution (
139
+ location = location ,
140
+ project_name = wheel .project_name ,
141
+ version = wheel .version ,
142
+ # Increase priority over eggs.
143
+ precedence = EGG_DIST + 1 ,
144
+ )
145
+ ]
130
146
if basename .endswith ('.exe' ):
131
147
win_base , py_ver , platform = parse_bdist_wininst (basename )
132
148
if win_base is not None :
@@ -137,7 +153,7 @@ def distros_for_location(location, basename, metadata=None):
137
153
#
138
154
for ext in EXTENSIONS :
139
155
if basename .endswith (ext ):
140
- basename = basename [:- len (ext )]
156
+ basename = basename [: - len (ext )]
141
157
return interpret_distro_name (location , basename , metadata )
142
158
return [] # no extension matched
143
159
@@ -150,8 +166,7 @@ def distros_for_filename(filename, metadata=None):
150
166
151
167
152
168
def interpret_distro_name (
153
- location , basename , metadata , py_version = None , precedence = SOURCE_DIST ,
154
- platform = None
169
+ location , basename , metadata , py_version = None , precedence = SOURCE_DIST , platform = None
155
170
):
156
171
"""Generate alternative interpretations of a source distro name
157
172
@@ -178,9 +193,13 @@ def interpret_distro_name(
178
193
179
194
for p in range (1 , len (parts ) + 1 ):
180
195
yield Distribution (
181
- location , metadata , '-' .join (parts [:p ]), '-' .join (parts [p :]),
182
- py_version = py_version , precedence = precedence ,
183
- platform = platform
196
+ location ,
197
+ metadata ,
198
+ '-' .join (parts [:p ]),
199
+ '-' .join (parts [p :]),
200
+ py_version = py_version ,
201
+ precedence = precedence ,
202
+ platform = platform ,
184
203
)
185
204
186
205
@@ -282,11 +301,16 @@ class PackageIndex(Environment):
282
301
"""A distribution index that scans web pages for download URLs"""
283
302
284
303
def __init__ (
285
- self , index_url = "https://pypi.org/simple/" , hosts = ('*' ,),
286
- ca_bundle = None , verify_ssl = True , * args , ** kw
304
+ self ,
305
+ index_url = "https://pypi.org/simple/" ,
306
+ hosts = ('*' ,),
307
+ ca_bundle = None ,
308
+ verify_ssl = True ,
309
+ * args ,
310
+ ** kw
287
311
):
288
312
super ().__init__ (* args , ** kw )
289
- self .index_url = index_url + "/" [: not index_url .endswith ('/' )]
313
+ self .index_url = index_url + "/" [: not index_url .endswith ('/' )]
290
314
self .scanned_urls = {}
291
315
self .fetched_urls = {}
292
316
self .package_pages = {}
@@ -379,7 +403,8 @@ def url_ok(self, url, fatal=False):
379
403
return True
380
404
msg = (
381
405
"\n Note: Bypassing %s (disallowed host; see "
382
- "http://bit.ly/2hrImnY for details).\n " )
406
+ "http://bit.ly/2hrImnY for details).\n "
407
+ )
383
408
if fatal :
384
409
raise DistutilsError (msg % url )
385
410
else :
@@ -417,9 +442,7 @@ def _scan(self, link):
417
442
if not link .startswith (self .index_url ):
418
443
return NO_MATCH_SENTINEL
419
444
420
- parts = list (map (
421
- urllib .parse .unquote , link [len (self .index_url ):].split ('/' )
422
- ))
445
+ parts = list (map (urllib .parse .unquote , link [len (self .index_url ) :].split ('/' )))
423
446
if len (parts ) != 2 or '#' in parts [1 ]:
424
447
return NO_MATCH_SENTINEL
425
448
@@ -461,16 +484,15 @@ def process_index(self, url, page):
461
484
def need_version_info (self , url ):
462
485
self .scan_all (
463
486
"Page at %s links to .py file(s) without version info; an index "
464
- "scan is required." , url
487
+ "scan is required." ,
488
+ url ,
465
489
)
466
490
467
491
def scan_all (self , msg = None , * args ):
468
492
if self .index_url not in self .fetched_urls :
469
493
if msg :
470
494
self .warn (msg , * args )
471
- self .info (
472
- "Scanning index of all packages (this may take a while)"
473
- )
495
+ self .info ("Scanning index of all packages (this may take a while)" )
474
496
self .scan_url (self .index_url )
475
497
476
498
def find_packages (self , requirement ):
@@ -501,9 +523,7 @@ def check_hash(self, checker, filename, tfp):
501
523
"""
502
524
checker is a ContentChecker
503
525
"""
504
- checker .report (
505
- self .debug ,
506
- "Validating %%s checksum for %s" % filename )
526
+ checker .report (self .debug , "Validating %%s checksum for %s" % filename )
507
527
if not checker .is_valid ():
508
528
tfp .close ()
509
529
os .unlink (filename )
@@ -540,7 +560,8 @@ def not_found_in_index(self, requirement):
540
560
else : # no distros seen for this name, might be misspelled
541
561
meth , msg = (
542
562
self .warn ,
543
- "Couldn't find index page for %r (maybe misspelled?)" )
563
+ "Couldn't find index page for %r (maybe misspelled?)" ,
564
+ )
544
565
meth (msg , requirement .unsafe_name )
545
566
self .scan_all ()
546
567
@@ -579,8 +600,14 @@ def download(self, spec, tmpdir):
579
600
return getattr (self .fetch_distribution (spec , tmpdir ), 'location' , None )
580
601
581
602
def fetch_distribution ( # noqa: C901 # is too complex (14) # FIXME
582
- self , requirement , tmpdir , force_scan = False , source = False ,
583
- develop_ok = False , local_index = None ):
603
+ self ,
604
+ requirement ,
605
+ tmpdir ,
606
+ force_scan = False ,
607
+ source = False ,
608
+ develop_ok = False ,
609
+ local_index = None ,
610
+ ):
584
611
"""Obtain a distribution suitable for fulfilling `requirement`
585
612
586
613
`requirement` must be a ``pkg_resources.Requirement`` instance.
@@ -612,15 +639,13 @@ def find(req, env=None):
612
639
if dist .precedence == DEVELOP_DIST and not develop_ok :
613
640
if dist not in skipped :
614
641
self .warn (
615
- "Skipping development or system egg: %s" , dist ,
642
+ "Skipping development or system egg: %s" ,
643
+ dist ,
616
644
)
617
645
skipped [dist ] = 1
618
646
continue
619
647
620
- test = (
621
- dist in req
622
- and (dist .precedence <= SOURCE_DIST or not source )
623
- )
648
+ test = dist in req and (dist .precedence <= SOURCE_DIST or not source )
624
649
if test :
625
650
loc = self .download (dist .location , tmpdir )
626
651
dist .download_location = loc
@@ -669,10 +694,15 @@ def fetch(self, requirement, tmpdir, force_scan=False, source=False):
669
694
670
695
def gen_setup (self , filename , fragment , tmpdir ):
671
696
match = EGG_FRAGMENT .match (fragment )
672
- dists = match and [
673
- d for d in
674
- interpret_distro_name (filename , match .group (1 ), None ) if d .version
675
- ] or []
697
+ dists = (
698
+ match
699
+ and [
700
+ d
701
+ for d in interpret_distro_name (filename , match .group (1 ), None )
702
+ if d .version
703
+ ]
704
+ or []
705
+ )
676
706
677
707
if len (dists ) == 1 : # unambiguous ``#egg`` fragment
678
708
basename = os .path .basename (filename )
@@ -689,8 +719,9 @@ def gen_setup(self, filename, fragment, tmpdir):
689
719
"from setuptools import setup\n "
690
720
"setup(name=%r, version=%r, py_modules=[%r])\n "
691
721
% (
692
- dists [0 ].project_name , dists [0 ].version ,
693
- os .path .splitext (basename )[0 ]
722
+ dists [0 ].project_name ,
723
+ dists [0 ].version ,
724
+ os .path .splitext (basename )[0 ],
694
725
)
695
726
)
696
727
return filename
@@ -766,23 +797,22 @@ def open_url(self, url, warning=None): # noqa: C901 # is too complex (12)
766
797
if warning :
767
798
self .warn (warning , v .reason )
768
799
else :
769
- raise DistutilsError ("Download error for %s: %s"
770
- % (url , v .reason )) from v
800
+ raise DistutilsError (
801
+ "Download error for %s: %s" % (url , v .reason )
802
+ ) from v
771
803
except http .client .BadStatusLine as v :
772
804
if warning :
773
805
self .warn (warning , v .line )
774
806
else :
775
807
raise DistutilsError (
776
808
'%s returned a bad status line. The server might be '
777
- 'down, %s' %
778
- (url , v .line )
809
+ 'down, %s' % (url , v .line )
779
810
) from v
780
811
except (http .client .HTTPException , socket .error ) as v :
781
812
if warning :
782
813
self .warn (warning , v )
783
814
else :
784
- raise DistutilsError ("Download error for %s: %s"
785
- % (url , v )) from v
815
+ raise DistutilsError ("Download error for %s: %s" % (url , v )) from v
786
816
787
817
def _download_url (self , scheme , url , tmpdir ):
788
818
# Determine download filename
@@ -887,10 +917,13 @@ def _download_git(self, url, filename):
887
917
888
918
if rev is not None :
889
919
self .info ("Checking out %s" , rev )
890
- os .system ("git -C %s checkout --quiet %s" % (
891
- filename ,
892
- rev ,
893
- ))
920
+ os .system (
921
+ "git -C %s checkout --quiet %s"
922
+ % (
923
+ filename ,
924
+ rev ,
925
+ )
926
+ )
894
927
895
928
return filename
896
929
@@ -903,10 +936,13 @@ def _download_hg(self, url, filename):
903
936
904
937
if rev is not None :
905
938
self .info ("Updating to %s" , rev )
906
- os .system ("hg --cwd %s up -C -r %s -q" % (
907
- filename ,
908
- rev ,
909
- ))
939
+ os .system (
940
+ "hg --cwd %s up -C -r %s -q"
941
+ % (
942
+ filename ,
943
+ rev ,
944
+ )
945
+ )
910
946
911
947
return filename
912
948
@@ -1010,7 +1046,8 @@ def __init__(self):
1010
1046
@property
1011
1047
def creds_by_repository (self ):
1012
1048
sections_with_repositories = [
1013
- section for section in self .sections ()
1049
+ section
1050
+ for section in self .sections ()
1014
1051
if self .get (section , 'repository' ).strip ()
1015
1052
]
1016
1053
@@ -1114,8 +1151,8 @@ def local_open(url):
1114
1151
files .append ('<a href="{name}">{name}</a>' .format (name = f ))
1115
1152
else :
1116
1153
tmpl = (
1117
- "<html><head><title>{url}</title>"
1118
- "</head><body>{files}</body></html>" )
1154
+ "<html><head><title>{url}</title>" "</head><body>{files}</body></html>"
1155
+ )
1119
1156
body = tmpl .format (url = url , files = '\n ' .join (files ))
1120
1157
status , message = 200 , "OK"
1121
1158
else :
0 commit comments