From 2a0f2e589c1f6375e3d2093619dcbedb1aa3284d Mon Sep 17 00:00:00 2001 From: Matthew Montgomery Date: Wed, 17 May 2017 15:44:24 -0500 Subject: [PATCH] Ignore index URL lines in requirements.txt files Currently if an index is specified by either -i, --index-url or --extra-index-url, the following error may be encountered when setup is run. Invalid requirement, parse error at "u'-i https'" This patch ignores those lines in a requirements.txt file durning parsing. Closes-Bug: #1394999 Change-Id: Ie03f54ca7a7edad7a26fa1721f7b26532b65e760 --- pbr/packaging.py | 4 ++++ pbr/tests/test_packaging.py | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/pbr/packaging.py b/pbr/packaging.py index a3527c91..105a010a 100644 --- a/pbr/packaging.py +++ b/pbr/packaging.py @@ -102,6 +102,10 @@ def parse_requirements(requirements_files=None, strip_markers=False): if (not line.strip()) or line.startswith('#'): continue + # Ignore index URL lines + if re.match(r'^\s*(-i|--index-url|--extra-index-url).*', line): + continue + # Handle nested requirements files such as: # -r other-requirements.txt if line.startswith('-r'): diff --git a/pbr/tests/test_packaging.py b/pbr/tests/test_packaging.py index 69a8f794..9efcbd78 100644 --- a/pbr/tests/test_packaging.py +++ b/pbr/tests/test_packaging.py @@ -486,6 +486,19 @@ class TestPresenceOfGit(base.BaseTestCase): self.assertEqual(False, git._git_is_installed()) +class TestIndexInRequirements(base.BaseTestCase): + + def test_index_in_requirement(self): + tempdir = tempfile.mkdtemp() + requirements = os.path.join(tempdir, 'requirements.txt') + with open(requirements, 'w') as f: + f.write('-i https://myindex.local') + f.write(' --index-url https://myindex.local') + f.write(' --extra-index-url https://myindex.local') + result = packaging.parse_requirements([requirements]) + self.assertEqual([], result) + + class TestNestedRequirements(base.BaseTestCase): def test_nested_requirement(self):