bndr / bndr/pipreqs

modules candidates should have __init__.py file

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

pipreqs was failing to include the root `Django` package, depending on what subdirectory I ran it over. This was due to the existence of a `logs/django` directory. I added a check for `__init__.py` and the total packages found jump by 8, up to 76. It turned out that `node_modules` directory was obscuring a bunch more (I should have --ignored it, of course).

The fix was a simple change to `get_all_imports()`:

```
for root, dirs, files in walk:
dirs[:] = [d for d in dirs if d not in ignore_dirs]

candidate = os.path.basename(root)
initfile = os.path.join(candidate, '__init__.py')
if os.path.exists(initfile):
candidates.append(candidate)
```

I'm not sure if this is a universal improvement, so didn't make a PR for it yet. Certainly, more thought needs to be given to submodules and, more broadly, relative imports.

Contributor guide

Open the contributing guide

Research direction

Start with get_all_imports() and reproduce the missing-root-package case from different project subdirectories, including a logs/django directory and node_modules. Check how candidate package directories and ignored directories are discovered. Done means package detection is consistent without false positives and the behavior around submodules and relative imports is resolved.

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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.