3
3
4
4
import logging
5
5
import cgi
6
+ import itertools
6
7
import sys
7
8
import os
8
9
import re
@@ -138,7 +139,8 @@ def add_dependency_links(self, links):
138
139
)
139
140
self .dependency_links .extend (links )
140
141
141
- def _sort_locations (self , locations ):
142
+ @staticmethod
143
+ def _sort_locations (locations , expand_dir = False ):
142
144
"""
143
145
Sort locations into "files" (archives) and "urls", and return
144
146
a pair of lists (files,urls)
@@ -158,19 +160,19 @@ def sort_path(path):
158
160
159
161
is_local_path = os .path .exists (url )
160
162
is_file_url = url .startswith ('file:' )
161
- is_find_link = url in self .find_links
162
163
163
164
if is_local_path or is_file_url :
164
165
if is_local_path :
165
166
path = url
166
167
else :
167
168
path = url_to_path (url )
168
- if is_find_link and os .path .isdir (path ):
169
- path = os .path .realpath (path )
170
- for item in os .listdir (path ):
171
- sort_path (os .path .join (path , item ))
172
- elif is_file_url and os .path .isdir (path ):
173
- urls .append (url )
169
+ if os .path .isdir (path ):
170
+ if expand_dir :
171
+ path = os .path .realpath (path )
172
+ for item in os .listdir (path ):
173
+ sort_path (os .path .join (path , item ))
174
+ elif is_file_url :
175
+ urls .append (url )
174
176
elif os .path .isfile (path ):
175
177
sort_path (path )
176
178
else :
@@ -342,31 +344,33 @@ def _find_all_versions(self, project_name):
342
344
See _link_package_versions for details on which files are accepted
343
345
"""
344
346
index_locations = self ._get_index_urls_locations (project_name )
345
- file_locations , url_locations = self ._sort_locations (index_locations )
346
- fl_file_loc , fl_url_loc = self ._sort_locations (self .find_links )
347
- file_locations .extend (fl_file_loc )
348
- url_locations .extend (fl_url_loc )
349
-
350
- _flocations , _ulocations = self ._sort_locations (self .dependency_links )
351
- file_locations .extend (_flocations )
347
+ index_file_loc , index_url_loc = self ._sort_locations (index_locations )
348
+ fl_file_loc , fl_url_loc = self ._sort_locations (
349
+ self .find_links , expand_dir = True )
350
+ dep_file_loc , dep_url_loc = self ._sort_locations (self .dependency_links )
351
+
352
+ file_locations = (
353
+ Link (url ) for url in itertools .chain (
354
+ index_file_loc , fl_file_loc , dep_file_loc )
355
+ )
352
356
353
357
# We trust every url that the user has given us whether it was given
354
358
# via --index-url or --find-links
355
- locations = [Link (url , trusted = True ) for url in url_locations ]
356
-
357
359
# We explicitly do not trust links that came from dependency_links
358
- locations .extend ([Link (url ) for url in _ulocations ])
359
-
360
360
# We want to filter out any thing which does not have a secure origin.
361
- locations = [
362
- l for l in locations
363
- if self ._validate_secure_origin (logger , l )
361
+ url_locations = [
362
+ link for link in itertools .chain (
363
+ (Link (url , trusted = True ) for url in index_url_loc ),
364
+ (Link (url , trusted = True ) for url in fl_url_loc ),
365
+ (Link (url ) for url in dep_url_loc ),
366
+ )
367
+ if self ._validate_secure_origin (logger , link )
364
368
]
365
369
366
370
logger .debug ('%d location(s) to search for versions of %s:' ,
367
- len (locations ), project_name )
371
+ len (url_locations ), project_name )
368
372
369
- for location in locations :
373
+ for location in url_locations :
370
374
logger .debug ('* %s' , location )
371
375
372
376
find_links_versions = list (self ._package_versions (
@@ -376,7 +380,7 @@ def _find_all_versions(self, project_name):
376
380
))
377
381
378
382
page_versions = []
379
- for page in self ._get_pages (locations , project_name ):
383
+ for page in self ._get_pages (url_locations , project_name ):
380
384
logger .debug ('Analyzing links from page %s' , page .url )
381
385
with indent_log ():
382
386
page_versions .extend (
@@ -396,7 +400,7 @@ def _find_all_versions(self, project_name):
396
400
397
401
file_versions = list (
398
402
self ._package_versions (
399
- ( Link ( url ) for url in file_locations ) ,
403
+ file_locations ,
400
404
project_name .lower ()
401
405
)
402
406
)
0 commit comments