1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
|
from __future__ import annotations
import sys
from datetime import datetime
from functools import partial
from typing import TYPE_CHECKING, Any
from unittest import mock
from polyfactory.__metadata__ import __project__, __version__
if TYPE_CHECKING:
from sphinx.addnodes import document # type: ignore[attr-defined]
from sphinx.application import Sphinx
for mod_name in ("beanie", "odmantic"):
sys.modules[mod_name] = mock.Mock()
PY_CLASS = "py:class"
PY_RE = r"py:.*"
# -- Environmental Data ------------------------------------------------------
# -- Project information -----------------------------------------------------
current_year = datetime.now().year
project = __project__
copyright = f"{current_year}, Litestar Organization"
release = __version__
extensions = [
"sphinx.ext.intersphinx",
"sphinx.ext.autosectionlabel",
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
"sphinx_design",
"auto_pytabs.sphinx_ext",
"sphinx_copybutton",
"sphinx.ext.viewcode",
"sphinx.ext.todo",
"sphinx.ext.viewcode",
"sphinx_toolbox.collapse",
"sphinx_togglebutton",
"sphinx_paramlinks",
]
intersphinx_mapping = {
"python": ("/usr/share/doc/python3-doc/html", None),
"faker": ("/usr/share/doc/faker-doc/html", None),
"pytest": ("/usr/share/doc/python-pytest-doc/html", None),
"msgspec": ("/usr/share/doc/python-msgspec-doc/html", None),
}
nitpicky = True
nitpick_ignore = [
(PY_CLASS, "BaseModel"),
(PY_CLASS, "Decimal"),
(PY_CLASS, "Faker"),
(PY_CLASS, "FieldInfo"),
(PY_CLASS, "Random"),
(PY_CLASS, "Scope"),
(PY_CLASS, "T"),
(PY_CLASS, "F"),
(PY_CLASS, "P"),
(PY_CLASS, "P.args"),
(PY_CLASS, "P.kwargs"),
(PY_CLASS, "Self"),
(PY_CLASS, "TypeGuard"),
(PY_CLASS, "date"),
(PY_CLASS, "tzinfo"),
(PY_CLASS, "BeanieDocumentFactory"),
(PY_CLASS, "OdmanticModelFactory"),
(PY_CLASS, "ModelField"),
(PY_CLASS, "Session"),
(PY_CLASS, "AsyncSession"),
]
nitpick_ignore_regex = [
(PY_RE, r"typing_extensions.*"),
(PY_RE, r"polyfactory.*\.T"),
(PY_RE, r"polyfactory.*\.P"),
(PY_RE, r".*TypedDictT"),
(PY_RE, r"pydantic.*"),
(PY_RE, r"msgspec.*"),
]
suppress_warnings = [
"autosectionlabel.*",
"ref.python", # TODO: remove when https://github.com/sphinx-doc/sphinx/issues/4961 is fixed
"config.cache",
]
napoleon_google_docstring = True
napoleon_include_special_with_doc = True
napoleon_use_admonition_for_examples = True
napoleon_use_admonition_for_notes = True
napoleon_use_admonition_for_references = False
napoleon_attr_annotations = True
autoclass_content = "class"
autodoc_class_signature = "separated"
autodoc_default_options = {
"special-members": True,
"show-inheritance": True,
"members": True,
"exclude-members": "__init_subclass__,__weakref__,__subclasshook__",
}
autodoc_member_order = "bysource"
autodoc_typehints_format = "short"
auto_pytabs_min_version = (3, 8)
auto_pytabs_max_version = (3, 11)
auto_pytabs_compat_mode = True
autosectionlabel_prefix_document = True
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
# -- Style configuration -----------------------------------------------------
html_theme = "sphinx_rtd_theme"
html_title = "Polyfactory"
# pygments_style = "lightbulb"
todo_include_todos = True
html_static_path = ["_static"]
templates_path = ["_templates"]
#html_js_files = ["versioning.js"]
html_css_files = ["style.css"]
html_show_sourcelink = True
html_copy_source = True
html_context = {
"source_type": "github",
"source_user": "litestar-org",
"source_repo": "polyfactory",
"current_version": "latest",
"versions": [
("latest", "/latest"),
("development", "/main"),
],
"version": release,
}
html_theme_options = {
"logo_target": "/",
"github_repo_name": "polyfactory",
"github_url": "https://github.com/litestar-org/polyfactory",
"navigation_with_keys": True,
"nav_links": [
{"title": "Home", "url": "index"},
{
"title": "Community",
"children": [
{
"title": "Contributing",
"summary": "Learn how to contribute to the Type Lens project",
"url": "contribution-guide",
"icon": "contributing",
},
{
"title": "Code of Conduct",
"summary": "Review the etiquette for interacting with the Litestar community",
"url": "https://github.com/litestar-org/.github?tab=coc-ov-file",
"icon": "coc",
},
{
"title": "Security",
"summary": "Overview of Litestar's security protocols",
"url": "https://github.com/litestar-org/.github?tab=coc-ov-file#security-ov-file",
"icon": "coc",
},
],
},
{
"title": "About",
"children": [
{
"title": "Litestar Organization",
"summary": "Details about the Litestar organization",
"url": "https://litestar.dev/about/organization",
"icon": "org",
},
{
"title": "Releases",
"summary": "Explore the release process, versioning, and deprecation policy for Litestar",
"url": "releases",
"icon": "releases",
},
],
},
{
"title": "Release notes",
"children": [
{
"title": "Changelog",
"url": "changelog",
"summary": "All changes in the current major version",
},
],
},
{
"title": "Help",
"children": [
{
"title": "Discord Help Forum",
"summary": "Dedicated Discord help forum",
"url": "https://discord.gg/litestar",
"icon": "coc",
},
{
"title": "GitHub Discussions",
"summary": "GitHub Discussions",
"url": "https://github.com/litestar-org/polyfactory/discussions",
"icon": "coc",
},
{
"title": "Stack Overflow",
"summary": "We monitor the <code><b>polyfactory</b></code> tag on Stack Overflow",
"url": "https://stackoverflow.com/questions/tagged/polyfactory",
"icon": "coc",
},
],
},
{"title": "Sponsor", "url": "https://github.com/sponsors/Litestar-Org", "icon": "heart"},
],
}
def update_html_context(
app: Sphinx,
pagename: str,
templatename: str,
context: dict[str, Any],
doctree: document,
) -> None:
context["generate_toctree_html"] = partial(context["generate_toctree_html"], startdepth=0)
def delayed_setup(app: Sphinx) -> None:
"""When running linkcheck Shibuya causes a build failure, and checking
the builder in the initial `setup` function call is not possible, so the check
and extension setup has to be delayed until the builder is initialized.
"""
if app.builder.name == "linkcheck":
return
# app.setup_extension("shibuya")
def setup(app: Sphinx) -> dict[str, bool]:
app.connect("builder-inited", delayed_setup, priority=0)
app.setup_extension("sphinx_rtd_theme")
return {"parallel_read_safe": True, "parallel_write_safe": True}
|