Skip to content

Commit

Permalink
Merge pull request #3745 from pypa/bugfix/check_unused
Browse files Browse the repository at this point in the history
make check unused work
  • Loading branch information
Frost Ming authored May 20, 2019
2 parents fb890d6 + bc37bea commit c67a38e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions news/3745.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Normalize the package names to lowercase when comparing used and in-Pipfile packages.
8 changes: 5 additions & 3 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c67a38e

Please sign in to comment.