Mercurial > hgrepos > Python > libs > ConfigMix
comparison docs/conf.py @ 783:8151ac02f71d
Move all the transforms (|xxx| replacements) from rst_prolog/_epilog to the already existing transform
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 16 May 2026 21:58:06 +0200 |
| parents | 236a1d00b8a6 |
| children | 16f040434598 |
comparison
equal
deleted
inserted
replaced
| 782:36d9f5164046 | 783:8151ac02f71d |
|---|---|
| 13 # documentation root, use os.path.abspath to make it absolute, like shown here. | 13 # documentation root, use os.path.abspath to make it absolute, like shown here. |
| 14 # | 14 # |
| 15 import datetime | 15 import datetime |
| 16 import os | 16 import os |
| 17 import sys | 17 import sys |
| 18 | |
| 19 import sphinx.util.logging | |
| 20 import sphinx.transforms | |
| 18 | 21 |
| 19 sys.path.insert(0, os.path.dirname(os.path.abspath('.'))) | 22 sys.path.insert(0, os.path.dirname(os.path.abspath('.'))) |
| 20 | 23 |
| 21 import configmix | 24 import configmix |
| 22 from configmix.compat import u | 25 from configmix.compat import u |
| 120 highlight_language = "default" | 123 highlight_language = "default" |
| 121 | 124 |
| 122 # The name of the Pygments (syntax highlighting) style to use. | 125 # The name of the Pygments (syntax highlighting) style to use. |
| 123 pygments_style = 'sphinx' | 126 pygments_style = 'sphinx' |
| 124 | 127 |
| 125 rst_prolog = """ | |
| 126 .. |release_date| replace:: %s | |
| 127 .. |release_rev| replace:: %s | |
| 128 """ % (release_date, release_rev) | |
| 129 if define_rest_keywords: | |
| 130 rst_prolog += """\ | |
| 131 .. |VCSJustDate| replace:: %s | |
| 132 .. |VCSRevision| replace:: %s | |
| 133 .. |VCSHGRevision| replace:: %s | |
| 134 """ % (release_date, release_rev, release_rev) | |
| 135 | |
| 136 | 128 |
| 137 # -- Options for HTML output ------------------------------------------------- | 129 # -- Options for HTML output ------------------------------------------------- |
| 138 | 130 |
| 139 # The theme to use for HTML and HTML Help pages. See the documentation for | 131 # The theme to use for HTML and HTML Help pages. See the documentation for |
| 140 # a list of builtin themes. | 132 # a list of builtin themes. |
| 262 autodoc_member_order = 'bysource' | 254 autodoc_member_order = 'bysource' |
| 263 autoclass_content = 'both' | 255 autoclass_content = 'both' |
| 264 | 256 |
| 265 | 257 |
| 266 def setup(app): | 258 def setup(app): |
| 259 logger = sphinx.util.logging.getLogger("conf-setup") | |
| 260 logger.info("Release: %s", release) | |
| 261 logger.info("Release Date: %s", release_date) | |
| 262 logger.info("Release Rev: %s", release_rev) | |
| 263 | |
| 267 # | 264 # |
| 268 # Custom release_date variable with a custom substitution |release_date| | 265 # Custom release_date variable with a custom substitution |release_date| |
| 269 # and |release_rev|'. | 266 # and |release_rev|'. |
| 270 # | 267 # |
| 271 app.add_config_value('release_date', '', 'env') | 268 app.add_config_value('release_date', '', 'env') |
| 272 app.add_config_value('release_rev', '', 'env') | 269 app.add_config_value('release_rev', '', 'env') |
| 273 | 270 |
| 274 import sphinx.transforms | |
| 275 | |
| 276 class IAMCustomSubstitutions(sphinx.transforms.SphinxTransform): | 271 class IAMCustomSubstitutions(sphinx.transforms.SphinxTransform): |
| 277 | 272 |
| 278 default_priority = sphinx.transforms.DefaultSubstitutions.default_priority | 273 default_priority = sphinx.transforms.DefaultSubstitutions.default_priority |
| 274 | |
| 275 SUBSTITUTIONS = { | |
| 276 "release_date": release_date, | |
| 277 "release_rev": release_rev | |
| 278 } | |
| 279 if define_rest_keywords: | |
| 280 SUBSTITUTIONS.update( | |
| 281 {"VCSJustDate": release_date, | |
| 282 "VCSRevision": release_rev, | |
| 283 "VCSHGRevision": release_rev}) | |
| 284 | |
| 279 def apply(self): | 285 def apply(self): |
| 280 from docutils import nodes | 286 from docutils import nodes |
| 281 for ref in self.document.traverse(nodes.substitution_reference): | 287 for ref in self.document.traverse(nodes.substitution_reference): |
| 282 refname = ref['refname'] | 288 refname = ref['refname'] |
| 283 if refname in ('release_date' 'release_rev'): | 289 if refname in self.SUBSTITUTIONS: |
| 284 stext = self.config[refname] | 290 stext = self.SUBSTITUTIONS[refname] |
| 285 ref.replace_self(nodes.Text(stext, stext)) | 291 ref.replace_self(nodes.Text(stext, stext)) |
| 292 #if refname in ('release_date' 'release_rev'): | |
| 293 # stext = self.config[refname] | |
| 294 # ref.replace_self(nodes.Text(stext, stext)) | |
| 286 | 295 |
| 287 app.add_transform(IAMCustomSubstitutions) | 296 app.add_transform(IAMCustomSubstitutions) |
