2023-07-21 14:54:09 +01:00
|
|
|
# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK
|
2023-03-28 17:33:34 +01:00
|
|
|
# Configuration file for the Sphinx documentation builder.
|
|
|
|
|
#
|
|
|
|
|
# For the full list of built-in configuration values, see the documentation:
|
|
|
|
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
|
|
|
|
|
2023-05-25 11:42:19 +01:00
|
|
|
import datetime
|
|
|
|
|
|
2023-03-28 17:33:34 +01:00
|
|
|
# -- Project information -----------------------------------------------------
|
|
|
|
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
|
2023-05-25 10:52:29 +01:00
|
|
|
import os
|
2024-05-14 07:36:29 +01:00
|
|
|
import shutil
|
2023-05-25 10:52:29 +01:00
|
|
|
import sys
|
2024-05-14 07:36:29 +01:00
|
|
|
from pathlib import Path
|
2024-03-14 23:17:34 +00:00
|
|
|
from typing import Any
|
2023-05-25 11:42:19 +01:00
|
|
|
|
|
|
|
|
import furo # noqa
|
|
|
|
|
|
2023-05-25 10:52:29 +01:00
|
|
|
sys.path.insert(0, os.path.abspath("../"))
|
2023-03-28 17:33:34 +01:00
|
|
|
|
2023-05-25 10:52:29 +01:00
|
|
|
# -- Project information -----------------------------------------------------
|
|
|
|
|
year = datetime.datetime.now().year
|
2023-06-08 15:57:38 +01:00
|
|
|
project = "PrimAITE"
|
2023-07-21 14:00:50 +01:00
|
|
|
copyright = f"Copyright (C) Defence Science and Technology Laboratory UK 2021 - {year}"
|
|
|
|
|
author = "Defence Science and Technology Laboratory UK"
|
2023-05-25 10:52:29 +01:00
|
|
|
|
|
|
|
|
# The short Major.Minor.Build version
|
|
|
|
|
with open("../src/primaite/VERSION", "r") as file:
|
|
|
|
|
version = file.readline()
|
|
|
|
|
# The full version, including alpha/beta/rc tags
|
|
|
|
|
release = version
|
2023-03-28 17:33:34 +01:00
|
|
|
|
2024-02-23 08:55:32 +00:00
|
|
|
# set global variables
|
|
|
|
|
rst_prolog = f"""
|
|
|
|
|
.. |VERSION| replace:: {release}
|
|
|
|
|
"""
|
|
|
|
|
|
2023-06-08 15:57:38 +01:00
|
|
|
html_title = f"{project} v{release} docs"
|
|
|
|
|
|
2023-03-28 17:33:34 +01:00
|
|
|
# -- General configuration ---------------------------------------------------
|
|
|
|
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
|
|
|
|
|
2023-06-08 15:57:38 +01:00
|
|
|
# Add any Sphinx extension module names here, as strings. They can be
|
|
|
|
|
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
|
|
|
|
# ones.
|
|
|
|
|
extensions = [
|
|
|
|
|
"sphinx.ext.autodoc", # Core Sphinx library for auto html doc generation from docstrings
|
2024-05-14 07:36:29 +01:00
|
|
|
# "sphinx.ext.autosummary", # Create summary tables for modules/classes/methods etc
|
2023-06-08 15:57:38 +01:00
|
|
|
"sphinx.ext.intersphinx", # Link to other project's documentation (see mapping below)
|
|
|
|
|
"sphinx.ext.viewcode", # Add a link to the Python source code for classes, functions etc.
|
|
|
|
|
"sphinx.ext.todo",
|
|
|
|
|
"sphinx_copybutton", # Adds a copy button to code blocks
|
2024-05-14 07:36:29 +01:00
|
|
|
"nbsphinx",
|
2023-06-08 15:57:38 +01:00
|
|
|
]
|
|
|
|
|
|
2023-05-25 10:52:29 +01:00
|
|
|
templates_path = ["_templates"]
|
2024-02-16 16:14:36 +00:00
|
|
|
exclude_patterns = [
|
|
|
|
|
"_build",
|
|
|
|
|
"Thumbs.db",
|
|
|
|
|
".DS_Store",
|
|
|
|
|
]
|
2023-03-28 17:33:34 +01:00
|
|
|
|
|
|
|
|
# -- Options for HTML output -------------------------------------------------
|
|
|
|
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
|
|
|
|
|
2023-05-25 10:52:29 +01:00
|
|
|
html_theme = "furo"
|
|
|
|
|
html_static_path = ["_static"]
|
2024-02-16 16:14:36 +00:00
|
|
|
html_theme_options = {"globaltoc_collapse": True, "globaltoc_maxdepth": 2}
|
|
|
|
|
html_copy_source = False
|
2024-05-14 07:36:29 +01:00
|
|
|
nbsphinx_allow_errors = True
|
2024-05-09 13:43:55 +01:00
|
|
|
|
|
|
|
|
|
2024-03-14 23:17:34 +00:00
|
|
|
def replace_token(app: Any, docname: Any, source: Any):
|
|
|
|
|
"""Replaces a token from the list of tokens."""
|
|
|
|
|
result = source[0]
|
|
|
|
|
for key in app.config.tokens:
|
|
|
|
|
result = result.replace(key, app.config.tokens[key])
|
|
|
|
|
source[0] = result
|
|
|
|
|
|
|
|
|
|
|
2024-05-09 13:43:55 +01:00
|
|
|
tokens = {
|
|
|
|
|
"{VERSION}": release,
|
|
|
|
|
} # Token VERSION is replaced by the value of the PrimAITE version in the version file
|
2024-03-14 23:17:34 +00:00
|
|
|
"""Dict containing the tokens that need to be replaced in documentation."""
|
|
|
|
|
|
2024-05-14 07:36:29 +01:00
|
|
|
temp_ignored_notebooks = ["Training-an-RLLib-Agent.ipynb", "Training-an-RLLIB-MARL-System.ipynb"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def copy_notebooks_to_docs():
|
|
|
|
|
"""Copies the notebooks to a directory within docs directory so that they can be included."""
|
|
|
|
|
for notebook in Path("../src/primaite").rglob("*.ipynb"):
|
|
|
|
|
if notebook.name not in temp_ignored_notebooks:
|
|
|
|
|
dest = Path("source") / "notebooks"
|
|
|
|
|
Path(dest).mkdir(parents=True, exist_ok=True)
|
|
|
|
|
shutil.copy2(src=notebook, dst=dest)
|
|
|
|
|
|
|
|
|
|
# copy any images
|
|
|
|
|
# TODO
|
|
|
|
|
|
2024-03-14 23:17:34 +00:00
|
|
|
|
|
|
|
|
def setup(app: Any):
|
|
|
|
|
"""Custom setup for sphinx."""
|
2024-05-14 07:36:29 +01:00
|
|
|
copy_notebooks_to_docs()
|
2024-03-14 23:17:34 +00:00
|
|
|
app.add_config_value("tokens", {}, True)
|
|
|
|
|
app.connect("source-read", replace_token)
|