def resolve_linkrole(name, text, check=True): |
apigen_relpath = get_apigen_relpath() |
if name == 'api': |
if text == 'py': |
return ('py', apigen_relpath + 'api/index.html') |
else: |
assert text.startswith('py.'), ( |
'api link "%s" does not point to the py package') % (text,) |
dotted_name = text |
if dotted_name.find('(') > -1: |
dotted_name = dotted_name[:text.find('(')] |
|
path = dotted_name.split('.')[1:] |
dotted_name = '.'.join(path) |
obj = py |
if check: |
for chunk in path: |
try: |
obj = getattr(obj, chunk) |
except AttributeError: |
raise AssertionError( |
'problem with linkrole :api:`%s`: can not resolve ' |
-> 'dotted name %s' % (text, dotted_name,)) |
return (text, apigen_relpath + 'api/%s.html' % (dotted_name,)) |
elif name == 'source': |
assert text.startswith('py/'), ('source link "%s" does not point ' |
'to the py package') % (text,) |
relpath = '/'.join(text.split('/')[1:]) |
if check: |
pkgroot = py.__pkg__.getpath() |
abspath = pkgroot.join(relpath) |
assert pkgroot.join(relpath).check(), ( |
'problem with linkrole :source:`%s`: ' |
'path %s does not exist' % (text, relpath)) |
if relpath.endswith('/') or not relpath: |
relpath += 'index.html' |
else: |
relpath += '.html' |
return (text, apigen_relpath + 'source/%s' % (relpath,)) |