From 1e05037c2ae02a4d52d0f50abf00d61021971508 Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Sun, 23 Aug 2015 08:48:29 -0400 Subject: [PATCH] Strip comments in requirements files Since we don't strip comments from end of the requirements like: requests-kerberos>=0.6;python_version=='2.7' # MIT The currnet code ends up failing with a: "Invalid environment marker" We should strip the comments out before processing. Closes-Bug: #1487835 Change-Id: I75d2e83a5f60f93e1c38d53fb4f0a29ba35120b1 --- pbr/packaging.py | 1 + pbr/tests/test_packaging.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pbr/packaging.py b/pbr/packaging.py index ec4388b2..672b8a7d 100644 --- a/pbr/packaging.py +++ b/pbr/packaging.py @@ -132,6 +132,7 @@ def parse_requirements(requirements_files=None, strip_markers=False): reason = 'Index Location' if line is not None: + line = re.sub('#.*$', '', line) if strip_markers: semi_pos = line.find(';') if semi_pos < 0: diff --git a/pbr/tests/test_packaging.py b/pbr/tests/test_packaging.py index 4a188d00..607d63af 100644 --- a/pbr/tests/test_packaging.py +++ b/pbr/tests/test_packaging.py @@ -466,6 +466,9 @@ class TestRequirementParsing(base.BaseTestCase): f.write(textwrap.dedent(six.u("""\ bar quux<1.0; python_version=='2.6' + requests-aws>=0.1.4 # BSD License (3 clause) + Routes>=1.12.3,!=2.0,!=2.1;python_version=='2.7' + requests-kerberos>=0.6;python_version=='2.7' # MIT """))) setup_cfg = os.path.join(tempdir, 'setup.cfg') with open(setup_cfg, 'wt') as f: @@ -481,11 +484,14 @@ class TestRequirementParsing(base.BaseTestCase): # pkg_resources.split_sections uses None as the title of an # anonymous section instead of the empty string. Weird. expected_requirements = { - None: ['bar'], + None: ['bar', 'requests-aws>=0.1.4'], ":(python_version=='2.6')": ['quux<1.0'], - "test:(python_version=='2.7')": ['baz>3.2'], - "test": ['foo'] + ":(python_version=='2.7')": ['Routes>=1.12.3,!=2.0,!=2.1', + 'requests-kerberos>=0.6'], + 'test': ['foo'], + "test:(python_version=='2.7')": ['baz>3.2'] } + setup_py = os.path.join(tempdir, 'setup.py') with open(setup_py, 'wt') as f: f.write(textwrap.dedent(six.u("""\