Created
August 22, 2016 12:07
-
-
Save lenolib/231799fa60b9ff444e5d21f16b91f3a8 to your computer and use it in GitHub Desktop.
Find python imports in current directory that are not part of the python standard library
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
# Find python imports in current directory that are not part of the python standard library | |
function non-stdlib-imports () { | |
# Requires isort to be pip-installed | |
stdlib_mods=`python -c "import isort, sys; sys.stdout.write('|'.join(isort.settings.default['known_standard_library']))"` | |
non_stdlib_used_mods=`grep "import " $(find . -name "*.py") | cut -f2 -d ' ' | cut -f1 -d'.' | sort | uniq | grep -v -E $stdlib_mods` | |
grep -nRE "$non_stdlib_used_mods" | grep -e "import.* " -e "from.* " | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment