| 1 |
import sys |
| 2 |
from pathlib import Path |
| 3 |
|
| 4 |
from sphinx.ext.linkcode import add_linkcode_domain |
| 5 |
|
| 6 |
sys.path.insert(0, str(Path.cwd().resolve())) |
| 7 |
|
| 8 |
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode'] |
| 9 |
exclude_patterns = ['_build'] |
| 10 |
|
| 11 |
|
| 12 |
if 'test_linkcode' in tags: # NoQA: F821 (tags is injected into conf.py) |
| 13 |
extensions.remove('sphinx.ext.viewcode') |
| 14 |
extensions.append('sphinx.ext.linkcode') |
| 15 |
|
| 16 |
def linkcode_resolve(domain, info): |
| 17 |
if domain == 'py': |
| 18 |
fn = info['module'].replace('.', '/') |
| 19 |
return 'https://foobar/source/%s.py' % fn |
| 20 |
elif domain == 'js': |
| 21 |
return 'https://foobar/js/' + info['fullname'] |
| 22 |
elif domain in {'c', 'cpp'}: |
| 23 |
return f'https://foobar/{domain}/{"".join(info["names"])}' |
| 24 |
elif domain == 'rst': |
| 25 |
return 'http://foobar/rst/{fullname}'.format(**info) |
| 26 |
else: |
| 27 |
raise AssertionError |
| 28 |
|
| 29 |
def setup(app): |
| 30 |
add_linkcode_domain('rst', ['fullname']) |