Deal with underscores in names in edit-constraints
Problem showed up with django_openstack_auth job that installs from source. The change to devstack to verify LIBS_FROM_GIT kicked in (Iffef2007f99a0e932b68c4c897ebbfb748cac2b4) and starting failing the job. The problem was that the edit_constraint was not fixing the django-openstack-auth line in upperconstraints.txt as the setup.cfg had name = django_openstack_auth. Note that when things finally get installed setup_tools' safe_name kicks in to standardize names and for example glance_store will show up as glance-store in pip freeze. So we should be able to treat this situation better and allow constraints to have the safe names (using dashes). Co-Authored-By: Robert Collins <rbtcollins@hp.com> Change-Id: Ibaa22657a2cf2c0ad96dbd0b9bc43cdafe6a1d56
This commit is contained in:
parent
ab17d700ed
commit
3ebedf84f0
@ -21,10 +21,11 @@ from openstack_requirements import requirement
|
|||||||
|
|
||||||
|
|
||||||
def edit(reqs, name, replacement):
|
def edit(reqs, name, replacement):
|
||||||
|
key = requirement.canonical_name(name)
|
||||||
if not replacement:
|
if not replacement:
|
||||||
reqs.pop(name, None)
|
reqs.pop(key, None)
|
||||||
else:
|
else:
|
||||||
reqs[name] = [
|
reqs[key] = [
|
||||||
(requirement.Requirement('', '', '', '', replacement), '')]
|
(requirement.Requirement('', '', '', '', replacement), '')]
|
||||||
result = []
|
result = []
|
||||||
for entries in reqs.values():
|
for entries in reqs.values():
|
||||||
|
@ -41,6 +41,11 @@ url_re = re.compile(
|
|||||||
'#egg=(?P<name>[-\.\w]+)')
|
'#egg=(?P<name>[-\.\w]+)')
|
||||||
|
|
||||||
|
|
||||||
|
def canonical_name(req_name):
|
||||||
|
"""Return the canonical form of req_name."""
|
||||||
|
return pkg_resources.safe_name(req_name).lower()
|
||||||
|
|
||||||
|
|
||||||
def parse(content, permit_urls=False):
|
def parse(content, permit_urls=False):
|
||||||
return to_dict(to_reqs(content, permit_urls=permit_urls))
|
return to_dict(to_reqs(content, permit_urls=permit_urls))
|
||||||
|
|
||||||
@ -134,7 +139,8 @@ def to_dict(req_sequence):
|
|||||||
reqs = dict()
|
reqs = dict()
|
||||||
for req, req_line in req_sequence:
|
for req, req_line in req_sequence:
|
||||||
if req is not None:
|
if req is not None:
|
||||||
reqs.setdefault(req.package.lower(), []).append((req, req_line))
|
key = canonical_name(req.package)
|
||||||
|
reqs.setdefault(key, []).append((req, req_line))
|
||||||
return reqs
|
return reqs
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,3 +83,10 @@ class TestEdit(testtools.TestCase):
|
|||||||
res = edit.edit(reqs, 'foo', 'foo==1.3')
|
res = edit.edit(reqs, 'foo', 'foo==1.3')
|
||||||
self.assertEqual(requirement.Requirements(
|
self.assertEqual(requirement.Requirements(
|
||||||
[requirement.Requirement('', '', '', '', 'foo==1.3')]), res)
|
[requirement.Requirement('', '', '', '', 'foo==1.3')]), res)
|
||||||
|
|
||||||
|
def test_replace_non_canonical(self):
|
||||||
|
new_req = '-e file:///path#egg=foo_baz'
|
||||||
|
reqs = requirement.parse("foo-baz===1.0.2\n")
|
||||||
|
res = edit.edit(reqs, 'foo_baz', new_req)
|
||||||
|
self.assertEqual(res, requirement.Requirements(
|
||||||
|
[requirement.Requirement('', '', '', '', new_req)]))
|
||||||
|
@ -148,3 +148,17 @@ class TestToReqs(testtools.TestCase):
|
|||||||
set(['oslo.config', 'oslo.concurrency', 'oslo.context']),
|
set(['oslo.config', 'oslo.concurrency', 'oslo.context']),
|
||||||
set(reqs.keys()),
|
set(reqs.keys()),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TestCanonicalName(testtools.TestCase):
|
||||||
|
|
||||||
|
def test_underscores(self):
|
||||||
|
self.assertEqual('foo-bar', requirement.canonical_name('Foo_bar'))
|
||||||
|
|
||||||
|
|
||||||
|
class TestToDict(testtools.TestCase):
|
||||||
|
|
||||||
|
def test_canonicalises(self):
|
||||||
|
req = requirement.Requirement('Foo_bar', '', '', '', '')
|
||||||
|
self.assertEqual(
|
||||||
|
{'foo-bar': [(req, '')]}, requirement.to_dict([(req, '')]))
|
||||||
|
Loading…
Reference in New Issue
Block a user