Commit bca35333 authored by Wei Tie's avatar Wei Tie

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: 's avatarWei Tie <nuaafe@gmail.com>
parent 033c1bde
...@@ -137,13 +137,15 @@ def parse_requirements(requirements_files=None, strip_markers=False): ...@@ -137,13 +137,15 @@ def parse_requirements(requirements_files=None, strip_markers=False):
# such as: # such as:
# -e git://github.com/openstack/nova/master#egg=nova # -e git://github.com/openstack/nova/master#egg=nova
# -e git://github.com/openstack/nova/master#egg=nova-1.2.3 # -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): 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: # such as:
# http://github.com/openstack/nova/zipball/master#egg=nova # http://github.com/openstack/nova/zipball/master#egg=nova
# http://github.com/openstack/nova/zipball/master#egg=nova-1.2.3 # 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): 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) egg_fragment, line)
# -f lines are for index locations, and don't get used here # -f lines are for index locations, and don't get used here
elif re.match(r'\s*-f\s+', line): elif re.match(r'\s*-f\s+', line):
......
...@@ -579,6 +579,11 @@ class ParseRequirementsTestScenarios(base.BaseTestCase): ...@@ -579,6 +579,11 @@ class ParseRequirementsTestScenarios(base.BaseTestCase):
('versioned', {'versioned': True, 'expected': ['bar>=1.2.3']}) ('versioned', {'versioned': True, 'expected': ['bar>=1.2.3']})
] ]
subdirectory_scenarios = [
('non-subdirectory', {'has_subdirectory': False}),
('has-subdirectory', {'has_subdirectory': True})
]
scenarios = [ scenarios = [
('normal', {'url': "foo\nbar", 'expected': ['foo', 'bar']}), ('normal', {'url': "foo\nbar", 'expected': ['foo', 'bar']}),
('normal_with_comments', { ('normal_with_comments', {
...@@ -591,7 +596,7 @@ class ParseRequirementsTestScenarios(base.BaseTestCase): ...@@ -591,7 +596,7 @@ class ParseRequirementsTestScenarios(base.BaseTestCase):
('ssh_egg_url', {'url': 'git+ssh://foo.com/zipball#egg=bar'}), ('ssh_egg_url', {'url': 'git+ssh://foo.com/zipball#egg=bar'}),
('git_https_egg_url', {'url': 'git+https://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'}), ('http_egg_url', {'url': 'https://foo.com/zipball#egg=bar'}),
], versioned_scenarios) ], versioned_scenarios, subdirectory_scenarios)
scenarios = scenarios + testscenarios.multiply_scenarios( scenarios = scenarios + testscenarios.multiply_scenarios(
[ [
...@@ -601,7 +606,7 @@ class ParseRequirementsTestScenarios(base.BaseTestCase): ...@@ -601,7 +606,7 @@ class ParseRequirementsTestScenarios(base.BaseTestCase):
('non-editable', {'editable': False}), ('non-editable', {'editable': False}),
('editable', {'editable': True}), ('editable', {'editable': True}),
], ],
versioned_scenarios) versioned_scenarios, subdirectory_scenarios)
def test_parse_requirements(self): def test_parse_requirements(self):
tmp_file = tempfile.NamedTemporaryFile() tmp_file = tempfile.NamedTemporaryFile()
...@@ -610,6 +615,8 @@ class ParseRequirementsTestScenarios(base.BaseTestCase): ...@@ -610,6 +615,8 @@ class ParseRequirementsTestScenarios(base.BaseTestCase):
req_string = ("-e %s" % req_string) req_string = ("-e %s" % req_string)
if hasattr(self, 'versioned') and self.versioned: if hasattr(self, 'versioned') and self.versioned:
req_string = ("%s-1.2.3" % req_string) 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: with open(tmp_file.name, 'w') as fh:
fh.write(req_string) fh.write(req_string)
self.assertEqual(self.expected, self.assertEqual(self.expected,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment