Skip to content

Instantly share code, notes, and snippets.

@lenolib
Created August 22, 2016 12:07
Show Gist options
  • Save lenolib/231799fa60b9ff444e5d21f16b91f3a8 to your computer and use it in GitHub Desktop.
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
# 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