20
20
from . import DistlibException , resources
21
21
from .compat import StringIO
22
22
from .version import get_scheme , UnsupportedVersionError
23
- from .metadata import (Metadata , METADATA_FILENAME , WHEEL_METADATA_FILENAME ,
24
- LEGACY_METADATA_FILENAME )
25
- from .util import (parse_requirement , cached_property , parse_name_and_version ,
26
- read_exports , write_exports , CSVReader , CSVWriter )
23
+ from .metadata import (Metadata , METADATA_FILENAME , WHEEL_METADATA_FILENAME , LEGACY_METADATA_FILENAME )
24
+ from .util import (parse_requirement , cached_property , parse_name_and_version , read_exports , write_exports , CSVReader ,
25
+ CSVWriter )
27
26
28
27
__all__ = [
29
- 'Distribution' , 'BaseInstalledDistribution' , 'InstalledDistribution' ,
30
- 'EggInfoDistribution' , 'DistributionPath'
28
+ 'Distribution' , 'BaseInstalledDistribution' , 'InstalledDistribution' , 'EggInfoDistribution' , 'DistributionPath'
31
29
]
32
30
33
31
logger = logging .getLogger (__name__ )
34
32
35
33
EXPORTS_FILENAME = 'pydist-exports.json'
36
34
COMMANDS_FILENAME = 'pydist-commands.json'
37
35
38
- DIST_FILES = ('INSTALLER' , METADATA_FILENAME , 'RECORD' , 'REQUESTED' ,
39
- 'RESOURCES' , EXPORTS_FILENAME , 'SHARED' )
36
+ DIST_FILES = ('INSTALLER' , METADATA_FILENAME , 'RECORD' , 'REQUESTED' , 'RESOURCES' , EXPORTS_FILENAME , 'SHARED' )
40
37
41
38
DISTINFO_EXT = '.dist-info'
42
39
@@ -134,29 +131,21 @@ def _yield_distributions(self):
134
131
continue
135
132
try :
136
133
if self ._include_dist and entry .endswith (DISTINFO_EXT ):
137
- possible_filenames = [
138
- METADATA_FILENAME , WHEEL_METADATA_FILENAME ,
139
- LEGACY_METADATA_FILENAME
140
- ]
134
+ possible_filenames = [METADATA_FILENAME , WHEEL_METADATA_FILENAME , LEGACY_METADATA_FILENAME ]
141
135
for metadata_filename in possible_filenames :
142
- metadata_path = posixpath .join (
143
- entry , metadata_filename )
136
+ metadata_path = posixpath .join (entry , metadata_filename )
144
137
pydist = finder .find (metadata_path )
145
138
if pydist :
146
139
break
147
140
else :
148
141
continue
149
142
150
143
with contextlib .closing (pydist .as_stream ()) as stream :
151
- metadata = Metadata (fileobj = stream ,
152
- scheme = 'legacy' )
144
+ metadata = Metadata (fileobj = stream , scheme = 'legacy' )
153
145
logger .debug ('Found %s' , r .path )
154
146
seen .add (r .path )
155
- yield new_dist_class (r .path ,
156
- metadata = metadata ,
157
- env = self )
158
- elif self ._include_egg and entry .endswith (
159
- ('.egg-info' , '.egg' )):
147
+ yield new_dist_class (r .path , metadata = metadata , env = self )
148
+ elif self ._include_egg and entry .endswith (('.egg-info' , '.egg' )):
160
149
logger .debug ('Found %s' , r .path )
161
150
seen .add (r .path )
162
151
yield old_dist_class (r .path , self )
@@ -274,8 +263,7 @@ def provides_distribution(self, name, version=None):
274
263
try :
275
264
matcher = self ._scheme .matcher ('%s (%s)' % (name , version ))
276
265
except ValueError :
277
- raise DistlibException ('invalid name or version: %r, %r' %
278
- (name , version ))
266
+ raise DistlibException ('invalid name or version: %r, %r' % (name , version ))
279
267
280
268
for dist in self .get_distributions ():
281
269
# We hit a problem on Travis where enum34 was installed and doesn't
@@ -390,10 +378,8 @@ def provides(self):
390
378
def _get_requirements (self , req_attr ):
391
379
md = self .metadata
392
380
reqts = getattr (md , req_attr )
393
- logger .debug ('%s: got requirements %r from metadata: %r' , self .name ,
394
- req_attr , reqts )
395
- return set (
396
- md .get_requirements (reqts , extras = self .extras , env = self .context ))
381
+ logger .debug ('%s: got requirements %r from metadata: %r' , self .name , req_attr , reqts )
382
+ return set (md .get_requirements (reqts , extras = self .extras , env = self .context ))
397
383
398
384
@property
399
385
def run_requires (self ):
@@ -469,8 +455,7 @@ def __eq__(self, other):
469
455
if type (other ) is not type (self ):
470
456
result = False
471
457
else :
472
- result = (self .name == other .name and self .version == other .version
473
- and self .source_url == other .source_url )
458
+ result = (self .name == other .name and self .version == other .version and self .source_url == other .source_url )
474
459
return result
475
460
476
461
def __hash__ (self ):
@@ -561,8 +546,7 @@ def __init__(self, path, metadata=None, env=None):
561
546
if r is None :
562
547
r = finder .find (LEGACY_METADATA_FILENAME )
563
548
if r is None :
564
- raise ValueError ('no %s found in %s' %
565
- (METADATA_FILENAME , path ))
549
+ raise ValueError ('no %s found in %s' % (METADATA_FILENAME , path ))
566
550
with contextlib .closing (r .as_stream ()) as stream :
567
551
metadata = Metadata (fileobj = stream , scheme = 'legacy' )
568
552
@@ -580,8 +564,7 @@ def __init__(self, path, metadata=None, env=None):
580
564
self .modules = data .splitlines ()
581
565
582
566
def __repr__ (self ):
583
- return '<InstalledDistribution %r %s at %r>' % (
584
- self .name , self .version , self .path )
567
+ return '<InstalledDistribution %r %s at %r>' % (self .name , self .version , self .path )
585
568
586
569
def __str__ (self ):
587
570
return "%s %s" % (self .name , self .version )
@@ -703,8 +686,7 @@ def write_installed_files(self, paths, prefix, dry_run=False):
703
686
size = '%d' % os .path .getsize (path )
704
687
with open (path , 'rb' ) as fp :
705
688
hash_value = self .get_hash (fp .read ())
706
- if path .startswith (base ) or (base_under_prefix
707
- and path .startswith (prefix )):
689
+ if path .startswith (base ) or (base_under_prefix and path .startswith (prefix )):
708
690
path = os .path .relpath (path , base )
709
691
writer .writerow ((path , hash_value , size ))
710
692
@@ -746,8 +728,7 @@ def check_installed_files(self):
746
728
with open (path , 'rb' ) as f :
747
729
actual_hash = self .get_hash (f .read (), hasher )
748
730
if actual_hash != hash_value :
749
- mismatches .append (
750
- (path , 'hash' , hash_value , actual_hash ))
731
+ mismatches .append ((path , 'hash' , hash_value , actual_hash ))
751
732
return mismatches
752
733
753
734
@cached_property
@@ -829,9 +810,8 @@ def get_distinfo_file(self, path):
829
810
# it's an absolute path?
830
811
distinfo_dirname , path = path .split (os .sep )[- 2 :]
831
812
if distinfo_dirname != self .path .split (os .sep )[- 1 ]:
832
- raise DistlibException (
833
- 'dist-info file %r does not belong to the %r %s '
834
- 'distribution' % (path , self .name , self .version ))
813
+ raise DistlibException ('dist-info file %r does not belong to the %r %s '
814
+ 'distribution' % (path , self .name , self .version ))
835
815
836
816
# The file must be relative
837
817
if path not in DIST_FILES :
@@ -857,8 +837,7 @@ def list_distinfo_files(self):
857
837
yield path
858
838
859
839
def __eq__ (self , other ):
860
- return (isinstance (other , InstalledDistribution )
861
- and self .path == other .path )
840
+ return (isinstance (other , InstalledDistribution ) and self .path == other .path )
862
841
863
842
# See http://docs.python.org/reference/datamodel#object.__hash__
864
843
__hash__ = object .__hash__
@@ -911,8 +890,7 @@ def parse_requires_data(data):
911
890
if not line : # pragma: no cover
912
891
continue
913
892
if line .startswith ('[' ): # pragma: no cover
914
- logger .warning (
915
- 'Unexpected line: quitting requirement scan: %r' , line )
893
+ logger .warning ('Unexpected line: quitting requirement scan: %r' , line )
916
894
break
917
895
r = parse_requirement (line )
918
896
if not r : # pragma: no cover
@@ -954,13 +932,11 @@ def parse_requires_path(req_path):
954
932
else :
955
933
# FIXME handle the case where zipfile is not available
956
934
zipf = zipimport .zipimporter (path )
957
- fileobj = StringIO (
958
- zipf .get_data ('EGG-INFO/PKG-INFO' ).decode ('utf8' ))
935
+ fileobj = StringIO (zipf .get_data ('EGG-INFO/PKG-INFO' ).decode ('utf8' ))
959
936
metadata = Metadata (fileobj = fileobj , scheme = 'legacy' )
960
937
try :
961
938
data = zipf .get_data ('EGG-INFO/requires.txt' )
962
- tl_data = zipf .get_data ('EGG-INFO/top_level.txt' ).decode (
963
- 'utf-8' )
939
+ tl_data = zipf .get_data ('EGG-INFO/top_level.txt' ).decode ('utf-8' )
964
940
requires = parse_requires_data (data .decode ('utf-8' ))
965
941
except IOError :
966
942
requires = None
@@ -990,8 +966,7 @@ def parse_requires_path(req_path):
990
966
return metadata
991
967
992
968
def __repr__ (self ):
993
- return '<EggInfoDistribution %r %s at %r>' % (self .name , self .version ,
994
- self .path )
969
+ return '<EggInfoDistribution %r %s at %r>' % (self .name , self .version , self .path )
995
970
996
971
def __str__ (self ):
997
972
return "%s %s" % (self .name , self .version )
@@ -1083,8 +1058,7 @@ def list_distinfo_files(self, absolute=False):
1083
1058
yield line
1084
1059
1085
1060
def __eq__ (self , other ):
1086
- return (isinstance (other , EggInfoDistribution )
1087
- and self .path == other .path )
1061
+ return (isinstance (other , EggInfoDistribution ) and self .path == other .path )
1088
1062
1089
1063
# See http://docs.python.org/reference/datamodel#object.__hash__
1090
1064
__hash__ = object .__hash__
@@ -1184,8 +1158,7 @@ def to_dot(self, f, skip_disconnected=True):
1184
1158
disconnected .append (dist )
1185
1159
for other , label in adjs :
1186
1160
if label is not None :
1187
- f .write ('"%s" -> "%s" [label="%s"]\n ' %
1188
- (dist .name , other .name , label ))
1161
+ f .write ('"%s" -> "%s" [label="%s"]\n ' % (dist .name , other .name , label ))
1189
1162
else :
1190
1163
f .write ('"%s" -> "%s"\n ' % (dist .name , other .name ))
1191
1164
if not skip_disconnected and len (disconnected ) > 0 :
@@ -1225,8 +1198,7 @@ def topological_sort(self):
1225
1198
# Remove from the adjacency list of others
1226
1199
for k , v in alist .items ():
1227
1200
alist [k ] = [(d , r ) for d , r in v if d not in to_remove ]
1228
- logger .debug ('Moving to result: %s' ,
1229
- ['%s (%s)' % (d .name , d .version ) for d in to_remove ])
1201
+ logger .debug ('Moving to result: %s' , ['%s (%s)' % (d .name , d .version ) for d in to_remove ])
1230
1202
result .extend (to_remove )
1231
1203
return result , list (alist .keys ())
1232
1204
@@ -1261,15 +1233,13 @@ def make_graph(dists, scheme='default'):
1261
1233
1262
1234
# now make the edges
1263
1235
for dist in dists :
1264
- requires = (dist .run_requires | dist .meta_requires
1265
- | dist .build_requires | dist .dev_requires )
1236
+ requires = (dist .run_requires | dist .meta_requires | dist .build_requires | dist .dev_requires )
1266
1237
for req in requires :
1267
1238
try :
1268
1239
matcher = scheme .matcher (req )
1269
1240
except UnsupportedVersionError :
1270
1241
# XXX compat-mode if cannot read the version
1271
- logger .warning ('could not read version %r - using name only' ,
1272
- req )
1242
+ logger .warning ('could not read version %r - using name only' , req )
1273
1243
name = req .split ()[0 ]
1274
1244
matcher = scheme .matcher (name )
1275
1245
0 commit comments