bndr / bndr/pipreqs

os.walk() is overkill and may bring wrong packages

Open
#403 2 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

Ni!
Using `os.walk()` in `get_locally_installed_packages()` will break in case a parent directory of multiple python versions slips by accident into `sys.path`. For example, if `sys.path` contains `"/usr/lib/"`, the walk will traverse all packages-like descendant directories, no matter if they're is in `sys.path` or not.

A solution would be to check whether something like `root[ len(path.rstrip(os.sep) + 1):].count(os.sep) == 1` to ensure we only look inside child directories, where python would actually look.

Contributor guide

Open the contributing guide

Research direction

Locate get_locally_installed_packages() and inspect how os.walk() processes each sys.path entry. Reproduce the case with a parent directory such as /usr/lib/ in sys.path, then verify that only direct child package directories are considered rather than deeper descendants.

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
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.