diff options
author | Marcus Smith <qwcode@gmail.com> | 2015-10-09 07:48:28 -0700 |
---|---|---|
committer | Marcus Smith <qwcode@gmail.com> | 2015-10-09 07:48:28 -0700 |
commit | 13d43e3af8b5c8e8c7c66dde8a9f76b340697c3e (patch) | |
tree | 59667d9526e067727c4419562d6e6c3776e13665 | |
parent | 9b29884fe90a1da9606672925f22267571d2e6eb (diff) | |
parent | b58d2c9f34d869db96fc1f47e43039ef576f300f (diff) | |
download | pip-13d43e3af8b5c8e8c7c66dde8a9f76b340697c3e.tar.gz |
Merge pull request #3170 from qwcode/req_line_numbers2
update for processing continuations/comments for req files
-rw-r--r-- | pip/req/req_file.py | 11 | ||||
-rw-r--r-- | tests/unit/test_req_file.py | 10 |
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("""\ |