annotate docs/conf.py @ 66:9ba1584d4b4a

Also add a test that completely highlights a document with Pygments
author Franz Glasner <fzglas.hg@dom66.de>
date Tue, 28 Apr 2026 15:02:15 +0200
parents 414bf3cbb152
children 93ade4c595b7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
45
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1 # Configuration file for the Sphinx documentation builder.
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2 #
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
3 # For the full list of built-in configuration values, see the documentation:
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
4 # https://www.sphinx-doc.org/en/master/usage/configuration.html
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
5
49
5c0f26a21e81 Determine "release" dynamically from the package's "__version__"
Franz Glasner <fzglas.hg@dom66.de>
parents: 48
diff changeset
6 import ast
63
414bf3cbb152 Add a custom lexer to the Sphinx application dynamically with "no_end" set to True
Franz Glasner <fzglas.hg@dom66.de>
parents: 60
diff changeset
7 import functools
49
5c0f26a21e81 Determine "release" dynamically from the package's "__version__"
Franz Glasner <fzglas.hg@dom66.de>
parents: 48
diff changeset
8 import io
63
414bf3cbb152 Add a custom lexer to the Sphinx application dynamically with "no_end" set to True
Franz Glasner <fzglas.hg@dom66.de>
parents: 60
diff changeset
9 import os
414bf3cbb152 Add a custom lexer to the Sphinx application dynamically with "no_end" set to True
Franz Glasner <fzglas.hg@dom66.de>
parents: 60
diff changeset
10 import sys
49
5c0f26a21e81 Determine "release" dynamically from the package's "__version__"
Franz Glasner <fzglas.hg@dom66.de>
parents: 48
diff changeset
11 import re
5c0f26a21e81 Determine "release" dynamically from the package's "__version__"
Franz Glasner <fzglas.hg@dom66.de>
parents: 48
diff changeset
12
63
414bf3cbb152 Add a custom lexer to the Sphinx application dynamically with "no_end" set to True
Franz Glasner <fzglas.hg@dom66.de>
parents: 60
diff changeset
13 sys.path.insert(0, os.path.dirname(os.path.abspath('.')))
414bf3cbb152 Add a custom lexer to the Sphinx application dynamically with "no_end" set to True
Franz Glasner <fzglas.hg@dom66.de>
parents: 60
diff changeset
14
45
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
15 # -- Project information -----------------------------------------------------
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
16 # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
17
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
18 project = 'Pygments Pseudocode Lexer'
50
e6354e3abbec Remove the comma in the copyright statement
Franz Glasner <fzglas.hg@dom66.de>
parents: 49
diff changeset
19 copyright = '2026 Franz Glasner'
45
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
20 author = 'Franz Glasner'
49
5c0f26a21e81 Determine "release" dynamically from the package's "__version__"
Franz Glasner <fzglas.hg@dom66.de>
parents: 48
diff changeset
21 # Determine "release" dynamically from the package's "__version__"
5c0f26a21e81 Determine "release" dynamically from the package's "__version__"
Franz Glasner <fzglas.hg@dom66.de>
parents: 48
diff changeset
22 with io.open("../pygments_lexer_pseudocode2/__init__.py",
5c0f26a21e81 Determine "release" dynamically from the package's "__version__"
Franz Glasner <fzglas.hg@dom66.de>
parents: 48
diff changeset
23 "rt",
5c0f26a21e81 Determine "release" dynamically from the package's "__version__"
Franz Glasner <fzglas.hg@dom66.de>
parents: 48
diff changeset
24 encoding="utf-8") as relfp:
5c0f26a21e81 Determine "release" dynamically from the package's "__version__"
Franz Glasner <fzglas.hg@dom66.de>
parents: 48
diff changeset
25 release = ast.literal_eval(
5c0f26a21e81 Determine "release" dynamically from the package's "__version__"
Franz Glasner <fzglas.hg@dom66.de>
parents: 48
diff changeset
26 re.search(r"""^\s*__version__\s*=\s*(("|')[^"']*\2)""",
5c0f26a21e81 Determine "release" dynamically from the package's "__version__"
Franz Glasner <fzglas.hg@dom66.de>
parents: 48
diff changeset
27 relfp.read(),
5c0f26a21e81 Determine "release" dynamically from the package's "__version__"
Franz Glasner <fzglas.hg@dom66.de>
parents: 48
diff changeset
28 re.MULTILINE)
5c0f26a21e81 Determine "release" dynamically from the package's "__version__"
Franz Glasner <fzglas.hg@dom66.de>
parents: 48
diff changeset
29 .group(1)
5c0f26a21e81 Determine "release" dynamically from the package's "__version__"
Franz Glasner <fzglas.hg@dom66.de>
parents: 48
diff changeset
30 )
51
b4c255f8bdc4 Also define "version" (identical to "release" yet)
Franz Glasner <fzglas.hg@dom66.de>
parents: 50
diff changeset
31 version = release
b4c255f8bdc4 Also define "version" (identical to "release" yet)
Franz Glasner <fzglas.hg@dom66.de>
parents: 50
diff changeset
32 del relfp
45
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
33
60
0ff291eac663 Minimal Sphinx configuration for the first tests
Franz Glasner <fzglas.hg@dom66.de>
parents: 51
diff changeset
34
45
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
35 # -- General configuration ---------------------------------------------------
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
36 # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
37
60
0ff291eac663 Minimal Sphinx configuration for the first tests
Franz Glasner <fzglas.hg@dom66.de>
parents: 51
diff changeset
38 extensions = [
0ff291eac663 Minimal Sphinx configuration for the first tests
Franz Glasner <fzglas.hg@dom66.de>
parents: 51
diff changeset
39 "sphinx.ext.todo",
0ff291eac663 Minimal Sphinx configuration for the first tests
Franz Glasner <fzglas.hg@dom66.de>
parents: 51
diff changeset
40 ]
45
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
41
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
42 templates_path = ['_templates']
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
43 exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
44
60
0ff291eac663 Minimal Sphinx configuration for the first tests
Franz Glasner <fzglas.hg@dom66.de>
parents: 51
diff changeset
45
0ff291eac663 Minimal Sphinx configuration for the first tests
Franz Glasner <fzglas.hg@dom66.de>
parents: 51
diff changeset
46 # --- Options for todo extension ---------------------------------------------
0ff291eac663 Minimal Sphinx configuration for the first tests
Franz Glasner <fzglas.hg@dom66.de>
parents: 51
diff changeset
47 todo_include_todos = True
45
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
48
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
49
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
50 # -- Options for HTML output -------------------------------------------------
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
51 # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
52
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
53 html_theme = 'alabaster'
60
0ff291eac663 Minimal Sphinx configuration for the first tests
Franz Glasner <fzglas.hg@dom66.de>
parents: 51
diff changeset
54 html_theme = 'haiku'
45
6ac1ea5d2d4a Begin documentation: add the Sphinx generated configuration as-is
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
55 html_static_path = ['_static']
60
0ff291eac663 Minimal Sphinx configuration for the first tests
Franz Glasner <fzglas.hg@dom66.de>
parents: 51
diff changeset
56 #pygments_style = "sphinx"
0ff291eac663 Minimal Sphinx configuration for the first tests
Franz Glasner <fzglas.hg@dom66.de>
parents: 51
diff changeset
57 pygments_style = "default"
63
414bf3cbb152 Add a custom lexer to the Sphinx application dynamically with "no_end" set to True
Franz Glasner <fzglas.hg@dom66.de>
parents: 60
diff changeset
58
414bf3cbb152 Add a custom lexer to the Sphinx application dynamically with "no_end" set to True
Franz Glasner <fzglas.hg@dom66.de>
parents: 60
diff changeset
59
414bf3cbb152 Add a custom lexer to the Sphinx application dynamically with "no_end" set to True
Franz Glasner <fzglas.hg@dom66.de>
parents: 60
diff changeset
60 def setup(app):
414bf3cbb152 Add a custom lexer to the Sphinx application dynamically with "no_end" set to True
Franz Glasner <fzglas.hg@dom66.de>
parents: 60
diff changeset
61 # Add a custom lexer: AlgPseudocodeLexer with custom init option "no_end"
414bf3cbb152 Add a custom lexer to the Sphinx application dynamically with "no_end" set to True
Franz Glasner <fzglas.hg@dom66.de>
parents: 60
diff changeset
62 from pygments_lexer_pseudocode2.algpseudocode import AlgPseudocodeLexer
414bf3cbb152 Add a custom lexer to the Sphinx application dynamically with "no_end" set to True
Franz Glasner <fzglas.hg@dom66.de>
parents: 60
diff changeset
63
414bf3cbb152 Add a custom lexer to the Sphinx application dynamically with "no_end" set to True
Franz Glasner <fzglas.hg@dom66.de>
parents: 60
diff changeset
64 # Given lexer must be callable: also use an indirection with "partial"
414bf3cbb152 Add a custom lexer to the Sphinx application dynamically with "no_end" set to True
Franz Glasner <fzglas.hg@dom66.de>
parents: 60
diff changeset
65 app.add_lexer("NoEndAlgPseudocode",
414bf3cbb152 Add a custom lexer to the Sphinx application dynamically with "no_end" set to True
Franz Glasner <fzglas.hg@dom66.de>
parents: 60
diff changeset
66 functools.partial(AlgPseudocodeLexer, no_end=True))