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

Subfolders with the same name as a package prevent the package from being added #233

Open liem-dq opened 3 years ago

liem-dq commented 3 years ago

Having a subfolder with the same name as a package will silently prevent that package from being added to requirements.txt. For example, having a subfolder called yaml in a repository will prevent PyYaml from being added. This appears to be the issue in

181 and #187.

One (partial) solution would be to check if the folder contains __init__.py, and if it does not, remove it from the candidates list in the get_all_imports() function , as it cannot (or at least shouldn't) be used as an import anyway. Another feature that could be helpful would be to check for items that are common to both imports and candidates, and then check if they map to a valid PyPi package, and then emit a warning that they are being suppressed.

I'm unsure if this could lead to unintended effects or break existing applications, but if this seems like a good idea I'm happy to implement it myself and submit a PR.