|
| 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 | +import logging |
| 8 | +import os |
| 9 | +import sys |
| 10 | +from datetime import datetime |
| 11 | + |
| 12 | +# -- Path setup -------------------------------------------------------------- |
| 13 | + |
| 14 | +# If extensions (or modules to document with autodoc) are in another directory, |
| 15 | +# add these directories to sys.path here. If the directory is relative to the |
| 16 | +# documentation root, use os.path.abspath to make it absolute, like shown here. |
| 17 | +# |
| 18 | +sys.path.insert(0, os.path.abspath("../../")) |
| 19 | + |
| 20 | +from olmo_core.version import VERSION, VERSION_SHORT # noqa: E402 |
| 21 | + |
| 22 | +# -- Project information ----------------------------------------------------- |
| 23 | + |
| 24 | +project = "OLMo-core" |
| 25 | +copyright = f"{datetime.today().year}, Allen Institute for Artificial Intelligence" |
| 26 | +author = "Allen Institute for Artificial Intelligence" |
| 27 | +version = VERSION_SHORT |
| 28 | +release = VERSION |
| 29 | + |
| 30 | + |
| 31 | +# -- General configuration --------------------------------------------------- |
| 32 | + |
| 33 | +# Add any Sphinx extension module names here, as strings. They can be |
| 34 | +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom |
| 35 | +# ones. |
| 36 | +extensions = [ |
| 37 | + "sphinx.ext.autodoc", |
| 38 | + "sphinx.ext.napoleon", |
| 39 | + "myst_parser", |
| 40 | + "sphinx.ext.intersphinx", |
| 41 | + "sphinx.ext.viewcode", |
| 42 | + "sphinx_copybutton", |
| 43 | + "sphinx_autodoc_typehints", |
| 44 | +] |
| 45 | + |
| 46 | +# Tell myst-parser to assign header anchors for h1-h3. |
| 47 | +myst_heading_anchors = 3 |
| 48 | + |
| 49 | +suppress_warnings = ["myst.header"] |
| 50 | + |
| 51 | +# Add any paths that contain templates here, relative to this directory. |
| 52 | +templates_path = ["_templates"] |
| 53 | + |
| 54 | +# List of patterns, relative to source directory, that match files and |
| 55 | +# directories to ignore when looking for source files. |
| 56 | +# This pattern also affects html_static_path and html_extra_path. |
| 57 | +exclude_patterns = ["_build"] |
| 58 | + |
| 59 | +source_suffix = [".rst", ".md"] |
| 60 | + |
| 61 | +intersphinx_mapping = { |
| 62 | + "python": ("https://docs.python.org/3", None), |
| 63 | + "docker": ("https://docker-py.readthedocs.io/en/stable/", None), |
| 64 | + "requests": ("https://requests.readthedocs.io/en/stable/", None), |
| 65 | +} |
| 66 | + |
| 67 | +# By default, sort documented members by type within classes and modules. |
| 68 | +autodoc_member_order = "bysource" |
| 69 | +autodoc_default_options = {"show-inheritance": True, "undoc-members": True} |
| 70 | + |
| 71 | +# Include default values when documenting parameter types. |
| 72 | +typehints_defaults = "comma" |
| 73 | + |
| 74 | +copybutton_prompt_text = r">>> |\.\.\. " |
| 75 | +copybutton_prompt_is_regexp = True |
| 76 | + |
| 77 | +# -- Options for HTML output ------------------------------------------------- |
| 78 | + |
| 79 | +# The theme to use for HTML and HTML Help pages. See the documentation for |
| 80 | +# a list of builtin themes. |
| 81 | +# |
| 82 | +html_theme = "furo" |
| 83 | + |
| 84 | +html_title = f"OLMo-core v{VERSION}" |
| 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 = ["_static"] |
| 90 | + |
| 91 | +html_css_files = ["css/custom.css"] |
| 92 | + |
| 93 | +html_favicon = "_static/favicon.ico" |
| 94 | + |
| 95 | +html_theme_options = { |
| 96 | + "light_logo": "olmo-full-color.png", |
| 97 | + "dark_logo": "olmo-full-color.png", |
| 98 | + "footer_icons": [ |
| 99 | + { |
| 100 | + "name": "GitHub", |
| 101 | + "url": "https://github.com/allenai/OLMo-core", |
| 102 | + "html": """ |
| 103 | + <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16"> |
| 104 | + <path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path> |
| 105 | + </svg> |
| 106 | + """, # noqa: E501 |
| 107 | + "class": "", |
| 108 | + }, |
| 109 | + ], |
| 110 | +} |
| 111 | + |
| 112 | +# -- Hack to get rid of stupid warnings from sphinx_autodoc_typehints -------- |
| 113 | + |
| 114 | + |
| 115 | +class ShutupSphinxAutodocTypehintsFilter(logging.Filter): |
| 116 | + def filter(self, record: logging.LogRecord) -> bool: |
| 117 | + if "Cannot resolve forward reference" in record.msg: |
| 118 | + return False |
| 119 | + if "Failed guarded type import" in record.msg: |
| 120 | + return False |
| 121 | + return True |
| 122 | + |
| 123 | + |
| 124 | +logging.getLogger("sphinx.sphinx_autodoc_typehints").addFilter(ShutupSphinxAutodocTypehintsFilter()) |
| 125 | + |
| 126 | + |
| 127 | +def autodoc_skip_member(app, what, name, obj, skip, options): |
| 128 | + """ |
| 129 | + Skip documenting these Pydantic-specific attributes. |
| 130 | + """ |
| 131 | + del app, what, obj, skip, options |
| 132 | + exclude = name in {"model_config", "model_fields", "model_computed_fields"} |
| 133 | + return True if exclude else None |
| 134 | + |
| 135 | + |
| 136 | +def setup(app): |
| 137 | + app.connect("autodoc-skip-member", autodoc_skip_member) |
0 commit comments