Last active
April 5, 2024 00:44
-
-
Save kobybum/a162be138b2d19e3eac20547a7f10fa3 to your computer and use it in GitHub Desktop.
Finding Unused Python Files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This is part of a Medium article about finding unused files: | |
# https://medium.com/@kobybum/finding-dead-python-files-with-snakefood-6c75a3e82294 | |
# Generate a list of included dependencies | |
sfood -i example-project > /tmp/out.deps | |
# Get dependant filepath from each dependency, sort and get unique | |
cat /tmp/out.deps | \ | |
grep -v test | \ | |
cut -d"'" -f8 | \ | |
sort | \ | |
uniq > /tmp/required.txt | |
# Find all modules in our project | |
find example-project -name '*.py' | \ | |
grep -v "__init__.py" | \ | |
grep -v "test" | \ | |
sort > /tmp/modules.txt | |
# Compare the two, and cleanup | |
diff tmp/modules.py tmp/required.py | grep '<' | cut -d' ' -f2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice
Suggestions:
grep -v -e "__init__.py" -e "test"
CWD=$(pwd)
to get the current working directoy and and use that instead of "example-project" as the starting pointTMP_DIR="/tmp/${CWD}/"
as in"${TMP_DIR}/out.deps"
and then add at the end of the coderm -r "${TMP_DIR}"