Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make check unused work #3745

Merged
merged 6 commits into from
May 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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