bndr / pipreqs

pipreqs - Generate pip requirements.txt file based on imports of any project. Looking for maintainers to move this project forward.
Apache License 2.0
6.38k stars 388 forks source link

mypy cache folder causes generated requirements to be empty #330

Open cebtenzzre opened 2 years ago

cebtenzzre commented 2 years ago

Related to #73.

Steps to reproduce

$ 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