speed up proper_case using pypi warehouse JSON api

This commit is contained in:
Nate Prewitt
2017-05-21 23:40:17 -07:00
parent e77f23a958
commit ec02cca602
2 changed files with 4 additions and 19 deletions
-3
View File
@@ -501,9 +501,6 @@ def do_lock(no_hashes=True):
if not no_hashes:
lockfile['default'][dep['name']]['hash'] = dep['hash']
# Properly case package names.
lockfile = recase_file(lockfile)
# Write out lockfile.
with open(project.lockfile_location, 'w') as f:
json.dump(lockfile, f, indent=4, separators=(',', ': '), sort_keys=True)
+4 -16
View File
@@ -15,6 +15,8 @@ except ImportError:
# List of version control systems we support.
VCS_LIST = ('git', 'svn', 'hg', 'bzr')
requests = requests.session()
def format_toml(data):
"""Pretty-formats a given toml string."""
data = data.split('\n')
@@ -183,26 +185,12 @@ def pep423_name(name):
def proper_case(package_name):
"""Properly case project name from pypi.org"""
# Capture tag contents here.
collected = []
class SimpleHTMLParser(HTMLParser):
def handle_data(self, data):
# Remove extra blank data from https://pypi.org/simple
data = data.strip()
if len(data) > 2:
collected.append(data)
# Hit the simple API.
r = requests.get('https://pypi.org/simple/{0}'.format(package_name), timeout=2)
r = requests.get('https://pypi.org/pypi/{0}/json'.format(package_name), timeout=1, stream=True)
if not r.ok:
raise IOError('Unable to find package {0} in PyPI repository.'.format(package_name))
# Parse the HTML.
parser = SimpleHTMLParser()
parser.feed(r.text)
r = parse.parse('Links for {name}', collected[1])
r = parse.parse('https://pypi.org/pypi/{name}/json', r.url)
good_name = r['name']
return good_name