1919
2020import setuptools
2121from 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 ,
2536)
2637from distutils import log
2738from distutils .errors import DistutilsError
4051EXTENSIONS = ".tar.gz .tar.bz2 .tar .zip .tgz" .split ()
4152
4253__all__ = [
43- 'PackageIndex' , 'distros_for_url' , 'parse_bdist_wininst' ,
54+ 'PackageIndex' ,
55+ 'distros_for_url' ,
56+ 'parse_bdist_wininst' ,
4457 'interpret_distro_name' ,
4558]
4659
4760_SOCKET_TIMEOUT = 15
4861
4962_tmpl = "setuptools/{setuptools.__version__} Python-urllib/{py_major}"
5063user_agent = _tmpl .format (
51- py_major = '{}.{}' .format (* sys .version_info ), setuptools = setuptools )
64+ py_major = '{}.{}' .format (* sys .version_info ), setuptools = setuptools
65+ )
5266
5367
5468def parse_requirement_arg (spec ):
@@ -120,13 +134,15 @@ def distros_for_location(location, basename, metadata=None):
120134 wheel = Wheel (basename )
121135 if not wheel .is_compatible ():
122136 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+ ]
130146 if basename .endswith ('.exe' ):
131147 win_base , py_ver , platform = parse_bdist_wininst (basename )
132148 if win_base is not None :
@@ -137,7 +153,7 @@ def distros_for_location(location, basename, metadata=None):
137153 #
138154 for ext in EXTENSIONS :
139155 if basename .endswith (ext ):
140- basename = basename [:- len (ext )]
156+ basename = basename [: - len (ext )]
141157 return interpret_distro_name (location , basename , metadata )
142158 return [] # no extension matched
143159
@@ -150,8 +166,7 @@ def distros_for_filename(filename, metadata=None):
150166
151167
152168def 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
155170):
156171 """Generate alternative interpretations of a source distro name
157172
@@ -178,9 +193,13 @@ def interpret_distro_name(
178193
179194 for p in range (1 , len (parts ) + 1 ):
180195 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 ,
184203 )
185204
186205
@@ -282,11 +301,16 @@ class PackageIndex(Environment):
282301 """A distribution index that scans web pages for download URLs"""
283302
284303 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
287311 ):
288312 super ().__init__ (* args , ** kw )
289- self .index_url = index_url + "/" [: not index_url .endswith ('/' )]
313+ self .index_url = index_url + "/" [: not index_url .endswith ('/' )]
290314 self .scanned_urls = {}
291315 self .fetched_urls = {}
292316 self .package_pages = {}
@@ -379,7 +403,8 @@ def url_ok(self, url, fatal=False):
379403 return True
380404 msg = (
381405 "\n Note: Bypassing %s (disallowed host; see "
382- "http://bit.ly/2hrImnY for details).\n " )
406+ "http://bit.ly/2hrImnY for details).\n "
407+ )
383408 if fatal :
384409 raise DistutilsError (msg % url )
385410 else :
@@ -417,9 +442,7 @@ def _scan(self, link):
417442 if not link .startswith (self .index_url ):
418443 return NO_MATCH_SENTINEL
419444
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 ('/' )))
423446 if len (parts ) != 2 or '#' in parts [1 ]:
424447 return NO_MATCH_SENTINEL
425448
@@ -461,16 +484,15 @@ def process_index(self, url, page):
461484 def need_version_info (self , url ):
462485 self .scan_all (
463486 "Page at %s links to .py file(s) without version info; an index "
464- "scan is required." , url
487+ "scan is required." ,
488+ url ,
465489 )
466490
467491 def scan_all (self , msg = None , * args ):
468492 if self .index_url not in self .fetched_urls :
469493 if msg :
470494 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)" )
474496 self .scan_url (self .index_url )
475497
476498 def find_packages (self , requirement ):
@@ -501,9 +523,7 @@ def check_hash(self, checker, filename, tfp):
501523 """
502524 checker is a ContentChecker
503525 """
504- checker .report (
505- self .debug ,
506- "Validating %%s checksum for %s" % filename )
526+ checker .report (self .debug , "Validating %%s checksum for %s" % filename )
507527 if not checker .is_valid ():
508528 tfp .close ()
509529 os .unlink (filename )
@@ -540,7 +560,8 @@ def not_found_in_index(self, requirement):
540560 else : # no distros seen for this name, might be misspelled
541561 meth , msg = (
542562 self .warn ,
543- "Couldn't find index page for %r (maybe misspelled?)" )
563+ "Couldn't find index page for %r (maybe misspelled?)" ,
564+ )
544565 meth (msg , requirement .unsafe_name )
545566 self .scan_all ()
546567
@@ -579,8 +600,14 @@ def download(self, spec, tmpdir):
579600 return getattr (self .fetch_distribution (spec , tmpdir ), 'location' , None )
580601
581602 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+ ):
584611 """Obtain a distribution suitable for fulfilling `requirement`
585612
586613 `requirement` must be a ``pkg_resources.Requirement`` instance.
@@ -612,15 +639,13 @@ def find(req, env=None):
612639 if dist .precedence == DEVELOP_DIST and not develop_ok :
613640 if dist not in skipped :
614641 self .warn (
615- "Skipping development or system egg: %s" , dist ,
642+ "Skipping development or system egg: %s" ,
643+ dist ,
616644 )
617645 skipped [dist ] = 1
618646 continue
619647
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 )
624649 if test :
625650 loc = self .download (dist .location , tmpdir )
626651 dist .download_location = loc
@@ -669,10 +694,15 @@ def fetch(self, requirement, tmpdir, force_scan=False, source=False):
669694
670695 def gen_setup (self , filename , fragment , tmpdir ):
671696 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+ )
676706
677707 if len (dists ) == 1 : # unambiguous ``#egg`` fragment
678708 basename = os .path .basename (filename )
@@ -689,8 +719,9 @@ def gen_setup(self, filename, fragment, tmpdir):
689719 "from setuptools import setup\n "
690720 "setup(name=%r, version=%r, py_modules=[%r])\n "
691721 % (
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 ],
694725 )
695726 )
696727 return filename
@@ -766,23 +797,22 @@ def open_url(self, url, warning=None): # noqa: C901 # is too complex (12)
766797 if warning :
767798 self .warn (warning , v .reason )
768799 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
771803 except http .client .BadStatusLine as v :
772804 if warning :
773805 self .warn (warning , v .line )
774806 else :
775807 raise DistutilsError (
776808 '%s returned a bad status line. The server might be '
777- 'down, %s' %
778- (url , v .line )
809+ 'down, %s' % (url , v .line )
779810 ) from v
780811 except (http .client .HTTPException , socket .error ) as v :
781812 if warning :
782813 self .warn (warning , v )
783814 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
786816
787817 def _download_url (self , scheme , url , tmpdir ):
788818 # Determine download filename
@@ -887,10 +917,13 @@ def _download_git(self, url, filename):
887917
888918 if rev is not None :
889919 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+ )
894927
895928 return filename
896929
@@ -903,10 +936,13 @@ def _download_hg(self, url, filename):
903936
904937 if rev is not None :
905938 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+ )
910946
911947 return filename
912948
@@ -1010,7 +1046,8 @@ def __init__(self):
10101046 @property
10111047 def creds_by_repository (self ):
10121048 sections_with_repositories = [
1013- section for section in self .sections ()
1049+ section
1050+ for section in self .sections ()
10141051 if self .get (section , 'repository' ).strip ()
10151052 ]
10161053
@@ -1114,8 +1151,8 @@ def local_open(url):
11141151 files .append ('<a href="{name}">{name}</a>' .format (name = f ))
11151152 else :
11161153 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+ )
11191156 body = tmpl .format (url = url , files = '\n ' .join (files ))
11201157 status , message = 200 , "OK"
11211158 else :
0 commit comments