comparison docs/conf.py @ 167:ddefcc20367c

More static and/or dynamic metadata into README and project's init: release date, revision. While there bump the version to 3.0.0.dev1.
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 10 May 2026 15:27:18 +0200
parents 6a7dace0141e
children f761694373e0
comparison
equal deleted inserted replaced
166:6a7dace0141e 167:ddefcc20367c
2 # 2 #
3 # For the full list of built-in configuration values, see the documentation: 3 # For the full list of built-in configuration values, see the documentation:
4 # https://www.sphinx-doc.org/en/master/usage/configuration.html 4 # https://www.sphinx-doc.org/en/master/usage/configuration.html
5 5
6 import ast 6 import ast
7 import datetime
7 import functools 8 import functools
8 import io 9 import io
9 import os 10 import os
10 import sys 11 import sys
11 import re 12 import re
18 needs_sphinx = '2.1' 19 needs_sphinx = '2.1'
19 """2.1: - :py:meth:Sphinx.add_lexer` takes a class as argument 20 """2.1: - :py:meth:Sphinx.add_lexer` takes a class as argument
20 21
21 """ 22 """
22 23
24 today = datetime.date.today().isoformat()
23 25
24 # -- Project information ----------------------------------------------------- 26 # -- Project information -----------------------------------------------------
25 # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information 27 # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
26 28
27 project = 'Pygments Pseudocode Lexer' 29 project = 'Pygments Pseudocode Lexer'
28 copyright = '2026 Franz Glasner. © Copyright 2015 Simon Wachter' 30 copyright = u'2026 Franz Glasner. © Copyright 2015 Simon Wachter'
29 author = 'Franz Glasner' 31 author = 'Franz Glasner'
30 # Determine "release" dynamically from the package's "__version__" 32 #
33 # Determine "release" and other release metadata dynamically from the
34 # package's "__version__" or other VCS data.
35 #
31 with io.open("../pygments_lexer_pseudocode2/__init__.py", 36 with io.open("../pygments_lexer_pseudocode2/__init__.py",
32 "rt", 37 "rt",
33 encoding="utf-8") as relfp: 38 encoding="utf-8") as relfp:
39 verfiledata = relfp.read()
34 release = ast.literal_eval( 40 release = ast.literal_eval(
35 re.search(r"""^\s*__version__\s*=\s*(("|')[^"']*\2)""", 41 re.search(r"""^\s*__version__\s*=\s*(("|')[^"']*\2)""",
36 relfp.read(), 42 verfiledata,
37 re.MULTILINE) 43 re.MULTILINE).group(1))
38 .group(1) 44 release_date = (
39 ) 45 ast.literal_eval(
46 re.search(r"""^\s*__date__\s*=\s*(("|')[^"']*\2)""",
47 verfiledata,
48 re.MULTILINE).group(1))
49 or "dev:%s" % (today,)
50 )
51 release_rev = ast.literal_eval(
52 re.search(r"""^\s*__revision__\s*=\s*(("|')[^"']*\2)""",
53 verfiledata,
54 re.MULTILINE).group(1))
55 if release_rev.startswith("|") or release_rev.endswith("|"):
56 # Assume that make export (hg kwarchive) is not called.
57 import subprocess
58 try:
59 release_rev = subprocess.check_output(
60 ["hg", "id", "-i"], stderr=subprocess.STDOUT)
61 except Exception:
62 release_rev = "<unknown>"
63 else:
64 if sys.version_info[0] >= 3:
65 release_rev = release_rev.decode("ascii")
66 release_rev = "dev:%s" % (release_rev.strip(),)
67 define_rest_keywords = True
68 else:
69 #
70 # Assume that all keywords are expanded properly everywhere:
71 # do not define special VCSxxx keyword below.
72 #
73 define_rest_keywords = False
74
40 version = release 75 version = release
41 del relfp
42 primary_domain = None 76 primary_domain = None
43 77
44 # -- General configuration --------------------------------------------------- 78 # -- General configuration ---------------------------------------------------
45 # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration 79 # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
46 80
53 87
54 highlight_language = "none" 88 highlight_language = "none"
55 89
56 rst_prolog = """ 90 rst_prolog = """
57 .. role:: algpseudocode(code) 91 .. role:: algpseudocode(code)
58 """ 92 .. |release_date| replace:: %s
93 .. |release_rev| replace:: %s
94 """ % (release_date, release_rev)
95 if define_rest_keywords:
96 rst_prolog += """\
97 .. |VCSJustDate| replace:: %s
98 .. |VCSRevision| replace:: %s
99 """ % (release_date, release_rev)
59 rst_epilog = """ 100 rst_epilog = """
60 .. _Pygments: https://pygments.org/ 101 .. _Pygments: https://pygments.org/
61 .. _Sphinx: https://www.sphinx-doc.org 102 .. _Sphinx: https://www.sphinx-doc.org
62 .. _Python: https://www.python.org/ 103 .. _Python: https://www.python.org/
63 .. _Algpseudocodex: https://ctan.org/pkg/algpseudocodex 104 .. _Algpseudocodex: https://ctan.org/pkg/algpseudocodex
71 # -- Options for HTML output ------------------------------------------------- 112 # -- Options for HTML output -------------------------------------------------
72 # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output 113 # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
73 114
74 html_static_path = ['_static'] 115 html_static_path = ['_static']
75 html_extra_path = ['../LICENSES', './examples'] 116 html_extra_path = ['../LICENSES', './examples']
117 html_copy_source = False
118 html_show_sourcelink = False
76 119
77 #html_theme = 'alabaster' 120 #html_theme = 'alabaster'
78 html_theme = 'haiku' 121 html_theme = 'haiku'
79 html_title = 'The %s v%s' % (project, release) 122 html_title = 'The %s v%s' % (project, release)
80 html_short_title = html_title 123 html_short_title = html_title
124 html_last_updated_fmt = "%s (rv:%s)" % (today, release_rev)
81 #pygments_style = "sphinx" 125 #pygments_style = "sphinx"
82 pygments_style = "default" 126 pygments_style = "default"
83 127
84 128
85 def setup(app): 129 def setup(app):
130 #
131 # Custom release_date and commit id variables with a custom substitution
132 # |release_date| and |release_rev|'.
133 #
134 app.add_config_value('release_date', '', 'env')
135 app.add_config_value('release_rev', '', 'env')
136
86 # 137 #
87 # Add a custom lexer: AlgPseudocodeLexer with custom init option "no_end" 138 # Add a custom lexer: AlgPseudocodeLexer with custom init option "no_end"
88 # Given lexer must be callable: so use an indirection with "partial". 139 # Given lexer must be callable: so use an indirection with "partial".
89 # 140 #
90 # See also: 141 # See also: