Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
diff 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 |
line wrap: on
line diff
--- a/docs/conf.py Fri May 08 23:54:06 2026 +0200 +++ b/docs/conf.py Sun May 10 15:27:18 2026 +0200 @@ -4,6 +4,7 @@ # https://www.sphinx-doc.org/en/master/usage/configuration.html import ast +import datetime import functools import io import os @@ -20,25 +21,58 @@ """ +today = datetime.date.today().isoformat() # -- Project information ----------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information project = 'Pygments Pseudocode Lexer' -copyright = '2026 Franz Glasner. © Copyright 2015 Simon Wachter' +copyright = u'2026 Franz Glasner. © Copyright 2015 Simon Wachter' author = 'Franz Glasner' -# Determine "release" dynamically from the package's "__version__" +# +# Determine "release" and other release metadata dynamically from the +# package's "__version__" or other VCS data. +# with io.open("../pygments_lexer_pseudocode2/__init__.py", "rt", encoding="utf-8") as relfp: + verfiledata = relfp.read() release = ast.literal_eval( re.search(r"""^\s*__version__\s*=\s*(("|')[^"']*\2)""", - relfp.read(), - re.MULTILINE) - .group(1) - ) + verfiledata, + re.MULTILINE).group(1)) + release_date = ( + ast.literal_eval( + re.search(r"""^\s*__date__\s*=\s*(("|')[^"']*\2)""", + verfiledata, + re.MULTILINE).group(1)) + or "dev:%s" % (today,) + ) + release_rev = ast.literal_eval( + re.search(r"""^\s*__revision__\s*=\s*(("|')[^"']*\2)""", + verfiledata, + re.MULTILINE).group(1)) + if release_rev.startswith("|") or release_rev.endswith("|"): + # Assume that make export (hg kwarchive) is not called. + import subprocess + try: + release_rev = subprocess.check_output( + ["hg", "id", "-i"], stderr=subprocess.STDOUT) + except Exception: + release_rev = "<unknown>" + else: + if sys.version_info[0] >= 3: + release_rev = release_rev.decode("ascii") + release_rev = "dev:%s" % (release_rev.strip(),) + define_rest_keywords = True + else: + # + # Assume that all keywords are expanded properly everywhere: + # do not define special VCSxxx keyword below. + # + define_rest_keywords = False + version = release -del relfp primary_domain = None # -- General configuration --------------------------------------------------- @@ -55,7 +89,14 @@ rst_prolog = """ .. role:: algpseudocode(code) -""" +.. |release_date| replace:: %s +.. |release_rev| replace:: %s +""" % (release_date, release_rev) +if define_rest_keywords: + rst_prolog += """\ +.. |VCSJustDate| replace:: %s +.. |VCSRevision| replace:: %s +""" % (release_date, release_rev) rst_epilog = """ .. _Pygments: https://pygments.org/ .. _Sphinx: https://www.sphinx-doc.org @@ -73,17 +114,27 @@ html_static_path = ['_static'] html_extra_path = ['../LICENSES', './examples'] +html_copy_source = False +html_show_sourcelink = False #html_theme = 'alabaster' html_theme = 'haiku' html_title = 'The %s v%s' % (project, release) html_short_title = html_title +html_last_updated_fmt = "%s (rv:%s)" % (today, release_rev) #pygments_style = "sphinx" pygments_style = "default" def setup(app): # + # Custom release_date and commit id variables with a custom substitution + # |release_date| and |release_rev|'. + # + app.add_config_value('release_date', '', 'env') + app.add_config_value('release_rev', '', 'env') + + # # Add a custom lexer: AlgPseudocodeLexer with custom init option "no_end" # Given lexer must be callable: so use an indirection with "partial". #
