|
| 1 | +import sys |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +root = Path(__file__).absolute().parent.parent |
| 5 | +sys.path.insert(0, str(root)) |
| 6 | + |
| 7 | +DOCSDIR = '.' |
| 8 | +BUILDDIR = '_build' |
| 9 | +TEMPLATESDIR = '_templates' |
| 10 | +STATICDIR = '_static' |
| 11 | +SOURCEDIR = '../edtools' |
| 12 | + |
| 13 | + |
| 14 | +# -- Run apidoc plug-in manually, as readthedocs doesn't support it ------- |
| 15 | +# See https://github.com/rtfd/readthedocs.org/issues/1139 |
| 16 | +def run_apidoc(app): |
| 17 | + ignore_paths = [] |
| 18 | + |
| 19 | + cmd = ('--separate --no-toc --force --module-first ' |
| 20 | + f'-t {TEMPLATESDIR} ' |
| 21 | + f'-o {DOCSDIR} ' |
| 22 | + f'{SOURCEDIR} ') |
| 23 | + |
| 24 | + args = cmd.split() + ignore_paths |
| 25 | + |
| 26 | + from sphinx.ext import apidoc |
| 27 | + apidoc.main(args) |
| 28 | + |
| 29 | + |
| 30 | +# Convert readme.md and others to rst to be included in index.html |
| 31 | +def make_markdown(app): |
| 32 | + import subprocess |
| 33 | + for inp, out in (('../README.md', 'readme.rst'),): |
| 34 | + cmd = f'pandoc --from=markdown --to=rst --output={out} {inp}' |
| 35 | + args = cmd.split() |
| 36 | + subprocess.run(args) |
| 37 | + |
| 38 | + |
| 39 | +# https://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx-core-events |
| 40 | +# https://github.com/readthedocs/readthedocs.org/issues/2276 |
| 41 | +def setup(app): |
| 42 | + app.connect('builder-inited', make_markdown) |
| 43 | + app.connect('builder-inited', run_apidoc) |
| 44 | + |
| 45 | + |
| 46 | +extensions = [ |
| 47 | + 'sphinx.ext.autodoc', |
| 48 | + # 'sphinx.ext.coverage', |
| 49 | + # 'sphinx.ext.doctest', |
| 50 | + # 'sphinx.ext.intersphinx', |
| 51 | + # 'sphinx.ext.mathjax', |
| 52 | + 'sphinx.ext.napoleon', |
| 53 | + # 'nbsphinx', |
| 54 | + # 'nbsphinx_link', |
| 55 | + # 'sphinx.ext.todo', |
| 56 | + # 'sphinx.ext.viewcode', |
| 57 | + 'autodocsumm', |
| 58 | +] |
| 59 | + |
| 60 | +# Add any paths that contain templates here, relative to this directory. |
| 61 | +templates_path = ['_templates'] |
| 62 | + |
| 63 | +# The suffix(es) of source filenames. |
| 64 | +# You can specify multiple suffix as a list of string: |
| 65 | +source_suffix = ['.rst', '.md'] |
| 66 | + |
| 67 | +# The master toctree document. |
| 68 | +master_doc = 'index' |
| 69 | + |
| 70 | +# General information about the project. |
| 71 | +project = 'edtools' |
| 72 | +copyright = '2021, ' |
| 73 | +author = 'Stef Smeets' |
| 74 | + |
| 75 | +# The short X.Y version. |
| 76 | +version = release = '1.0.0' |
| 77 | + |
| 78 | +# The language for content autogenerated by Sphinx. |
| 79 | +language = 'english' |
| 80 | + |
| 81 | +# List of patterns, relative to source directory, that match files and |
| 82 | +# directories to ignore when looking for source files. |
| 83 | +# This patterns also effect to html_static_path and html_extra_path |
| 84 | +exclude_patterns = [BUILDDIR, 'Thumbs.db', '.DS_Store'] |
| 85 | + |
| 86 | +# Add any paths that contain custom static files (such as style sheets) here, |
| 87 | +# relative to this directory. They are copied after the builtin static files, |
| 88 | +# so a file named "default.css" will overwrite the builtin "default.css". |
| 89 | +html_static_path = [STATICDIR] |
| 90 | + |
| 91 | +# The name of the Pygments (syntax highlighting) style to use. |
| 92 | +pygments_style = 'sphinx' |
| 93 | + |
| 94 | +# If true, `todo` and `todoList` produce output, else they produce nothing. |
| 95 | +todo_include_todos = False |
| 96 | + |
| 97 | +# Use autoapi.extension to run sphinx-apidoc |
| 98 | +autoapi_dirs = [SOURCEDIR] |
| 99 | + |
| 100 | +# The theme to use for HTML and HTML Help pages. See the documentation for |
| 101 | +# a list of builtin themes. |
| 102 | +html_theme = 'sphinx_rtd_theme' |
| 103 | +# options for rtd-theme |
| 104 | +# html_theme_options = { |
| 105 | +# 'display_version': True, |
| 106 | +# 'prev_next_buttons_location': 'bottom', |
| 107 | +# 'style_external_links': False, |
| 108 | +# # toc options |
| 109 | +# 'collapse_navigation': True, |
| 110 | +# 'sticky_navigation': True, |
| 111 | +# 'navigation_depth': 4, |
| 112 | +# 'includehidden': True, |
| 113 | +# 'titles_only': False, |
| 114 | +# } |
| 115 | + |
| 116 | +autodoc_default_options = { |
| 117 | + 'autosummary': True, |
| 118 | + 'special-members': '__init__', |
| 119 | +} |
| 120 | + |
| 121 | +autodoc_mock_imports = [ |
| 122 | + 'cctbx', |
| 123 | + 'iotbx', |
| 124 | + 'importlib_metadata' |
| 125 | +] |
| 126 | + |
| 127 | +intersphinx_mapping = { |
| 128 | + 'python': ('https://docs.python.org/3', None), |
| 129 | + 'numpy': ('https://docs.scipy.org/doc/numpy/', None), |
| 130 | + 'scipy': ('https://docs.scipy.org/doc/scipy/reference/', None), |
| 131 | + 'scikit-image': ('https://scikit-image.org/docs/stable/', None), |
| 132 | + 'matplotlib': ('https://matplotlib.org/stable/', None), |
| 133 | +} |
0 commit comments