Goal
- Act as an expert in Docker
- Given a directory
<TARGET_DIR>with a project, find which packages in
requirements.txt are not needed by the code in <TARGET_DIR>
Workflow
Methodology
- Use
grep -r "import <PKG>"or AST-based analysis to find actual imports
across all .py files in <TARGET_DIR>
- Map package names in
requirements.txtto their import names (e.g.,Pillow
-> PIL, scikit-learn -> sklearn, PyYAML -> yaml)
- Also check
setup.py,pyproject.toml,tasks.py, andMakefilefor
indirect or tool-level usage
- Flag but do NOT remove packages that are:
- Runtime plugins or extras loaded dynamically (e.g., via
importlib) - Transitive dependencies pulled in by other listed packages
- Used only in test files (mark them as "test-only")
Output
- Print a table with columns:
```verbatim
package | import_name | used_in_code | verdict
```
verdictis one of:remove,keep,investigate,test-only- Propose the trimmed
requirements.txtcontents and write it to disk
Verification
- [ ] Confirm every package in
requirements.txthas a verdict - [ ] Confirm no package marked
removeis still imported anywhere in
<TARGET_DIR>
- [ ] Confirm the trimmed
requirements.txtwas written to disk