Browse files

Support requirements that start with '-e'

If a requirements file contains a VCS repository specified with -e,
and it also specifies a revision number, confirm that the revisions
match.

For example:

-e git://github.com/jcrocholl/pep8.git@bb20999aefc394fb826371764146bf61d8e572e2#egg=pep8-dev
  • Loading branch information...
1 parent 79e7c59 commit c37ea85a42d1b0811c3f30503dd0d553e32c1a20 @lorin lorin committed Jul 12, 2012
Showing with 38 additions and 2 deletions.
  1. +38 −2 src/piplint/__init__.py
View
40 src/piplint/__init__.py
@@ -20,14 +20,50 @@ def check_requirements(requirement_files, strict=False):
about the missing dependency.
"""
version_re = re.compile(r'^([^<>=\s#]+)\s*(>=|>|<|<=|==)?\s*([^<>=\s#]+)?(?:\s*#.*)?$')
+ checkout_re = re.compile(r'[#@]')
def parse_package_line(line):
try:
+ if line.startswith('-e'):
+ return parse_checkout_line(line)
package, compare, version = version_re.split(line)[1:-1]
except ValueError:
raise ValueError("Unknown package line format: %r" % line)
return (package, compare or None, parse_version(version) if version else None, line)
+ def parse_checkout_line(whole_line):
+ """
+ parse a line that starts with '-e'
+
+ e.g.,
+ -e git://github.com/jcrocholl/pep8.git@bb20999aefc394fb826371764146bf61d8e572e2#egg=pep8-dev
+ """
+ # Snip off the '-e' and any leading whitespace
+ line = whole_line[2:].lstrip()
+
+ # Check if there is a revision specified
+ if '@' in line:
+ (url, rev, eggname) = checkout_re.split(line)
+ return (url, '==', rev, line)
+ else:
+ (url, eggname) = line.split('#')
+ return (url, None, None, line)
+
+ def is_requirements_line(line):
+ """
+ line is a valid requirement in requirements file or pip freeze output
+ """
+ if not line:
+ return False
+ if line.startswith('#'):
+ return False
+ if line.startswith('-e'):
+ return True
+ if line.startswith('-'):
+ return False
+ return True
+
+
def valid_version(version, compare, r_version):
if not all([compare, version]):
return True
@@ -50,7 +86,7 @@ def valid_version(version, compare, r_version):
freeze = Popen(['pip freeze'], stdout=PIPE, shell=True)
for line in freeze.communicate()[0].splitlines():
line = line.strip()
- if not line or line.startswith('-'):
+ if not is_requirements_line(line):
unknown_reqs.add(line)
continue
frozen_reqs.append(parse_package_line(line))
@@ -59,7 +95,7 @@ def valid_version(version, compare, r_version):
with open(fname) as fp:
for line in fp:
line = line.strip()
- if not line or line.startswith('-') or line.startswith('#'):
+ if not is_requirements_line(line):
continue
listed_reqs.append(parse_package_line(line))

0 comments on commit c37ea85

Please sign in to comment.