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 2 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
6 changes: 3 additions & 3 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ 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"):
if r not in BAD_PACKAGES:
rs.append(r)
pkg_names = pipreqs.get_pkg_names(rs)
Expand Down Expand Up @@ -2537,8 +2537,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
7 changes: 4 additions & 3 deletions tests/integration/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,21 @@ def test_install_parse_error(PipenvInstance, pypi):
@pytest.mark.code
@pytest.mark.check
@pytest.mark.unused
@pytest.mark.skip(reason="non-deterministic")
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 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