diff options
author | Monty Taylor <mordred@inaugust.com> | 2013-10-28 17:24:18 +0000 |
---|---|---|
committer | Monty Taylor <mordred@inaugust.com> | 2013-11-14 06:13:22 -0500 |
commit | efe5028569cfb045d54383adb3cb65646e07dee4 (patch) | |
tree | 2fabb5eb3958932604e273b854204a33847e58d1 | |
parent | ef1922b5ffeea243bd814da99ab7a3b8390476b8 (diff) | |
download | pbr-efe5028569cfb045d54383adb3cb65646e07dee4.tar.gz |
Base python 2.7 skip list on parsed names
We keep a list of libraries that should only be installed on python 2.6,
but the check to see if a requirement matches that list was only doing
a simple string equality, which would miss attempts to install version
specified instances of one of them.
Instead, use pkg_resources to parse the potential requirements line and
operate on the parsed project name.
Change-Id: If64e4b2ee6696a0531e3ed6099e63372d47bc851
-rw-r--r-- | pbr/packaging.py | 8 | ||||
-rw-r--r-- | pbr/tests/test_setup.py | 14 |
2 files changed, 21 insertions, 1 deletions
diff --git a/pbr/packaging.py b/pbr/packaging.py index 7f7261a..a90482c 100644 --- a/pbr/packaging.py +++ b/pbr/packaging.py @@ -148,6 +148,11 @@ def parse_requirements(requirements_files=None): if (not line.strip()) or line.startswith('#'): continue + try: + project_name = pkg_resources.Requirement.parse(line).project_name + except ValueError: + project_name = None + # For the requirements list, we need to inject only the portion # after egg= so that distutils knows the package it's looking for # such as: @@ -167,7 +172,8 @@ def parse_requirements(requirements_files=None): # -f lines are for index locations, and don't get used here elif re.match(r'\s*-f\s+', line): pass - elif line in BROKEN_ON_27 and sys.version_info >= (2, 7): + elif (project_name and + project_name in BROKEN_ON_27 and sys.version_info >= (2, 7)): pass else: requirements.append(line) diff --git a/pbr/tests/test_setup.py b/pbr/tests/test_setup.py index 93d3cdf..e2bda3f 100644 --- a/pbr/tests/test_setup.py +++ b/pbr/tests/test_setup.py @@ -302,6 +302,20 @@ class ParseRequirementsTest(base.BaseTestCase): if sys.version_info >= (2, 7): self.assertEqual([], packaging.parse_requirements([self.tmp_file])) + def test_parse_requirements_removes_versioned_ordereddict(self): + self.useFixture(fixtures.MonkeyPatch('sys.version_info', (2, 7))) + with open(self.tmp_file, 'w') as fh: + fh.write("ordereddict==1.0.1") + self.assertEqual([], packaging.parse_requirements([self.tmp_file])) + + def test_parse_requirements_keeps_versioned_ordereddict(self): + self.useFixture(fixtures.MonkeyPatch('sys.version_info', (2, 6))) + with open(self.tmp_file, 'w') as fh: + fh.write("ordereddict==1.0.1") + self.assertEqual([ + "ordereddict==1.0.1"], + packaging.parse_requirements([self.tmp_file])) + def test_parse_requirements_override_with_env(self): with open(self.tmp_file, 'w') as fh: fh.write("foo\nbar") |