summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Smith <qwcode@gmail.com>2015-10-08 15:25:51 -0700
committerMarcus Smith <qwcode@gmail.com>2015-10-08 15:25:51 -0700
commitb58d2c9f34d869db96fc1f47e43039ef576f300f (patch)
treef3413a3d58eb131d13375dab09063177e7dca3a2
parent49290789461d1e43c0106e19d8b55501f1180315 (diff)
downloadpip-b58d2c9f34d869db96fc1f47e43039ef576f300f.tar.gz
process line continuations first (but with some special handling for comments)
-rw-r--r--pip/req/req_file.py11
-rw-r--r--tests/unit/test_req_file.py10
2 files changed, 12 insertions, 9 deletions
diff --git a/pip/req/req_file.py b/pip/req/req_file.py
index 7a1aa53e7..075544e0c 100644
--- a/pip/req/req_file.py
+++ b/pip/req/req_file.py
@@ -98,8 +98,8 @@ def preprocess(content, options):
:param options: cli options
"""
lines_enum = enumerate(content.splitlines(), start=1)
- lines_enum = ignore_comments(lines_enum)
lines_enum = join_lines(lines_enum)
+ lines_enum = ignore_comments(lines_enum)
lines_enum = skip_regex(lines_enum, options)
return lines_enum
@@ -278,13 +278,16 @@ def build_parser():
def join_lines(lines_enum):
- """Joins a line ending in '\' with the previous line. The joined line takes on
- the index of the first line.
+ """Joins a line ending in '\' with the previous line (except when following
+ comments). The joined line takes on the index of the first line.
"""
primary_line_number = None
new_line = []
for line_number, line in lines_enum:
- if not line.endswith('\\'):
+ if not line.endswith('\\') or COMMENT_RE.match(line):
+ if COMMENT_RE.match(line):
+ # this ensures comments are always matched later
+ line = ' ' + line
if new_line:
new_line.append(line)
yield primary_line_number, ''.join(new_line)
diff --git a/tests/unit/test_req_file.py b/tests/unit/test_req_file.py
index d714baacd..ae446a4c0 100644
--- a/tests/unit/test_req_file.py
+++ b/tests/unit/test_req_file.py
@@ -37,16 +37,16 @@ def options(session):
class TestPreprocess(object):
"""tests for `preprocess`"""
- def test_comments_processed_before_joining_case1(self):
+ def test_comments_and_joins_case1(self):
content = textwrap.dedent("""\
req1 \\
# comment \\
req2
""")
result = preprocess(content, None)
- assert list(result) == [(1, 'req1 req2')]
+ assert list(result) == [(1, 'req1'), (3, 'req2')]
- def test_comments_processed_before_joining_case2(self):
+ def test_comments_and_joins_case2(self):
content = textwrap.dedent("""\
req1\\
# comment
@@ -54,14 +54,14 @@ class TestPreprocess(object):
result = preprocess(content, None)
assert list(result) == [(1, 'req1')]
- def test_comments_processed_before_joining_case3(self):
+ def test_comments_and_joins_case3(self):
content = textwrap.dedent("""\
req1 \\
# comment
req2
""")
result = preprocess(content, None)
- assert list(result) == [(1, 'req1 req2')]
+ assert list(result) == [(1, 'req1'), (3, 'req2')]
def test_skip_regex_after_joining_case1(self, options):
content = textwrap.dedent("""\