[Python-checkins] bpo-43778: Fix Sphinx glossary_search extension (GH-25286)
vstinner
webhook-mailer at python.org
Thu Apr 8 18:07:22 EDT 2021
https://github.com/python/cpython/commit/f32d0221477f18993666bb66cc79c61c4e145d42
commit: f32d0221477f18993666bb66cc79c61c4e145d42
branch: master
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2021-04-09T00:07:01+02:00
summary:
bpo-43778: Fix Sphinx glossary_search extension (GH-25286)
Create the _static/ directory if it doesn't exist.
Add also constants for the static directory and the JSON filename.
files:
A Misc/NEWS.d/next/Documentation/2021-04-08-22-42-02.bpo-43778.MszRnY.rst
M Doc/tools/extensions/glossary_search.py
diff --git a/Doc/tools/extensions/glossary_search.py b/Doc/tools/extensions/glossary_search.py
index 34d227d670243..59a6862ea3d3f 100644
--- a/Doc/tools/extensions/glossary_search.py
+++ b/Doc/tools/extensions/glossary_search.py
@@ -7,14 +7,16 @@
:license: Python license.
"""
-from os import path
+import json
+import os.path
+from docutils.nodes import definition_list_item
from sphinx.addnodes import glossary
from sphinx.util import logging
-from docutils.nodes import definition_list_item
-import json
logger = logging.getLogger(__name__)
+STATIC_DIR = '_static'
+JSON = 'glossary.json'
def process_glossary_nodes(app, doctree, fromdocname):
@@ -45,8 +47,12 @@ def on_build_finish(app, exc):
if not app.env.glossary_terms:
return
- logger.info('Writing glossary.json', color='green')
- with open(path.join(app.outdir, '_static', 'glossary.json'), 'w') as f:
+ logger.info(f'Writing {JSON}', color='green')
+
+ dest_dir = os.path.join(app.outdir, STATIC_DIR)
+ os.makedirs(dest_dir, exist_ok=True)
+
+ with open(os.path.join(dest_dir, JSON), 'w') as f:
json.dump(app.env.glossary_terms, f)
diff --git a/Misc/NEWS.d/next/Documentation/2021-04-08-22-42-02.bpo-43778.MszRnY.rst b/Misc/NEWS.d/next/Documentation/2021-04-08-22-42-02.bpo-43778.MszRnY.rst
new file mode 100644
index 0000000000000..86dc286f83ce9
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2021-04-08-22-42-02.bpo-43778.MszRnY.rst
@@ -0,0 +1,2 @@
+Fix the Sphinx glossary_search extension: create the _static/ sub-directory
+if it doesn't exist.
More information about the Python-checkins
mailing list