This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
support pip 7, where 'use_wheel' doesn't exist #94
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ | |
from collections import defaultdict | ||
from functools import wraps | ||
from hashlib import sha256 | ||
from itertools import chain | ||
from itertools import chain, count, islice | ||
from linecache import getline | ||
import mimetypes | ||
from optparse import OptionParser | ||
|
@@ -104,6 +104,13 @@ def iter(self, ret, *args, **kwargs): | |
|
||
DownloadProgressBar = DownloadProgressSpinner = NullProgressBar | ||
|
||
try: | ||
from pip.index import FormatControl # noqa | ||
format_control_arg = 'format_control' | ||
PIP_COUNTS_COMMENTS = False | ||
except ImportError: | ||
format_control_arg = 'use_wheel' # pre-7 | ||
PIP_COUNTS_COMMENTS = True | ||
|
||
__version__ = 2, 4, 1 | ||
|
||
|
@@ -217,6 +224,8 @@ def requirement_args(argv, want_paths=False, want_other=False): | |
if want_other: | ||
yield arg | ||
|
||
# any line that is a comment or just whitespace | ||
IGNORED_LINE_RE = re.compile(r'^(\s*#.*)?\s*$') | ||
|
||
HASH_COMMENT_RE = re.compile( | ||
r""" | ||
|
@@ -311,7 +320,7 @@ def package_finder(argv): | |
# Carry over PackageFinder kwargs that have [about] the same names as | ||
# options attr names: | ||
possible_options = [ | ||
'find_links', 'use_wheel', 'allow_external', 'allow_unverified', | ||
'find_links', format_control_arg, 'allow_external', 'allow_unverified', | ||
'allow_all_external', ('allow_all_prereleases', 'pre'), | ||
'process_dependency_links'] | ||
kwargs = {} | ||
|
@@ -447,23 +456,31 @@ def _path_and_line(self): | |
def _expected_hashes(self): | ||
"""Return a list of known-good hashes for this package.""" | ||
|
||
def hashes_above(path, line_number): | ||
"""Yield hashes from contiguous comment lines before line | ||
``line_number``. | ||
def get_hash_lists(path): | ||
"""Yield lists of hashes appearing between non-comment lines. | ||
|
||
The lists will be in order of appearance and, for each non-empty | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really clever! |
||
list, their place in the results will coincide with that of the | ||
line number of the corresponding result from `parse_requirements` | ||
(which changed in pip 7.0 to not count comments). | ||
""" | ||
for line_number in xrange(line_number - 1, 0, -1): | ||
line = getline(path, line_number) | ||
match = HASH_COMMENT_RE.match(line) | ||
if match: | ||
yield match.groupdict()['hash'] | ||
elif not line.lstrip().startswith('#'): | ||
# If we hit a non-comment line, abort | ||
hashes = [] | ||
for lineno in count(1): | ||
line = getline(path, lineno) | ||
if line == '': | ||
break | ||
|
||
hashes = list(hashes_above(*self._path_and_line())) | ||
hashes.reverse() # because we read them backwards | ||
return hashes | ||
match = HASH_COMMENT_RE.match(line) | ||
if match: # accumulate hashes seen so far | ||
hashes.append(match.groupdict()['hash']) | ||
if not IGNORED_LINE_RE.match(line): | ||
yield hashes # report hashes seen so far | ||
hashes = [] | ||
elif PIP_COUNTS_COMMENTS: | ||
# comment, count as normal req, but no hashes | ||
yield [] | ||
|
||
path, line_number = self._path_and_line() | ||
return next(islice(get_hash_lists(path), line_number-1, None)) | ||
|
||
def _download(self, link): | ||
"""Download a file, and return its name within my temp dir. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose these should both be CONSTANTS, or neither should.