Changeset View
Changeset View
Standalone View
Standalone View
swh/docs/sphinx/conf.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||
# | # | ||||
import os | import os | ||||
from typing import Dict | from typing import Dict | ||||
import django | |||||
from sphinx.ext import autodoc | from sphinx.ext import autodoc | ||||
from swh.docs.django_settings import force_django_settings | |||||
# General information about the project. | # General information about the project. | ||||
project = "Software Heritage - Development Documentation" | project = "Software Heritage - Development Documentation" | ||||
copyright = "2015-2021 The Software Heritage developers" | copyright = "2015-2021 The Software Heritage developers" | ||||
author = "The Software Heritage developers" | author = "The Software Heritage developers" | ||||
# -- General configuration ------------------------------------------------ | # -- General configuration ------------------------------------------------ | ||||
# Add any Sphinx extension module names here, as strings. They can be | # Add any Sphinx extension module names here, as strings. They can be | ||||
▲ Show 20 Lines • Show All 177 Lines • ▼ Show 20 Lines | def register_routingtable_as_label(app, document): | ||||
from sphinx.locale import _ # noqa | from sphinx.locale import _ # noqa | ||||
labels = app.env.domaindata["std"]["labels"] | labels = app.env.domaindata["std"]["labels"] | ||||
labels["routingtable"] = "http-routingtable", "", _("HTTP Routing Table") | labels["routingtable"] = "http-routingtable", "", _("HTTP Routing Table") | ||||
anonlabels = app.env.domaindata["std"]["anonlabels"] | anonlabels = app.env.domaindata["std"]["anonlabels"] | ||||
anonlabels["routingtable"] = "http-routingtable", "" | anonlabels["routingtable"] = "http-routingtable", "" | ||||
def setup(app): | # sphinx event handler to set adequate django settings prior reading | ||||
# hack to set the adequate django settings when building global swh doc | # apidoc generated rst files when building doc to avoid autodoc errors | ||||
# to avoid autodoc build errors | def set_django_settings(app, env, docname): | ||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "swh.docs.django_settings") | package_settings = { | ||||
django.setup() | "auth": "swh.auth.tests.django.app.apptest.settings", | ||||
"deposit": "swh.deposit.settings.development", | |||||
"web": "swh.web.settings.development", | |||||
} | |||||
for package, settings in package_settings.items(): | |||||
if any( | |||||
[pattern in docname for pattern in (f"swh.{package}", f"swh-{package}")] | |||||
): | |||||
force_django_settings(settings) | |||||
def setup(app): | |||||
# env-purge-doc event is fired before source-read | |||||
app.connect("env-purge-doc", set_django_settings) | |||||
# add autosimple directive (used in swh-web) | # add autosimple directive (used in swh-web) | ||||
app.add_autodocumenter(SimpleDocumenter) | app.add_autodocumenter(SimpleDocumenter) | ||||
# set an environment variable indicating we are currently building | # set an environment variable indicating we are currently building | ||||
# the documentation | # the documentation | ||||
os.environ["SWH_DOC_BUILD"] = "1" | os.environ["SWH_DOC_BUILD"] = "1" | ||||
# register routingtable label for sphinxcontrib-httpdomain <= 1.7.0 | # register routingtable label for sphinxcontrib-httpdomain <= 1.7.0 | ||||
from distutils.version import StrictVersion # noqa | from distutils.version import StrictVersion # noqa | ||||
import pkg_resources # noqa | import pkg_resources # noqa | ||||
httpdomain = pkg_resources.get_distribution("sphinxcontrib-httpdomain") | httpdomain = pkg_resources.get_distribution("sphinxcontrib-httpdomain") | ||||
if StrictVersion(httpdomain.version) <= StrictVersion("1.7.0"): | if StrictVersion(httpdomain.version) <= StrictVersion("1.7.0"): | ||||
app.connect("doctree-read", register_routingtable_as_label) | app.connect("doctree-read", register_routingtable_as_label) |