Mercurial > hgrepos > Python > libs > ConfigMix
comparison docs/conf.py @ 781:236a1d00b8a6
Some documentation tweaks: sync with other projects
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 16 May 2026 14:59:46 +0200 |
| parents | 48deafc1fd2f |
| children | 8151ac02f71d |
comparison
equal
deleted
inserted
replaced
| 780:47ae57d92ed3 | 781:236a1d00b8a6 |
|---|---|
| 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 | |
| 18 sys.path.insert(0, os.path.dirname(os.path.abspath('.'))) | 19 sys.path.insert(0, os.path.dirname(os.path.abspath('.'))) |
| 19 | 20 |
| 20 import configmix | 21 import configmix |
| 21 from configmix.compat import u | 22 from configmix.compat import u |
| 22 | 23 |
| 28 | 29 |
| 29 project = 'ConfigMix' | 30 project = 'ConfigMix' |
| 30 copyright = u('2015–2023, Franz Glasner. All rights reserved') | 31 copyright = u('2015–2023, Franz Glasner. All rights reserved') |
| 31 author = 'Franz Glasner' | 32 author = 'Franz Glasner' |
| 32 | 33 |
| 33 # The short X.Y version | 34 current_date = datetime.date.today().isoformat() |
| 34 version = '.'.join(configmix.__version__.split('.')[:2]) | 35 |
| 35 # The full version, including alpha/beta/rc tags | 36 # The full version, including alpha/beta/rc tags |
| 36 release = configmix.__version__ | 37 release = configmix.__version__ |
| 38 # The short X.Y version | |
| 39 version = '.'.join(release.split('.')[:2]) | |
| 40 | |
| 41 # | |
| 42 # Optimistically assume that all keywords are expanded properly everywhere: | |
| 43 # do not define special VCSxxx keyword below. | |
| 44 # | |
| 45 define_rest_keywords = False | |
| 46 | |
| 37 release_date = today = configmix.__date__ | 47 release_date = today = configmix.__date__ |
| 38 | 48 if (not release_date |
| 39 current_date = datetime.date.today().isoformat() | 49 or (release_date.startswith("|") and release_date.endswith("|"))): |
| 40 | 50 # Above assumption is not true: "hg kwarchive" nay not have been called |
| 51 release_date = today = "dev-%s" % (current_date,) | |
| 52 define_rest_keywords = True | |
| 53 release_rev = configmix.__revision__ | |
| 54 if (not release_rev | |
| 55 or (release_rev.startswith("|") and release_rev.endswith("|"))): | |
| 56 # | |
| 57 # Above assumption is not true: "hg kwarchive" may not have been called. | |
| 58 # Try to determine from VCS. | |
| 59 # | |
| 60 import subprocess | |
| 61 try: | |
| 62 release_rev = subprocess.check_output( | |
| 63 ["hg", "id", "-i"], stderr=subprocess.STDOUT) | |
| 64 except Exception: | |
| 65 release_rev = "<UNKNOWN>" | |
| 66 else: | |
| 67 if sys.version_info[0] >= 3: | |
| 68 release_rev = release_rev.decode("ascii") | |
| 69 release_rev = "dev-%s" % (release_rev.strip(),) | |
| 70 define_rest_keywords = True | |
| 71 else: | |
| 72 # | |
| 73 # Assume that all keywords are expanded properly everywhere: | |
| 74 # do not define special VCSxxx keyword below. | |
| 75 # | |
| 76 define_rest_keywords = False | |
| 41 | 77 |
| 42 # -- General configuration --------------------------------------------------- | 78 # -- General configuration --------------------------------------------------- |
| 43 | 79 |
| 44 # If your documentation needs a minimal Sphinx version, state it here. | 80 # If your documentation needs a minimal Sphinx version, state it here. |
| 45 # | 81 # |
| 84 highlight_language = "default" | 120 highlight_language = "default" |
| 85 | 121 |
| 86 # The name of the Pygments (syntax highlighting) style to use. | 122 # The name of the Pygments (syntax highlighting) style to use. |
| 87 pygments_style = 'sphinx' | 123 pygments_style = 'sphinx' |
| 88 | 124 |
| 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 | |
| 89 | 136 |
| 90 # -- Options for HTML output ------------------------------------------------- | 137 # -- Options for HTML output ------------------------------------------------- |
| 91 | 138 |
| 92 # The theme to use for HTML and HTML Help pages. See the documentation for | 139 # The theme to use for HTML and HTML Help pages. See the documentation for |
| 93 # a list of builtin themes. | 140 # a list of builtin themes. |
| 94 # | 141 # |
| 95 #html_theme = 'alabaster' | 142 #html_theme = 'alabaster' |
| 96 html_theme = 'haiku' | 143 html_theme = 'haiku' |
| 97 # for the Haiku title | 144 # for the Haiku title |
| 98 html_short_title = u("%s %s") % (project, release) | 145 html_short_title = u("%s %s") % (project, release) |
| 99 html_last_updated_fmt = "%s (rev %s)" % (current_date, configmix.__revision__) | 146 html_last_updated_fmt = "%s (rev %s)" % (current_date, release_rev) |
| 100 | 147 |
| 101 # Theme options are theme-specific and customize the look and feel of a theme | 148 # Theme options are theme-specific and customize the look and feel of a theme |
| 102 # further. For a list of options available for each theme, see the | 149 # further. For a list of options available for each theme, see the |
| 103 # documentation. | 150 # documentation. |
| 104 # | 151 # |
| 144 'pointsize': '11pt', | 191 'pointsize': '11pt', |
| 145 | 192 |
| 146 'babel': r'\usepackage{babel}', | 193 'babel': r'\usepackage{babel}', |
| 147 'preamble': r'\usepackage[stdtitle=false]{my-doc-style}', | 194 'preamble': r'\usepackage[stdtitle=false]{my-doc-style}', |
| 148 'maketitle': r'\builddate{%s}\vcsrevision{%s}\sphinxmaketitle' \ | 195 'maketitle': r'\builddate{%s}\vcsrevision{%s}\sphinxmaketitle' \ |
| 149 % (current_date, configmix.__revision__), | 196 % (current_date, release_rev), |
| 150 'fontpkg': r'\usepackage[fonts=charter]{my-doc-fonts}', | 197 'fontpkg': r'\usepackage[fonts=charter]{my-doc-fonts}', |
| 151 | 198 |
| 152 # Latex figure (float) alignment | 199 # Latex figure (float) alignment |
| 153 # | 200 # |
| 154 # 'figure_align': 'htbp', | 201 # 'figure_align': 'htbp', |
| 157 | 204 |
| 158 'fncychap': r'\usepackage[Sonny]{fncychap}', | 205 'fncychap': r'\usepackage[Sonny]{fncychap}', |
| 159 } | 206 } |
| 160 latex_additional_files = [ | 207 latex_additional_files = [ |
| 161 "_latex/my-doc-fonts.sty", | 208 "_latex/my-doc-fonts.sty", |
| 162 "_latex/my-doc-style.sty", | 209 "_latex/my-doc-style.sty", |
| 163 ] | 210 ] |
| 164 | 211 |
| 165 # Grouping the document tree into LaTeX files. List of tuples | 212 # Grouping the document tree into LaTeX files. List of tuples |
| 166 # (source start file, target name, title, | 213 # (source start file, target name, title, |
| 167 # author, documentclass [howto, manual, or own class]). | 214 # author, documentclass [howto, manual, or own class]). |
| 217 | 264 |
| 218 | 265 |
| 219 def setup(app): | 266 def setup(app): |
| 220 # | 267 # |
| 221 # Custom release_date variable with a custom substitution |release_date| | 268 # Custom release_date variable with a custom substitution |release_date| |
| 269 # and |release_rev|'. | |
| 222 # | 270 # |
| 223 app.add_config_value('release_date', '', 'env') | 271 app.add_config_value('release_date', '', 'env') |
| 272 app.add_config_value('release_rev', '', 'env') | |
| 224 | 273 |
| 225 import sphinx.transforms | 274 import sphinx.transforms |
| 226 | 275 |
| 227 class IAMCustomSubstitutions(sphinx.transforms.SphinxTransform): | 276 class IAMCustomSubstitutions(sphinx.transforms.SphinxTransform): |
| 228 | 277 |
| 229 default_priority = sphinx.transforms.DefaultSubstitutions.default_priority | 278 default_priority = sphinx.transforms.DefaultSubstitutions.default_priority |
| 230 def apply(self): | 279 def apply(self): |
| 231 from docutils import nodes | 280 from docutils import nodes |
| 232 for ref in self.document.traverse(nodes.substitution_reference): | 281 for ref in self.document.traverse(nodes.substitution_reference): |
| 233 refname = ref['refname'] | 282 refname = ref['refname'] |
| 234 if refname == 'release_date': | 283 if refname in ('release_date' 'release_rev'): |
| 235 stext = self.config[refname] | 284 stext = self.config[refname] |
| 236 ref.replace_self(nodes.Text(stext, stext)) | 285 ref.replace_self(nodes.Text(stext, stext)) |
| 237 | 286 |
| 238 app.add_transform(IAMCustomSubstitutions) | 287 app.add_transform(IAMCustomSubstitutions) |
