|
| 1 | +"""Sphinx configuration.""" |
| 2 | + |
| 3 | +# This file is execfile()d with the current directory set to its containing dir. |
| 4 | +# |
| 5 | +# This file only contains a selection of the most common options. For a full |
| 6 | +# list see the documentation: |
| 7 | +# https://www.sphinx-doc.org/en/master/usage/configuration.html |
| 8 | +# |
| 9 | +# All configuration values have a default; values that are commented out |
| 10 | +# serve to show the default. |
| 11 | + |
| 12 | +import os |
| 13 | +import shutil |
| 14 | +import sys |
| 15 | +from importlib.metadata import metadata |
| 16 | + |
| 17 | +# -- Path setup |
| 18 | + |
| 19 | +__location__ = os.path.dirname(__file__) |
| 20 | + |
| 21 | +# If extensions (or modules to document with autodoc) are in another directory, |
| 22 | +# add these directories to sys.path here. If the directory is relative to the |
| 23 | +# documentation root, use os.path.abspath to make it absolute, like shown here. |
| 24 | +sys.path.insert(0, os.path.join(__location__, "../../src")) |
| 25 | + |
| 26 | +# -- Run sphinx-apidoc |
| 27 | +# This hack is necessary since RTD does not issue `sphinx-apidoc` before running |
| 28 | +# `sphinx-build -b html . _build/html`. See Issue: |
| 29 | +# https://github.com/readthedocs/readthedocs.org/issues/1139 |
| 30 | +# DON'T FORGET: Check the box "Install your project inside a virtualenv |
| 31 | +# Additionally it helps us to avoid running apidoc manually |
| 32 | + |
| 33 | +try: # for Sphinx >= 1.7 |
| 34 | + from sphinx.ext import apidoc |
| 35 | +except ImportError: |
| 36 | + from sphinx import apidoc |
| 37 | + |
| 38 | +output_dir = os.path.join(__location__, "api") |
| 39 | +module_dir = os.path.join(__location__, "../../src/rxn_insight") |
| 40 | +try: |
| 41 | + shutil.rmtree(output_dir) |
| 42 | +except FileNotFoundError: |
| 43 | + pass |
| 44 | + |
| 45 | +try: |
| 46 | + import sphinx |
| 47 | + |
| 48 | + cmd_line = f"sphinx-apidoc --implicit-namespaces -f -o {output_dir} {module_dir}" |
| 49 | + |
| 50 | + args = cmd_line.split(" ") |
| 51 | + if tuple(sphinx.__version__.split(".")) >= ("1", "7"): |
| 52 | + # This is a rudimentary parse_version to avoid external dependencies |
| 53 | + args = args[1:] |
| 54 | + |
| 55 | + apidoc.main(args) |
| 56 | +except Exception as e: |
| 57 | + print(f"Running `sphinx-apidoc` failed!\n{e}") |
| 58 | + |
| 59 | +# -- Project information |
| 60 | + |
| 61 | +_metadata = metadata("rxn_insight") |
| 62 | + |
| 63 | +project = _metadata["Name"] |
| 64 | +author = _metadata["Author-email"].split("<", 1)[0].strip() |
| 65 | +copyright = f"2024, {author}" |
| 66 | + |
| 67 | +version = _metadata["Version"] |
| 68 | +release = ".".join(version.split(".")[:2]) |
| 69 | + |
| 70 | + |
| 71 | +# -- General configuration |
| 72 | + |
| 73 | +extensions = [ |
| 74 | + "myst_parser", |
| 75 | + "sphinx_copybutton", |
| 76 | + "sphinx.ext.autodoc", |
| 77 | + # "sphinx.ext.intersphinx", |
| 78 | + "sphinx.ext.viewcode", |
| 79 | +] |
| 80 | + |
| 81 | +templates_path = ["_templates"] |
| 82 | + |
| 83 | +exclude_patterns = [ |
| 84 | + "Thumbs.db", |
| 85 | + ".DS_Store", |
| 86 | + ".ipynb_checkpoints", |
| 87 | +] |
| 88 | + |
| 89 | +# -- Options for HTML output |
| 90 | + |
| 91 | +html_theme = "furo" |
| 92 | +html_static_path = ["_static"] |
0 commit comments