diff options
author | Ben Nemec <bnemec@redhat.com> | 2014-03-26 17:27:04 +0000 |
---|---|---|
committer | Ben Nemec <bnemec@redhat.com> | 2014-03-26 17:56:50 +0000 |
commit | 960385efd5bc2d9f2e93156524a4b207a1ab7332 (patch) | |
tree | 00726e051f7245b4d1bcead611305be88b8e6f5b | |
parent | 2aeb8da1dcab1d916928ce4b4b726a1aa4e252b8 (diff) | |
download | pbr-960385efd5bc2d9f2e93156524a4b207a1ab7332.tar.gz |
Add support for nested requirements files
pip supports requirements files with a line such as:
-r other-requirements.txt
for specifying nested requirements files. Adding support to pbr
should be helpful with handling optional dependencies in projects
better, by allowing us to split the requirements files and then
merge them back together using -r lines.
Change-Id: I80e081b2229cc81eed26533c50afb07dc98a1db1
-rw-r--r-- | pbr/packaging.py | 7 | ||||
-rw-r--r-- | pbr/tests/test_packaging.py | 15 |
2 files changed, 22 insertions, 0 deletions
diff --git a/pbr/packaging.py b/pbr/packaging.py index 21b2b82..9b022a7 100644 --- a/pbr/packaging.py +++ b/pbr/packaging.py @@ -125,6 +125,13 @@ def parse_requirements(requirements_files=None): if (not line.strip()) or line.startswith('#'): continue + # Handle nested requirements files such as: + # -r other-requirements.txt + if line.startswith('-r'): + req_file = line.partition(' ')[2] + requirements += parse_requirements([req_file]) + continue + try: project_name = pkg_resources.Requirement.parse(line).project_name except ValueError: diff --git a/pbr/tests/test_packaging.py b/pbr/tests/test_packaging.py index 029f378..d382d37 100644 --- a/pbr/tests/test_packaging.py +++ b/pbr/tests/test_packaging.py @@ -39,6 +39,7 @@ # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS import os +import tempfile import fixtures import mock @@ -126,3 +127,17 @@ class TestPresenceOfGit(base.BaseTestCase): '_run_shell_command') as _command: _command.side_effect = OSError self.assertEqual(False, packaging._git_is_installed()) + + +class TestNestedRequirements(base.BaseTestCase): + + def test_nested_requirement(self): + tempdir = tempfile.mkdtemp() + requirements = os.path.join(tempdir, 'requirements.txt') + nested = os.path.join(tempdir, 'nested.txt') + with open(requirements, 'w') as f: + f.write('-r ' + nested) + with open(nested, 'w') as f: + f.write('pbr') + result = packaging.parse_requirements([requirements]) + self.assertEqual(result, ['pbr']) |