Files
openfe/docs/conf.py
Mike Henry b0789ff0ae Add logging control (#1585)
* do we test this at all?

* start of logging improvements

* first pass at logging, worried about performance

* setup a base class + add type hints

* add placeholder url ref

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* update to new logging control

* Fix imports

* remove bit left over from being able to delete these log controlers

* looks like ... is used more than pass

* formatting fix

* Grab new format rule from main

* run ruff check --fix on conflicting files

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Added tests

* see if this fixes the doc build

* add back debugging code

* update openmm doc url

* add note about jax warning

* bump

* Remove debugging code to see if that fixes doc build

* ruff format

* Add url

* switch to using module instead of class w/ static methods

* Update docs/guide/troubleshooting.rst

Co-authored-by: Alyssa Travitz <31974495+atravitz@users.noreply.github.com>

* ruff fixes

* Ruff fix

* Added news entry

* Refactor to move things to private namespace

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Alyssa Travitz <31974495+atravitz@users.noreply.github.com>
2025-11-21 07:30:53 -08:00

250 lines
7.4 KiB
Python

# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
from importlib.metadata import version
from inspect import cleandoc
from pathlib import Path
import nbformat
import nbsphinx
from git import Repo
from packaging.version import parse
sys.path.insert(0, os.path.abspath("../"))
os.environ["SPHINX"] = "True"
# -- Project information -----------------------------------------------------
project = "OpenFE"
copyright = "2022, The OpenFE Development Team"
author = "The OpenFE Development Team"
# don't include patch version (https://github.com/OpenFreeEnergy/openfe/issues/1261)
version = f"{parse(version('openfe')).major}.{parse(version('openfe')).minor}"
# -- General configuration ---------------------------------------------------
# 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",
"sphinx.ext.napoleon",
"sphinx_click.ext",
"sphinxcontrib.autodoc_pydantic",
"sphinx_toolbox.collapse",
"sphinx.ext.autosectionlabel",
"sphinx_design",
"sphinx.ext.intersphinx",
"sphinx.ext.autosummary",
"docs._ext.sass",
"myst_parser",
"nbsphinx",
"nbsphinx_link",
"sphinx.ext.mathjax",
]
suppress_warnings = ["config.cache"] # https://github.com/sphinx-doc/sphinx/issues/12300
intersphinx_mapping = {
"python": ("https://docs.python.org/3.9", None),
"numpy": ("https://numpy.org/doc/stable", None),
"scikit.learn": ("https://scikit-learn.org/stable", None),
"openmm": ("https://docs.openmm.org/latest/api-python/", None),
"rdkit": ("https://www.rdkit.org/docs", None),
"openeye": ("https://docs.eyesopen.com/toolkits/python/", None),
"mdtraj": ("https://www.mdtraj.org/1.9.5/", None),
"openff.units": ("https://docs.openforcefield.org/projects/units/en/stable", None),
"gufe": ("https://gufe.openfree.energy/en/latest/", None),
}
autoclass_content = "both"
# Make sure labels are unique
# https://www.sphinx-doc.org/en/master/usage/extensions/autosectionlabel.html#confval-autosectionlabel_prefix_document
autosectionlabel_prefix_document = True
autodoc_pydantic_model_show_json = False
autodoc_default_options = {
"members": True,
"member-order": "bysource",
"inherited-members": "GufeTokenizable,BaseModel",
"undoc-members": True,
"special-members": "__call__",
}
toc_object_entries_show_parents = "hide"
# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = [
"_build",
"**/Thumbs.db",
"**/.DS_Store",
"_ext",
"_sass",
"**/README.md",
"ExampleNotebooks",
]
autodoc_mock_imports = [
"MDAnalysis",
"matplotlib",
"mdtraj",
"openfe_analysis",
"openmmforcefields",
"openmmtools",
"pymbar",
"openff.interchange",
"openmmforcefields",
"psutil",
"py3Dmol",
]
# Extensions for the myst parser
myst_enable_extensions = [
"dollarmath",
"colon_fence",
"smartquotes",
"replacements",
"deflist",
"attrs_inline",
]
myst_heading_anchors = 3
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "ofe_sphinx_theme"
html_theme_options = {
"logo": {"text": "OpenFE docs"},
"icon_links": [
{
"name": "GitHub",
"url": "https://github.com/OpenFreeEnergy/openfe",
"icon": "fa-brands fa-square-github",
"type": "fontawesome",
}
],
"accent_color": "cantina-purple",
"navigation_with_keys": False,
}
html_logo = "_static/OFE-color-icon.svg"
html_favicon = "_static/OFE-color-icon.svg"
# temporary fix, see https://github.com/pydata/pydata-sphinx-theme/issues/1662
html_sidebars = {
"installation": [],
"CHANGELOG": [],
}
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
# html_static_path = ['_static']
# replace macros
rst_prolog = """
.. |rdkit.mol| replace:: :class:`rdkit.Chem.rdchem.Mol`
"""
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]
html_css_files = [
"css/custom.css",
"css/custom-api.css",
"css/deflist-flowchart.css",
]
# custom-api.css is compiled from custom-api.scss
sass_src_dir = "_sass"
sass_out_dir = "_static/css"
# Clone or update ExampleNotebooks
example_notebooks_path = Path("ExampleNotebooks")
try:
if example_notebooks_path.exists():
repo = Repo(example_notebooks_path)
repo.remote("origin").pull()
else:
repo = Repo.clone_from(
"https://github.com/OpenFreeEnergy/ExampleNotebooks.git",
branch="2025.10.2",
to_path=example_notebooks_path,
)
except Exception as e:
from sphinx.util.logging import getLogger
filename = e.__traceback__.tb_frame.f_code.co_filename
lineno = e.__traceback__.tb_lineno
getLogger("sphinx.ext.openfe_git").warning(
f"Getting ExampleNotebooks failed in {filename} line {lineno}: {e}"
)
# First, create links at top of notebook pages
# All notebooks are in ExampleNotebooks repo, so link to that
# Finally, add sphinx reference anchor in prolog so that we can make refs
nbsphinx_prolog = cleandoc(r"""
{%- set gh_repo = "OpenFreeEnergy/ExampleNotebooks" -%}
{%- set gh_branch = "main" -%}
{%- set path = env.doc2path(env.docname, base=None) -%}
{%- if path.endswith(".nblink") -%}
{%- set path = env.metadata[env.docname]["nbsphinx-link-target"] -%}
{%- endif -%}
{%- if path.startswith("ExampleNotebooks/") -%}
{%- set path = path.replace("ExampleNotebooks/", "", 1) -%}
{%- endif -%}
{%- set gh_url =
"https://www.github.com/"
~ gh_repo
~ "/blob/"
~ gh_branch
~ "/"
~ path
-%}
{%- set dl_url =
"https://raw.githubusercontent.com/"
~ gh_repo
~ "/"
~ gh_branch
~ "/"
~ path
-%}
.. container:: ofe-top-of-notebook
.. button-link:: {{gh_url}}
:color: primary
:shadow:
:outline:
:octicon:`mark-github` View on GitHub
.. button-link:: {{dl_url}}
:color: primary
:shadow:
:outline:
:octicon:`download` Download Notebook
.. _{{ env.doc2path(env.docname, base=None) }}:
""")