From 4f676302cc552a081f80eed337bd20c11aa8b4b9 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Tue, 24 Jan 2017 22:42:01 -0500 Subject: [PATCH] proper casing for installing package names Fixes #78 --- Pipfile | 1 + Pipfile.lock | 6 +++++- pipenv/cli.py | 26 ++++++++++++++++++++++++-- setup.py | 3 ++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Pipfile b/Pipfile index 3b5d7ae3..80b45e2a 100644 --- a/Pipfile +++ b/Pipfile @@ -8,4 +8,5 @@ requirements-parser = "*" "backports.shutil_get_terminal_size" = "*" parse = "*" toml = "*" +requests = "*" click = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 021a2a42..bf0dcca0 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -36,6 +36,10 @@ "version": "==0.3.7", "hash": "sha256:a4c0f5bc358a62849653471e309dcc991223cf86abafbec17cd8f41327279e89" }, + "requests": { + "version": "==2.13.0", + "hash": "sha256:1a720e8862a41aa22e339373b526f508ef0c8988baf48b84d3fc891a8e237efb" + }, "click": { "version": "==6.7", "hash": "sha256:29f99fc6125fbc931b758dc053b3114e55c77a6e4c6c3a2674a2dc986016381d" @@ -79,6 +83,6 @@ } ], "requires": {}, - "Pipfile-sha256": "bceb0e55b886dea8ff6ada0dfe673c18a010695c160b0643e93c0fb6c5337fd6" + "Pipfile-sha256": "24f12b631b7c40b8c5eff934a1aef263ed04f5eaffb4acf4706442f3d23cba36" } } \ No newline at end of file diff --git a/pipenv/cli.py b/pipenv/cli.py index f3dec50c..39060138 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -6,6 +6,7 @@ import sys import distutils.spawn import shutil import signal +from HTMLParser import HTMLParser # Backport required for earlier versions of Python. if sys.version_info < (3, 3): @@ -18,6 +19,7 @@ import crayons import delegator import parse import pexpect +import requests from . import _pipfile as pipfile from .project import Project @@ -396,6 +398,26 @@ def which_pip(allow_global=False): return which('pip') +def proper_case(package_name): + + # Capture tag contents here. + collected = [] + + class SimpleHTMLParser(HTMLParser): + def handle_data(self, data): + if len(data) > 2: + collected.append(data) + + # Hit the simple API. + r = requests.get('{0}/{1}'.format(project.source['url'], package_name)) + + # Parse the HTML. + parser = SimpleHTMLParser() + parser.feed(r.content) + + # Use the last link on the page, use it to get proper casing. + return parse_download_fname(collected[-1])[0] + def format_help(help): """Formats the help string.""" help = help.replace(' check', str(crayons.green(' check'))) @@ -499,8 +521,8 @@ def install(package_name=False, more_packages=False, dev=False, three=False, sys for package_name in package_names: - # Lower-case incoming package name. - package_name = package_name + # Proper-case incoming package name (check against API). + package_name = proper_case(package_name) click.echo('Installing {0}...'.format(crayons.green(package_name))) diff --git a/setup.py b/setup.py index fb392bef..28a1f439 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,8 @@ required = [ 'virtualenv', 'delegator.py>=0.0.6', 'requirements-parser', - 'pexpect' + 'pexpect', + 'requests' ] # Backport required for earlier versions of Python.