From ec02cca60219b3cede2f1a9234dae409f047a422 Mon Sep 17 00:00:00 2001 From: Nate Prewitt Date: Sun, 21 May 2017 23:40:17 -0700 Subject: [PATCH] speed up proper_case using pypi warehouse JSON api --- pipenv/cli.py | 3 --- pipenv/utils.py | 20 ++++---------------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/pipenv/cli.py b/pipenv/cli.py index 43ddfb4d..2811c7ef 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -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) diff --git a/pipenv/utils.py b/pipenv/utils.py index 91086043..995c5217 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -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