From bca35333bcc1102040158ca97f2aac3bd932430b Mon Sep 17 00:00:00 2001 From: Wei Tie Date: Wed, 8 Aug 2018 18:03:31 -0700 Subject: [PATCH] Support subdirectory in the url Pip supports git+https://foo.com/zipball#egg=bar&subdirectory=baz when setup.py is not at the root directory of the project [1]. This commit keeps pbr function in this case. [1] https://pip.pypa.io/en/latest/reference/pip_install/#vcs-support Change-Id: I70dac755caacc89859a8646c090b69800401bbc0 Closes-Bug: 1786306 Signed-off-by: Wei Tie --- pbr/packaging.py | 6 ++++-- pbr/tests/test_packaging.py | 11 +++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pbr/packaging.py b/pbr/packaging.py index 8656a6ce..bb0ec6b5 100644 --- a/pbr/packaging.py +++ b/pbr/packaging.py @@ -137,13 +137,15 @@ def parse_requirements(requirements_files=None, strip_markers=False): # such as: # -e git://github.com/openstack/nova/master#egg=nova # -e git://github.com/openstack/nova/master#egg=nova-1.2.3 + # -e git+https://foo.com/zipball#egg=bar&subdirectory=baz if re.match(r'\s*-e\s+', line): - line = re.sub(r'\s*-e\s+.*#egg=(.*)$', egg_fragment, line) + line = re.sub(r'\s*-e\s+.*#egg=([^&]+).*$', egg_fragment, line) # such as: # http://github.com/openstack/nova/zipball/master#egg=nova # http://github.com/openstack/nova/zipball/master#egg=nova-1.2.3 + # git+https://foo.com/zipball#egg=bar&subdirectory=baz elif re.match(r'\s*(https?|git(\+(https|ssh))?):', line): - line = re.sub(r'\s*(https?|git(\+(https|ssh))?):.*#egg=(.*)$', + line = re.sub(r'\s*(https?|git(\+(https|ssh))?):.*#egg=([^&]+).*$', egg_fragment, line) # -f lines are for index locations, and don't get used here elif re.match(r'\s*-f\s+', line): diff --git a/pbr/tests/test_packaging.py b/pbr/tests/test_packaging.py index 5512d5d6..9bd91ae0 100644 --- a/pbr/tests/test_packaging.py +++ b/pbr/tests/test_packaging.py @@ -579,6 +579,11 @@ class ParseRequirementsTestScenarios(base.BaseTestCase): ('versioned', {'versioned': True, 'expected': ['bar>=1.2.3']}) ] + subdirectory_scenarios = [ + ('non-subdirectory', {'has_subdirectory': False}), + ('has-subdirectory', {'has_subdirectory': True}) + ] + scenarios = [ ('normal', {'url': "foo\nbar", 'expected': ['foo', 'bar']}), ('normal_with_comments', { @@ -591,7 +596,7 @@ class ParseRequirementsTestScenarios(base.BaseTestCase): ('ssh_egg_url', {'url': 'git+ssh://foo.com/zipball#egg=bar'}), ('git_https_egg_url', {'url': 'git+https://foo.com/zipball#egg=bar'}), ('http_egg_url', {'url': 'https://foo.com/zipball#egg=bar'}), - ], versioned_scenarios) + ], versioned_scenarios, subdirectory_scenarios) scenarios = scenarios + testscenarios.multiply_scenarios( [ @@ -601,7 +606,7 @@ class ParseRequirementsTestScenarios(base.BaseTestCase): ('non-editable', {'editable': False}), ('editable', {'editable': True}), ], - versioned_scenarios) + versioned_scenarios, subdirectory_scenarios) def test_parse_requirements(self): tmp_file = tempfile.NamedTemporaryFile() @@ -610,6 +615,8 @@ class ParseRequirementsTestScenarios(base.BaseTestCase): req_string = ("-e %s" % req_string) if hasattr(self, 'versioned') and self.versioned: req_string = ("%s-1.2.3" % req_string) + if hasattr(self, 'has_subdirectory') and self.has_subdirectory: + req_string = ("%s&subdirectory=baz" % req_string) with open(tmp_file.name, 'w') as fh: fh.write(req_string) self.assertEqual(self.expected,