mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
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.
This commit is contained in:
parent
a41782cc84
commit
f32d022147
2 changed files with 13 additions and 5 deletions
|
|
@ -7,14 +7,16 @@
|
||||||
|
|
||||||
:license: Python license.
|
: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.addnodes import glossary
|
||||||
from sphinx.util import logging
|
from sphinx.util import logging
|
||||||
from docutils.nodes import definition_list_item
|
|
||||||
import json
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
STATIC_DIR = '_static'
|
||||||
|
JSON = 'glossary.json'
|
||||||
|
|
||||||
|
|
||||||
def process_glossary_nodes(app, doctree, fromdocname):
|
def process_glossary_nodes(app, doctree, fromdocname):
|
||||||
|
|
@ -45,8 +47,12 @@ def on_build_finish(app, exc):
|
||||||
if not app.env.glossary_terms:
|
if not app.env.glossary_terms:
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.info('Writing glossary.json', color='green')
|
logger.info(f'Writing {JSON}', color='green')
|
||||||
with open(path.join(app.outdir, '_static', 'glossary.json'), 'w') as f:
|
|
||||||
|
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)
|
json.dump(app.env.glossary_terms, f)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix the Sphinx glossary_search extension: create the _static/ sub-directory
|
||||||
|
if it doesn't exist.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue