@@ -104,12 +104,23 @@ def sort_path(path):
104
104
return files , urls
105
105
106
106
def find_requirement (self , req , upgrade ):
107
+
108
+ def mkurl_pypi_url (url ):
109
+ loc = posixpath .join (url , url_name )
110
+ # For maximum compatibility with easy_install, ensure the path
111
+ # ends in a trailing slash. Although this isn't in the spec
112
+ # (and PyPI can handle it without the slash) some other index
113
+ # implementations might break if they relied on easy_install's behavior.
114
+ if not loc .endswith ('/' ):
115
+ loc = loc + '/'
116
+ return loc
117
+
107
118
url_name = req .url_name
108
119
# Only check main index if index URL is given:
109
120
main_index_url = None
110
121
if self .index_urls :
111
122
# Check that we have the url_name correctly spelled:
112
- main_index_url = Link (posixpath . join (self .index_urls [0 ], url_name ))
123
+ main_index_url = Link (mkurl_pypi_url (self .index_urls [0 ]))
113
124
# This will also cache the page, so it's okay that we get it again later:
114
125
page = self ._get_page (main_index_url , req )
115
126
if page is None :
@@ -119,15 +130,6 @@ def find_requirement(self, req, upgrade):
119
130
# adding more index URLs from requirements files
120
131
all_index_urls = self .index_urls + self .mirror_urls
121
132
122
- def mkurl_pypi_url (url ):
123
- loc = posixpath .join (url , url_name )
124
- # For maximum compatibility with easy_install, ensure the path
125
- # ends in a trailing slash. Although this isn't in the spec
126
- # (and PyPI can handle it without the slash) some other index
127
- # implementations might break if they relied on easy_install's behavior.
128
- if not loc .endswith ('/' ):
129
- loc = loc + '/'
130
- return loc
131
133
if url_name is not None :
132
134
locations = [
133
135
mkurl_pypi_url (url )
@@ -167,21 +169,23 @@ def mkurl_pypi_url(url):
167
169
if not found_versions and not page_versions and not dependency_versions and not file_versions :
168
170
logger .fatal ('Could not find any downloads that satisfy the requirement %s' % req )
169
171
raise DistributionNotFound ('No distributions at all found for %s' % req )
172
+ installed_version = []
170
173
if req .satisfied_by is not None :
171
- found_versions . append (( req .satisfied_by .parsed_version , InfLink , req .satisfied_by .version ))
174
+ installed_version = [( req .satisfied_by .parsed_version , InfLink , req .satisfied_by .version )]
172
175
if file_versions :
173
176
file_versions .sort (reverse = True )
174
177
logger .info ('Local files found: %s' % ', ' .join ([url_to_path (link .url ) for parsed , link , version in file_versions ]))
175
- found_versions = file_versions + found_versions
176
- all_versions = found_versions + page_versions + dependency_versions
178
+ #this is an intentional priority ordering
179
+ all_versions = installed_version + file_versions + found_versions + page_versions + dependency_versions
177
180
applicable_versions = []
178
181
for (parsed_version , link , version ) in all_versions :
179
182
if version not in req .req :
180
183
logger .info ("Ignoring link %s, version %s doesn't match %s"
181
184
% (link , version , ',' .join (['' .join (s ) for s in req .req .specs ])))
182
185
continue
183
186
applicable_versions .append ((parsed_version , link , version ))
184
- applicable_versions = sorted (applicable_versions , reverse = True )
187
+ #bring the latest version to the front, but maintains the priority ordering as secondary
188
+ applicable_versions = sorted (applicable_versions , key = lambda v : v [0 ], reverse = True )
185
189
existing_applicable = bool ([link for parsed_version , link , version in applicable_versions if link is InfLink ])
186
190
if not upgrade and existing_applicable :
187
191
if applicable_versions [0 ][1 ] is InfLink :
@@ -193,7 +197,7 @@ def mkurl_pypi_url(url):
193
197
return None
194
198
if not applicable_versions :
195
199
logger .fatal ('Could not find a version that satisfies the requirement %s (from versions: %s)'
196
- % (req , ', ' .join ([version for parsed_version , link , version in found_versions ])))
200
+ % (req , ', ' .join ([version for parsed_version , link , version in all_versions ])))
197
201
raise DistributionNotFound ('No distributions matching the version for %s' % req )
198
202
if applicable_versions [0 ][1 ] is InfLink :
199
203
# We have an existing version, and its the best version
@@ -227,7 +231,7 @@ def _find_url_name(self, index_url, url_name, req):
227
231
228
232
def _get_pages (self , locations , req ):
229
233
"""Yields (page, page_url) from the given locations, skipping
230
- locations that have errors, and adding download/ homepage links"""
234
+ locations that have errors, and adding homepage links"""
231
235
pending_queue = Queue ()
232
236
for location in locations :
233
237
pending_queue .put (location )
@@ -258,7 +262,7 @@ def _get_queued_page(self, req, pending_queue, done, seen):
258
262
if page is None :
259
263
continue
260
264
done .append (page )
261
- for link in page .rel_links ():
265
+ for link in page .rel_links (rels = ( 'homepage' ,) ):
262
266
pending_queue .put (link )
263
267
264
268
_egg_fragment_re = re .compile (r'#egg=([^&]*)' )
@@ -568,8 +572,8 @@ def links(self):
568
572
url = self .clean_link (urlparse .urljoin (self .base_url , url ))
569
573
yield Link (url , self )
570
574
571
- def rel_links (self ):
572
- for url in self .explicit_rel_links ():
575
+ def rel_links (self , rels = ( 'homepage' , 'download' ) ):
576
+ for url in self .explicit_rel_links (rels ):
573
577
yield url
574
578
for url in self .scraped_rel_links ():
575
579
yield url
@@ -703,7 +707,7 @@ def show_url(self):
703
707
return posixpath .basename (self .url .split ('#' , 1 )[0 ].split ('?' , 1 )[0 ])
704
708
705
709
#An "Infinite Link" that compares greater than other links
706
- InfLink = Link (Inf )
710
+ InfLink = Link (Inf ) #this object is not currently used as a sortable
707
711
708
712
709
713
def get_requirement_from_url (url ):
0 commit comments