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:
Davanum Srinivas 2015-09-16 14:49:07 -04:00 committed by Robert Collins
parent ab17d700ed
commit 3ebedf84f0
4 changed files with 31 additions and 3 deletions

View File

@ -21,10 +21,11 @@ from openstack_requirements import requirement
def edit(reqs, name, replacement):
key = requirement.canonical_name(name)
if not replacement:
reqs.pop(name, None)
reqs.pop(key, None)
else:
reqs[name] = [
reqs[key] = [
(requirement.Requirement('', '', '', '', replacement), '')]
result = []
for entries in reqs.values():

View File

@ -41,6 +41,11 @@ url_re = re.compile(
'#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):
return to_dict(to_reqs(content, permit_urls=permit_urls))
@ -134,7 +139,8 @@ def to_dict(req_sequence):
reqs = dict()
for req, req_line in req_sequence:
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

View File

@ -83,3 +83,10 @@ class TestEdit(testtools.TestCase):
res = edit.edit(reqs, 'foo', 'foo==1.3')
self.assertEqual(requirement.Requirements(
[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)]))

View File

@ -148,3 +148,17 @@ class TestToReqs(testtools.TestCase):
set(['oslo.config', 'oslo.concurrency', 'oslo.context']),
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, '')]))