Skip to content

Commit b39ef84

Browse files
committed
Load acronyms once
1 parent 79541a8 commit b39ef84

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

.scripts/gen_markdown_chapters.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
import re
1919
from pathlib import Path
2020

21+
# Load user-defined acronyms once when the module is imported
22+
ACRONYMS_PATH = Path(__file__).resolve().parent / "acronyms.json"
23+
with ACRONYMS_PATH.open("r", encoding="utf-8") as json_data:
24+
USER_ACRONYMS = json.load(json_data)
25+
2126
def to_title(name: str) -> str:
2227
"""Return *name* in title format with spaces and preserved acronyms."""
2328

@@ -27,10 +32,6 @@ def to_title(name: str) -> str:
2732
# Split on underscores, dashes, or spaces
2833
parts = re.split(r"[_\-\s]+", name)
2934

30-
# Import JSON file containing user-defined acronyms
31-
with open('acronyms.json') as json_data:
32-
user_acronyms = json.load(json_data)
33-
3435
# Capitalize each part, preserving all-uppercase acronyms
3536
words = []
3637
for part in parts:
@@ -41,8 +42,8 @@ def to_title(name: str) -> str:
4142
if not part:
4243
continue
4344

44-
# Check user-defined acronyms from `docs/acronyms.txt`
45-
if part.upper() in user_acronyms:
45+
# Check user-defined acronyms loaded from ``acronyms.json``
46+
if part.upper() in USER_ACRONYMS:
4647
words.append(part.upper())
4748

4849
# If the part is all uppercase and contains only alphanumeric characters,

0 commit comments

Comments
 (0)