Skip to content

Commit f32d022

Browse files
authored
bpo-43778: Fix Sphinx glossary_search extension (pythonGH-25286)
Create the _static/ directory if it doesn't exist. Add also constants for the static directory and the JSON filename.
1 parent a41782c commit f32d022

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

Doc/tools/extensions/glossary_search.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
88
:license: Python license.
99
"""
10-
from os import path
10+
import json
11+
import os.path
12+
from docutils.nodes import definition_list_item
1113
from sphinx.addnodes import glossary
1214
from sphinx.util import logging
13-
from docutils.nodes import definition_list_item
14-
import json
1515

1616

1717
logger = logging.getLogger(__name__)
18+
STATIC_DIR = '_static'
19+
JSON = 'glossary.json'
1820

1921

2022
def process_glossary_nodes(app, doctree, fromdocname):
@@ -45,8 +47,12 @@ def on_build_finish(app, exc):
4547
if not app.env.glossary_terms:
4648
return
4749

48-
logger.info('Writing glossary.json', color='green')
49-
with open(path.join(app.outdir, '_static', 'glossary.json'), 'w') as f:
50+
logger.info(f'Writing {JSON}', color='green')
51+
52+
dest_dir = os.path.join(app.outdir, STATIC_DIR)
53+
os.makedirs(dest_dir, exist_ok=True)
54+
55+
with open(os.path.join(dest_dir, JSON), 'w') as f:
5056
json.dump(app.env.glossary_terms, f)
5157

5258

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix the Sphinx glossary_search extension: create the _static/ sub-directory
2+
if it doesn't exist.

0 commit comments

Comments
 (0)