Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

support pip 7, where 'use_wheel' doesn't exist #94

Merged
merged 3 commits into from
Dec 3, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 33 additions & 16 deletions peep.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Copy link
Owner

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.

PIP_COUNTS_COMMENTS = False
except ImportError:
format_control_arg = 'use_wheel' # pre-7
PIP_COUNTS_COMMENTS = True

__version__ = 2, 4, 1

Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The 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.
Expand Down