use packaging to determine the canonical name for projects on PyPI
Rather than applying the rules ourselves, use the packaging project utility function to prepare the canonical name. Change-Id: I6310585ff14c376e954b0edc9def67cd65a5d550 Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
parent
55c12c6f36
commit
9b8f290117
@ -521,13 +521,6 @@ def validate_pypi_permissions(deliv, context):
|
|||||||
pypi_name = sdist
|
pypi_name = sdist
|
||||||
|
|
||||||
uploaders = pythonutils.get_pypi_uploaders(pypi_name)
|
uploaders = pythonutils.get_pypi_uploaders(pypi_name)
|
||||||
if not uploaders:
|
|
||||||
# Names like "openstack_requirements" are translated to
|
|
||||||
# "openstack-requirements" in the PyPI API.
|
|
||||||
alt_name = pypi_name.replace('_', '-')
|
|
||||||
LOG.debug('retrying with pypi_name name {!r}'.format(alt_name))
|
|
||||||
uploaders = pythonutils.get_pypi_uploaders(alt_name)
|
|
||||||
|
|
||||||
if not uploaders:
|
if not uploaders:
|
||||||
context.error(
|
context.error(
|
||||||
'could not find users with permission to upload packages '
|
'could not find users with permission to upload packages '
|
||||||
|
@ -18,6 +18,7 @@ import os
|
|||||||
import os.path
|
import os.path
|
||||||
import xmlrpc.client
|
import xmlrpc.client
|
||||||
|
|
||||||
|
from packaging import utils as packaging_utils
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from openstack_releases import processutils
|
from openstack_releases import processutils
|
||||||
@ -65,8 +66,9 @@ def guess_sdist_name(project):
|
|||||||
|
|
||||||
def get_pypi_info(dist_name):
|
def get_pypi_info(dist_name):
|
||||||
"Return PyPI information for the distribution."
|
"Return PyPI information for the distribution."
|
||||||
LOG.debug('looking at PyPI for {}'.format(dist_name))
|
canonical_name = packaging_utils.canonicalize_name(dist_name)
|
||||||
url = 'https://pypi.python.org/pypi/{}/json'.format(dist_name)
|
LOG.debug('looking at PyPI for {!r}'.format(canonical_name))
|
||||||
|
url = 'https://pypi.python.org/pypi/{}/json'.format(canonical_name)
|
||||||
LOG.debug(url)
|
LOG.debug(url)
|
||||||
try:
|
try:
|
||||||
return requests.get(url).json()
|
return requests.get(url).json()
|
||||||
@ -74,12 +76,22 @@ def get_pypi_info(dist_name):
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
def get_pypi_uploaders(dist_name):
|
def _get_pypi_roles(dist_name):
|
||||||
client = xmlrpc.client.ServerProxy('https://pypi.python.org/pypi')
|
client = xmlrpc.client.ServerProxy('https://pypi.python.org/pypi')
|
||||||
roles = client.package_roles(dist_name)
|
LOG.debug('retrieving roles for {!r}'.format(
|
||||||
|
dist_name))
|
||||||
|
return client.package_roles(dist_name)
|
||||||
|
|
||||||
|
|
||||||
|
def get_pypi_uploaders(dist_name):
|
||||||
|
roles = _get_pypi_roles(dist_name)
|
||||||
|
if not roles:
|
||||||
|
canonical_name = packaging_utils.canonicalize_name(dist_name)
|
||||||
|
roles = _get_pypi_roles(canonical_name)
|
||||||
uploaders = set(
|
uploaders = set(
|
||||||
acct
|
acct
|
||||||
for role, acct in roles
|
for role, acct in roles
|
||||||
if role in ('Owner', 'Maintainer')
|
if role in ('Owner', 'Maintainer')
|
||||||
)
|
)
|
||||||
|
LOG.debug('found: {}'.format(sorted(uploaders)))
|
||||||
return uploaders
|
return uploaders
|
||||||
|
@ -32,3 +32,4 @@ sphinx>=1.6.2 # BSD
|
|||||||
pyfiglet>=0.7.5
|
pyfiglet>=0.7.5
|
||||||
|
|
||||||
appdirs
|
appdirs
|
||||||
|
packaging>=16.5
|
||||||
|
Loading…
Reference in New Issue
Block a user