bndr / bndr/pipreqs

Pipreqs reports wrong version when package name != module name

Open
#265 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
7.5k
Forks
424
PR merge metrics
No merged PRs in 30d

Description

Steps to reproduce:
```bash
python3 -m venv testenv
source testenv/bin/activate
# install older version of scikit-learn
pip install pipreqs scikit-learn==0.20.3
mkdir test
echo "import sklearn" > test/test.py
pipreqs test
cat test/requirements.txt
deactivate
```
Actual Output
`scikit_learn==0.24.2`

Expected Output
`scikit_learn==0.20.3`

This occurs because `get_import_local` is called with package names in the `imports` parameter (by way of `candidates = get_pkg_names(candidates)`). It tests if each import is in `local`. However, `local` is a dict where the keys are module names. This results in not finding the locally installed package and instead looking up the latest version on pypi.org.

Contributor guide

Open the contributing guide

Research direction

Start by tracing get_import_local and get_pkg_names, especially how package names are checked against the local module-name dictionary. Reproduce the issue with scikit-learn==0.20.3 using the commands in the report, then verify that pipreqs writes scikit_learn==0.20.3 rather than the latest PyPI version.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.