|
| 1 | +# Configuration file for the Sphinx documentation builder. |
| 2 | +# |
| 3 | +# This file only contains a selection of the most common options. For a full |
| 4 | +# list see the documentation: |
| 5 | +# https://www.sphinx-doc.org/en/master/usage/configuration.html |
| 6 | + |
| 7 | +# -- Path setup -------------------------------------------------------------- |
| 8 | + |
| 9 | +# If extensions (or modules to document with autodoc) are in another directory, |
| 10 | +# add these directories to sys.path here. If the directory is relative to the |
| 11 | +# documentation root, use os.path.abspath to make it absolute, like shown here. |
| 12 | +# |
| 13 | +import os |
| 14 | +import sys |
| 15 | + |
| 16 | +import sphinx_rtd_theme |
| 17 | + |
| 18 | +# -- Project information ----------------------------------------------------- |
| 19 | + |
| 20 | +project = 'k2' |
| 21 | +copyright = '2020, k2 development team' |
| 22 | +author = 'k2 development team' |
| 23 | + |
| 24 | +# The full version, including alpha/beta/rc tags |
| 25 | +release = '0.0.1' |
| 26 | +version = '0.0.1' |
| 27 | + |
| 28 | +# -- General configuration --------------------------------------------------- |
| 29 | + |
| 30 | +# Add any Sphinx extension module names here, as strings. They can be |
| 31 | +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom |
| 32 | +# ones. |
| 33 | +extensions = [ |
| 34 | + 'sphinx.ext.autodoc', |
| 35 | + 'sphinx.ext.githubpages', |
| 36 | + 'sphinx.ext.linkcode', |
| 37 | + 'sphinx.ext.napoleon', |
| 38 | + 'sphinx_autodoc_typehints', |
| 39 | + 'sphinx_rtd_theme', |
| 40 | +] |
| 41 | + |
| 42 | +# Add any paths that contain templates here, relative to this directory. |
| 43 | +templates_path = ['_templates'] |
| 44 | + |
| 45 | +source_suffix = ['.rst'] |
| 46 | +master_doc = 'index' |
| 47 | + |
| 48 | +# List of patterns, relative to source directory, that match files and |
| 49 | +# directories to ignore when looking for source files. |
| 50 | +# This pattern also affects html_static_path and html_extra_path. |
| 51 | +exclude_patterns = [] |
| 52 | + |
| 53 | +# -- Options for HTML output ------------------------------------------------- |
| 54 | + |
| 55 | +# The theme to use for HTML and HTML Help pages. See the documentation for |
| 56 | +# a list of builtin themes. |
| 57 | +# |
| 58 | +html_theme = 'sphinx_rtd_theme' |
| 59 | +html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] |
| 60 | +html_show_sourcelink = True |
| 61 | + |
| 62 | +# Add any paths that contain custom static files (such as style sheets) here, |
| 63 | +# relative to this directory. They are copied after the builtin static files, |
| 64 | +# so a file named "default.css" will overwrite the builtin "default.css". |
| 65 | +html_static_path = ['_static'] |
| 66 | + |
| 67 | +pygments_style = 'sphinx' |
| 68 | + |
| 69 | +html_context = { |
| 70 | + 'display_github': True, |
| 71 | + 'github_user': 'k2-fsa', |
| 72 | + 'github_repo': 'k2', |
| 73 | + 'github_version': 'master', |
| 74 | + 'conf_py_path': '/k2/docs/source/', |
| 75 | +} |
| 76 | + |
| 77 | +# refer to |
| 78 | +# https://sphinx-rtd-theme.readthedocs.io/en/latest/configuring.html |
| 79 | +html_theme_options = { |
| 80 | + 'logo_only': False, |
| 81 | + 'display_version': True, |
| 82 | + 'prev_next_buttons_location': 'bottom', |
| 83 | + 'style_external_links': True, |
| 84 | +} |
| 85 | + |
| 86 | +autodoc_default_options = { |
| 87 | + 'content': 'both', |
| 88 | + 'members': None, |
| 89 | + 'member-order': 'bysource', |
| 90 | + 'special-members': '__init__', |
| 91 | + 'undoc-members': True, |
| 92 | + 'exclude-members': '__weakref__' |
| 93 | +} |
| 94 | + |
| 95 | + |
| 96 | +# Resolve function for the linkcode extension. |
| 97 | +# Modified from https://github.com/rwth-i6/returnn/blob/master/docs/conf.py |
| 98 | +def linkcode_resolve(domain, info): |
| 99 | + |
| 100 | + def find_source(): |
| 101 | + # try to find the file and line number, based on code from numpy: |
| 102 | + # https://github.com/numpy/numpy/blob/master/doc/source/conf.py#L286 |
| 103 | + obj = sys.modules[info['module']] |
| 104 | + for part in info['fullname'].split('.'): |
| 105 | + obj = getattr(obj, part) |
| 106 | + import inspect |
| 107 | + import os |
| 108 | + fn = inspect.getsourcefile(obj) |
| 109 | + fn = os.path.relpath(fn, start='k2') |
| 110 | + source, lineno = inspect.getsourcelines(obj) |
| 111 | + return fn, lineno, lineno + len(source) - 1 |
| 112 | + |
| 113 | + if domain != 'py' or not info['module']: |
| 114 | + return None |
| 115 | + try: |
| 116 | + filename = '%s#L%d-L%d' % find_source() |
| 117 | + except Exception: |
| 118 | + filename = info['module'].replace('.', '/') + '.py' |
| 119 | + filename = filename.replace('../', '') |
| 120 | + return f'https://github.com/k2-fsa/k2/blob/master/k2/{filename}' |
0 commit comments