summaryrefslogtreecommitdiff
path: root/doc/source
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2012-03-11 18:19:36 +0100
committerPauli Virtanen <pav@iki.fi>2012-03-11 18:25:19 +0100
commit39029f56f3851f703eafc77dd83c3d51136c9471 (patch)
treede20da1114496afc9ffd7f4f2c68020acadad5fa /doc/source
parent56f66bb13cfb68fde9172fc9ffc5b9c191c3e320 (diff)
downloadnumpy-39029f56f3851f703eafc77dd83c3d51136c9471.tar.gz
DOC: generate links to source code
Diffstat (limited to 'doc/source')
-rw-r--r--doc/source/conf.py64
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)