diff options
author | Victor Stinner <vstinner@python.org> | 2021-04-08 22:07:01 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-08 22:07:01 (GMT) |
commit | f32d0221477f18993666bb66cc79c61c4e145d42 (patch) | |
tree | 6c9fe2f12cb236fc79734d2e7d26d045132285a5 /Doc/tools | |
parent | a41782cc84bcd813209a03e6e11c60e77dbc7718 (diff) | |
download | cpython-f32d0221477f18993666bb66cc79c61c4e145d42.zip cpython-f32d0221477f18993666bb66cc79c61c4e145d42.tar.gz cpython-f32d0221477f18993666bb66cc79c61c4e145d42.tar.bz2 |
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.
Diffstat (limited to 'Doc/tools')
-rw-r--r-- | Doc/tools/extensions/glossary_search.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/Doc/tools/extensions/glossary_search.py b/Doc/tools/extensions/glossary_search.py index 34d227d..59a6862 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) |