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 <nuaafe@gmail.com>
This commit is contained in:
Wei Tie 2018-08-08 18:03:31 -07:00
parent 033c1bdee8
commit bca35333bc
2 changed files with 13 additions and 4 deletions

View File

@ -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):

View File

@ -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,