Merge pull request #16301 from qlyoung/reformat-sphinx-config-files

doc: reformat Sphinx conf.py files
This commit is contained in:
Christian Hopps 2024-06-27 14:39:02 -04:00 committed by GitHub
commit 5f41bb29ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 25 deletions

View File

@ -18,6 +18,7 @@ import re
import pygments import pygments
from sphinx.highlighting import lexers from sphinx.highlighting import lexers
from sphinx.util import logging from sphinx.util import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
# If extensions (or modules to document with autodoc) are in another directory, # If extensions (or modules to document with autodoc) are in another directory,
@ -53,18 +54,18 @@ source_suffix = ".rst"
master_doc = "index" master_doc = "index"
# General information about the project. # General information about the project.
project = u"FRR" project = "FRR"
copyright = u"2017, FRR" copyright = "2017, FRR"
author = u"FRR authors" author = "FRR authors"
# The version info for the project you're documenting, acts as replacement for # The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the # |version| and |release|, also used in various other places throughout the
# built documents. # built documents.
# The short X.Y version. # The short X.Y version.
version = u"?.?" version = "?.?"
# The full version, including alpha/beta/rc tags. # The full version, including alpha/beta/rc tags.
release = u"?.?-?" release = "?.?-?"
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@ -287,7 +288,7 @@ latex_elements = {
# (source start file, target name, title, # (source start file, target name, title,
# author, documentclass [howto, manual, or own class]). # author, documentclass [howto, manual, or own class]).
latex_documents = [ latex_documents = [
(master_doc, "FRR.tex", u"FRR Developer's Manual", u"FRR", "manual"), (master_doc, "FRR.tex", "FRR Developer's Manual", "FRR", "manual"),
] ]
# The name of an image file (relative to this directory) to place at the top of # The name of an image file (relative to this directory) to place at the top of
@ -315,7 +316,7 @@ latex_logo = "../figures/frr-logo-medium.png"
# One entry per manual page. List of tuples # One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section). # (source start file, name, description, authors, manual section).
man_pages = [(master_doc, "frr", u"FRR Developer's Manual", [author], 1)] man_pages = [(master_doc, "frr", "FRR Developer's Manual", [author], 1)]
# If true, show URL addresses after external links. # If true, show URL addresses after external links.
# man_show_urls = False # man_show_urls = False
@ -330,7 +331,7 @@ texinfo_documents = [
( (
master_doc, master_doc,
"frr", "frr",
u"FRR Developer's Manual", "FRR Developer's Manual",
author, author,
"FRR", "FRR",
"One line description of project.", "One line description of project.",
@ -358,27 +359,29 @@ texinfo_documents = [
with open("../extra/frrlexer.py", "rb") as lex: with open("../extra/frrlexer.py", "rb") as lex:
frrlexerpy = lex.read() frrlexerpy = lex.read()
frrfmt_re = re.compile(r'^\s*%(?P<spec>[^\s]+)\s+\((?P<types>.*)\)\s*$') frrfmt_re = re.compile(r"^\s*%(?P<spec>[^\s]+)\s+\((?P<types>.*)\)\s*$")
def parse_frrfmt(env, text, node): def parse_frrfmt(env, text, node):
from sphinx import addnodes from sphinx import addnodes
m = frrfmt_re.match(text) m = frrfmt_re.match(text)
if not m: if not m:
logger.warning('could not parse frrfmt:: %r' % (text), location=node) logger.warning("could not parse frrfmt:: %r" % (text), location=node)
node += addnodes.desc_name(text, text) node += addnodes.desc_name(text, text)
return text return text
spec, types = m.group('spec'), m.group('types') spec, types = m.group("spec"), m.group("types")
node += addnodes.desc_sig_operator('%', '%') node += addnodes.desc_sig_operator("%", "%")
node += addnodes.desc_name(spec + ' ', spec + ' ') node += addnodes.desc_name(spec + " ", spec + " ")
plist = addnodes.desc_parameterlist() plist = addnodes.desc_parameterlist()
for typ in types.split(','): for typ in types.split(","):
typ = typ.strip() typ = typ.strip()
plist += addnodes.desc_parameter(typ, typ) plist += addnodes.desc_parameter(typ, typ)
node += plist node += plist
return '%' + spec return "%" + spec
# custom extensions here # custom extensions here
def setup(app): def setup(app):

View File

@ -52,18 +52,18 @@ source_suffix = ".rst"
master_doc = "index" master_doc = "index"
# General information about the project. # General information about the project.
project = u"FRR" project = "FRR"
copyright = u"2017, FRR" copyright = "2017, FRR"
author = u"FRR authors" author = "FRR authors"
# The version info for the project you're documenting, acts as replacement for # The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the # |version| and |release|, also used in various other places throughout the
# built documents. # built documents.
# The short X.Y version. # The short X.Y version.
version = u"?.?" version = "?.?"
# The full version, including alpha/beta/rc tags. # The full version, including alpha/beta/rc tags.
release = u"?.?-?" release = "?.?-?"
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@ -287,7 +287,7 @@ latex_elements = {
# (source start file, target name, title, # (source start file, target name, title,
# author, documentclass [howto, manual, or own class]). # author, documentclass [howto, manual, or own class]).
latex_documents = [ latex_documents = [
(master_doc, "FRR.tex", u"FRR User Manual", u"FRR", "manual"), (master_doc, "FRR.tex", "FRR User Manual", "FRR", "manual"),
] ]
# The name of an image file (relative to this directory) to place at the top of # The name of an image file (relative to this directory) to place at the top of
@ -315,7 +315,7 @@ latex_logo = "../figures/frr-logo-medium.png"
# One entry per manual page. List of tuples # One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section). # (source start file, name, description, authors, manual section).
man_pages = [(master_doc, "frr", u"FRR User Manual", [author], 1)] man_pages = [(master_doc, "frr", "FRR User Manual", [author], 1)]
# If true, show URL addresses after external links. # If true, show URL addresses after external links.
# man_show_urls = False # man_show_urls = False
@ -330,7 +330,7 @@ texinfo_documents = [
( (
master_doc, master_doc,
"frr", "frr",
u"FRR User Manual", "FRR User Manual",
author, author,
"FRR", "FRR",
"One line description of project.", "One line description of project.",
@ -358,6 +358,7 @@ texinfo_documents = [
with open("../extra/frrlexer.py", "rb") as lex: with open("../extra/frrlexer.py", "rb") as lex:
frrlexerpy = lex.read() frrlexerpy = lex.read()
# Parse version string into int array # Parse version string into int array
def vparse(s): def vparse(s):
a = [] a = []
@ -376,7 +377,9 @@ def vparse(s):
def setup(app): def setup(app):
# object type for FRR CLI commands, can be extended to document parent CLI # object type for FRR CLI commands, can be extended to document parent CLI
# node later on # node later on
app.add_object_type("clicmd", "clicmd", indextemplate="pair: %s; configuration command") app.add_object_type(
"clicmd", "clicmd", indextemplate="pair: %s; configuration command"
)
# I dont care how stupid this is # I dont care how stupid this is
if "add_js_file" in dir(app): if "add_js_file" in dir(app):
@ -389,7 +392,6 @@ def setup(app):
else: else:
app.add_stylesheet("overrides.css") app.add_stylesheet("overrides.css")
# load Pygments lexer for FRR config syntax # load Pygments lexer for FRR config syntax
# #
# NB: in Pygments 2.2+ this can be done with `load_lexer_from_file`, but we # NB: in Pygments 2.2+ this can be done with `load_lexer_from_file`, but we