diff --git a/news/3745.bugfix.rst b/news/3745.bugfix.rst new file mode 100644 index 0000000000..229047a40d --- /dev/null +++ b/news/3745.bugfix.rst @@ -0,0 +1 @@ +Normalize the package names to lowercase when comparing used and in-Pipfile packages. diff --git a/pipenv/core.py b/pipenv/core.py index 65541857f2..7f04ac4999 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -242,7 +242,9 @@ def import_from_code(path="."): rs = [] try: - for r in pipreqs.get_all_imports(path): + for r in pipreqs.get_all_imports( + path, encoding="utf-8", extra_ignore_dirs=[".venv"] + ): if r not in BAD_PACKAGES: rs.append(r) pkg_names = pipreqs.get_pkg_names(rs) @@ -2537,8 +2539,8 @@ def do_check( if not args: args = [] if unused: - deps_required = [k for k in project.packages.keys()] - deps_needed = import_from_code(unused) + deps_required = [k.lower() for k in project.packages.keys()] + deps_needed = [k.lower() for k in import_from_code(unused)] for dep in deps_needed: try: deps_required.remove(dep) diff --git a/tests/integration/test_cli.py b/tests/integration/test_cli.py index 82b17e17ed..f131ae4440 100644 --- a/tests/integration/test_cli.py +++ b/tests/integration/test_cli.py @@ -217,20 +217,20 @@ def test_install_parse_error(PipenvInstance, pypi): @pytest.mark.code @pytest.mark.check @pytest.mark.unused -@pytest.mark.skip(reason="non-deterministic") +@pytest.mark.needs_internet(reason='required by check') def test_check_unused(PipenvInstance, pypi): with PipenvInstance(chdir=True, pypi=pypi) as p: with open('__init__.py', 'w') as f: contents = """ import tablib import records +import flask """.strip() f.write(contents) - p.pipenv('install requests') - p.pipenv('install tablib') - p.pipenv('install records') + p.pipenv('install requests tablib flask') - assert all(pkg in p.pipfile['packages'] for pkg in ['requests', 'tablib', 'records']) + assert all(pkg in p.pipfile['packages'] for pkg in ['requests', 'tablib', 'flask']) c = p.pipenv('check --unused .') assert 'tablib' not in c.out + assert 'flask' not in c.out