diff options
Diffstat (limited to 'doc/source/conf.py')
-rw-r--r-- | doc/source/conf.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/doc/source/conf.py b/doc/source/conf.py index 72083cc95..de9f6adf3 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -286,3 +286,67 @@ plot_rcparams = { if not use_matplotlib_plot_directive: import matplotlib matplotlib.rcParams.update(plot_rcparams) + +# ----------------------------------------------------------------------------- +# Source code links +# ----------------------------------------------------------------------------- + +import inspect +from os.path import relpath, dirname + +for name in ['sphinx.ext.linkcode', 'linkcode', 'numpydoc.linkcode']: + try: + __import__(name) + extensions.append(name) + break + except ImportError: + pass +else: + print "NOTE: linkcode extension not found -- no links to source generated" + +def linkcode_resolve(domain, info): + """ + Determine the URL corresponding to Python object + """ + if domain != 'py': + return None + + modname = info['module'] + fullname = info['fullname'] + + submod = sys.modules.get(modname) + if submod is None: + return None + + obj = submod + for part in fullname.split('.'): + try: + obj = getattr(obj, part) + except: + return None + + try: + fn = inspect.getsourcefile(obj) + except: + fn = None + if not fn: + return None + + try: + source, lineno = inspect.findsource(obj) + except: + lineno = None + + if lineno: + linespec = "#L%d" % (lineno + 1) + else: + linespec = "" + + fn = relpath(fn, start=dirname(numpy.__file__)) + + if 'dev' in numpy.__version__: + return "http://github.com/numpy/numpy/blob/master/numpy/%s%s" % ( + fn, linespec) + else: + return "http://github.com/numpy/numpy/blob/v%s/numpy/%s%s" % ( + numpy.__version__, fn, linespec) |