bndr / bndr/pipreqs

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

Open
#233 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

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()`](https://github.com/bndr/pipreqs/blob/060f52f59774c2fb8e24698da0a74cc7f6cfb8c9/pipreqs/pipreqs.py#L115) 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.

Contributor guide

Open the contributing guide

Research direction

Start in pipreqs/pipreqs.py at get_all_imports(), linked from the issue, and trace how subfolders become entries in candidates and how imports are matched to packages. Reproduce the yaml/PyYaml case, then define and verify behavior for folders with and without __init__.py, including whether warnings are needed and whether existing applications remain unaffected.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.