Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: add source links to api docs #14200

Merged
merged 1 commit into from
Sep 12, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import sys
import os
import re
import inspect
from pandas.compat import u, PY3

# If extensions (or modules to document with autodoc) are in another directory,
Expand Down Expand Up @@ -47,6 +48,7 @@
'sphinx.ext.coverage',
'sphinx.ext.pngmath',
'sphinx.ext.ifconfig',
'sphinx.ext.linkcode',
]


Expand Down Expand Up @@ -424,6 +426,55 @@ def get_items(self, names):
return items


# based on numpy doc/source/conf.py
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.getsourcelines(obj)
except:
lineno = None

if lineno:
linespec = "#L%d-L%d" % (lineno, lineno + len(source) - 1)
else:
linespec = ""

fn = os.path.relpath(fn, start=os.path.dirname(pandas.__file__))

if '+' in pandas.__version__:
return "http://github.com/pydata/pandas/blob/master/pandas/%s%s" % (
fn, linespec)
else:
return "http://github.com/pydata/pandas/blob/v%s/pandas/%s%s" % (
pandas.__version__, fn, linespec)


# remove the docstring of the flags attribute (inherited from numpy ndarray)
# because these give doc build errors (see GH issue 5331)
def remove_flags_docstring(app, what, name, obj, options, lines):
Expand Down