From b9bd4835ee1a130263a4ae99828386a9e159ce5f Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Tue, 10 Apr 2018 20:39:51 +0800 Subject: [PATCH] Improve according to comments --- pipenv/project.py | 11 ++++++----- tests/test_pipenv.py | 15 +++++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/pipenv/project.py b/pipenv/project.py index 595f0b93..6ce151a1 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -595,8 +595,9 @@ class Project(object): """Get the equivalent package name in pipfile""" key = 'dev-packages' if dev else 'packages' section = self.parsed_pipfile.get(key, {}) + package_name = pep423_name(package_name) for name in section.keys(): - if pep423_name(name) == pep423_name(package_name): + if pep423_name(name) == package_name: return name return None @@ -626,11 +627,11 @@ class Project(object): package = convert_deps_from_pip(package_name) package_name = [k for k in package.keys()][0] name = self.get_package_name_in_pipfile(package_name, dev) - if name and name != package_name: - # Replace the packge name - del p[key][name] + if name and converted == '*': + # Skip for wildcard version + return # Add the package to the group. - p[key][package_name] = package[package_name] + p[key][name or package_name] = package[package_name] # Write Pipfile. self.write_toml(p) diff --git a/tests/test_pipenv.py b/tests/test_pipenv.py index b03875f7..51a12d2f 100644 --- a/tests/test_pipenv.py +++ b/tests/test_pipenv.py @@ -592,13 +592,13 @@ tpfd = "*" @pytest.mark.install @pytest.mark.run - def test_pep423_name_install(self, pypi): + def test_normalize_name_install(self, pypi): with PipenvInstance(pypi=pypi) as p: with open(p.pipfile_path, 'w') as f: contents = """ # Pre comment [packages] -python_DateUtil = "*" # Inline comment +Requests = "==2.14.0" # Inline comment """ f.write(contents) @@ -607,18 +607,21 @@ python_DateUtil = "*" # Inline comment c = p.pipenv('install requests') assert c.return_code == 0 - assert 'python_DateUtil' in p.pipfile['packages'] - c = p.pipenv('install python_dateutil') + assert 'requests' not in p.pipfile['packages'] + assert p.pipfile['packages']['Requests'] == '==2.14.0' + c = p.pipenv('install requests==2.18.4') + assert c.return_code == 0 + assert p.pipfile['packages']['Requests'] == '==2.18.4' + c = p.pipenv('install python_DateUtil') assert c.return_code == 0 assert 'python-dateutil' in p.pipfile['packages'] - assert 'python_DateUtil' not in p.pipfile['packages'] contents = open(p.pipfile_path).read() assert '# Pre comment' in contents assert '# Inline comment' in contents @pytest.mark.uninstall @pytest.mark.run - def test_pep423_name_uninstall(self, pypi): + def test_normalize_name_uninstall(self, pypi): with PipenvInstance(pypi=pypi) as p: with open(p.pipfile_path, 'w') as f: contents = """