bndr / bndr/pipreqs

mypy cache folder causes generated requirements to be empty

Open Beginner friendly
#330 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
7.5k
Forks
424
PR merge metrics
No merged PRs in 30d

Description

Related to #73.

### Steps to reproduce
- Create **foo.py**:
```python
import requests
```
- Run the following commands:
```
$ pipreqs --print
requests==2.28.1
INFO: Successfully output requirements

$ mypy foo.py
Success: no issues found in 1 source file

$ pipreqs --print

INFO: Successfully output requirements
```
I would expect 'requests' to still be in the generated requirements after running mypy.
### Description
Since mypy creates a subfolder called `.mypy_cache/3.10/requests`, pipreqs will add it to 'candidates' which causes the import to be satisfied, even though foo.py is obviously not going to attempt to import that folder. Ignoring `.mypy_cache` is the simple fix, but maybe folders shouldn't be considered packages unless they contain an `__init__.py`?
https://github.com/bndr/pipreqs/blob/a593d27e3d9fcdecc0fbf385ef43116cccad71ec/pipreqs/pipreqs.py#L104-L108
https://github.com/bndr/pipreqs/blob/a593d27e3d9fcdecc0fbf385ef43116cccad71ec/pipreqs/pipreqs.py#L143-L144

Contributor guide

Open the contributing guide

Research direction

Start in pipreqs/pipreqs.py at the linked lines around candidate discovery and package handling, then reproduce the commands from the issue with and without .mypy_cache. Done means running pipreqs after mypy still reports requests in the generated requirements rather than treating the cache directory as the import source.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.