Skip to content

Instantly share code, notes, and snippets.

@megies
Last active November 25, 2015 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save megies/af7c092f1214d834159c to your computer and use it in GitHub Desktop.
Save megies/af7c092f1214d834159c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import inspect
import re
from importlib import import_module
from pkgutil import walk_packages
from types import ModuleType
import obspy
from future.builtins import __all__ as future_builtins_names
def recursive_list(name, module, root=False):
if name in future_builtins_names:
return
# if we end up in obspy top-level from inside obspy, just ignore
if not root and module == obspy:
return
try:
obj = getattr(module, name)
except:
# getting tests from modules somehow not works (without importing the
# module again first, but we're not concerned about this particular
# import..)
if name == "tests" or module.__name__ == "obspy.lib":
return
# ignore precompiled extensions
if module.__name__ == "obspy.lib":
return
obj = import_module("." + name, module.__name__)
# check if the source file is in obspy package tree
try:
sourcefile = inspect.getsourcefile(obj) or inspect.getsourcefile(module)
except:
return
if not sourcefile:
return
if not re.match(r'/home/megies/anaconda/envs/stable/lib/python2.7/site-packages/obspy-0.10.2-py2.7-linux-x86_64.egg', sourcefile):
return
# recurse
is_module = isinstance(obj, ModuleType)
if is_module:
names = dir(obj)
if "__path__" in names:
names += [pkg[1].split(".")[0]
for pkg in walk_packages(obj.__path__)]
for name_ in sorted(set(names)):
if "." in name_:
from IPython.core.debugger import Tracer; Tracer(colors="Linux")()
recursive_list(name_, obj)
# print info on object
print("%s %s %s" % (str(is_module).ljust(6), module.__name__.ljust(50),
name))
if __name__ == "__main__":
num = len(dir(obspy))
names = (dir(obspy) +
[pkg[1].split(".")[0]
for pkg in walk_packages(obspy.__path__)])
for i_, name in enumerate(sorted(set(names))):
# somehow we end up in the obspy root again, so explicitely mark this
# as only allowed top-level
# n.b. this is coming from obspy.station.stationxml.py
# which has an 'import obspy' line..
recursive_list(name, obspy, root=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment