Skip to content

Instantly share code, notes, and snippets.

@jdunck
Created January 24, 2013 05:14
Show Gist options
  • Select an option

  • Save jdunck/4617846 to your computer and use it in GitHub Desktop.

Select an option

Save jdunck/4617846 to your computer and use it in GitHub Desktop.
dirty groping for required module versions of an arbitrary python codebase.
find . -iname '*.py' -type f | xargs grep 'import' | awk -F':' '{print $2}' | sed -E 's/ +$//g' | sed -E 's/^[ :tab:]+//g' | sort| uniq | python -c '
import sys
for line in sys.stdin.readlines():
try:
exec line
except:
print >> sys.stderr, "failed to exec %s" % line
def ver(mod):
for attempt in ["__version__", "VERSION", "__VERSION__"]:
if hasattr(mod, attempt):
return getattr(mod, attempt)
return None
for mod in sys.modules.keys():
this_ver = ver(sys.modules[mod])
if this_ver is None:
print >>sys.stderr, mod, this_ver
else:
print mod, this_ver
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment