From c7e1abab2421bbe2f35b81b3f26b198e7a40c30b Mon Sep 17 00:00:00 2001 From: Jeff Tratner Date: Fri, 16 Mar 2018 13:58:59 -0700 Subject: [PATCH] Fix error on empty virtualenv and pipenv clean Obv could also *not* create the empty virtualenv when running pipenv clean, but in general can imagine this also occurring if you created an empty virtualenv and then tried to do clean within it. (installed packages was ['']) --- pipenv/core.py | 4 ++-- tests/test_pipenv.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pipenv/core.py b/pipenv/core.py index 3e307c40..7b4d2392 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -2523,12 +2523,12 @@ def do_clean( # Ensure that virtualenv is available. ensure_project(three=three, python=python, validate=False) ensure_lockfile() - installed_packages = delegator.run( + installed_packages = filter(None, delegator.run( '{0} freeze'.format(which('pip')) ).out.strip( ).split( '\n' - ) + )) installed_package_names = [] for installed in installed_packages: r = get_requirement(installed) diff --git a/tests/test_pipenv.py b/tests/test_pipenv.py index 5cb012c1..110bd68e 100644 --- a/tests/test_pipenv.py +++ b/tests/test_pipenv.py @@ -1051,3 +1051,9 @@ requests = "==2.14.0" assert target_package in p.pipfile['packages'] assert p.pipfile['packages'][target_package] == '*' assert target_package in p.lockfile['default'] + + @pytest.mark.clean + def test_clean_on_empty_venv(self, pypi): + with PipenvInstance(pypi=pypi) as p: + c = p.pipenv('clean') + assert c.return_code == 0