Skip to content

Commit c67a38e

Browse files
author
Frost Ming
authored
Merge pull request #3745 from pypa/bugfix/check_unused
make check unused work
2 parents fb890d6 + bc37bea commit c67a38e

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

news/3745.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Normalize the package names to lowercase when comparing used and in-Pipfile packages.

pipenv/core.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ def import_from_code(path="."):
242242

243243
rs = []
244244
try:
245-
for r in pipreqs.get_all_imports(path):
245+
for r in pipreqs.get_all_imports(
246+
path, encoding="utf-8", extra_ignore_dirs=[".venv"]
247+
):
246248
if r not in BAD_PACKAGES:
247249
rs.append(r)
248250
pkg_names = pipreqs.get_pkg_names(rs)
@@ -2537,8 +2539,8 @@ def do_check(
25372539
if not args:
25382540
args = []
25392541
if unused:
2540-
deps_required = [k for k in project.packages.keys()]
2541-
deps_needed = import_from_code(unused)
2542+
deps_required = [k.lower() for k in project.packages.keys()]
2543+
deps_needed = [k.lower() for k in import_from_code(unused)]
25422544
for dep in deps_needed:
25432545
try:
25442546
deps_required.remove(dep)

tests/integration/test_cli.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,20 +217,20 @@ def test_install_parse_error(PipenvInstance, pypi):
217217
@pytest.mark.code
218218
@pytest.mark.check
219219
@pytest.mark.unused
220-
@pytest.mark.skip(reason="non-deterministic")
220+
@pytest.mark.needs_internet(reason='required by check')
221221
def test_check_unused(PipenvInstance, pypi):
222222
with PipenvInstance(chdir=True, pypi=pypi) as p:
223223
with open('__init__.py', 'w') as f:
224224
contents = """
225225
import tablib
226226
import records
227+
import flask
227228
""".strip()
228229
f.write(contents)
229-
p.pipenv('install requests')
230-
p.pipenv('install tablib')
231-
p.pipenv('install records')
230+
p.pipenv('install requests tablib flask')
232231

233-
assert all(pkg in p.pipfile['packages'] for pkg in ['requests', 'tablib', 'records'])
232+
assert all(pkg in p.pipfile['packages'] for pkg in ['requests', 'tablib', 'flask'])
234233

235234
c = p.pipenv('check --unused .')
236235
assert 'tablib' not in c.out
236+
assert 'flask' not in c.out

0 commit comments

Comments
 (0)