Skip to content

Commit c099d40

Browse files
committed
# Conflicts: # .scripts/gen_markdown_chapters.py
2 parents 3c3e9c7 + f5d41ca commit c099d40

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

.scripts/gen_markdown_chapters.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""Generate aggregated Markdown files for each examples subfolder.
33
44
Usage:
5-
python .scripts/examples_to_markdown_files.py \
5+
python .scripts/gen_markdown_chapters.py \
66
--examples-dir examples \
77
--output-dir docs
88
@@ -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,22 +32,15 @@ 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:
37-
38-
print(part)
39-
4038
# Skip empty parts that may result from leading/trailing separators
4139
if not part:
4240
continue
4341

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

4846
# If the part is all uppercase and contains only alphanumeric characters,
@@ -56,13 +54,6 @@ def to_title(name: str) -> str:
5654

5755
return " ".join(words)
5856

59-
def to_camel_case(name: str) -> str:
60-
"""Return *name* converted to CamelCase without leading digits."""
61-
# Strip leading numeric prefixes like ``01_``
62-
name = re.sub(r"^\d+_?", "", name)
63-
parts = re.split(r"[_\-\s]+", name)
64-
return " ".join(word.capitalize() for word in parts if word)
65-
6657
def generate_aggregate(folder: Path, output_dir: Path) -> None:
6758
"""Create a single Markdown file aggregating all examples in *folder*."""
6859
examples = []

.scripts/gen_markdown_pages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""Generate a Markdown file for each Python example.
33
44
Usage:
5-
python .scripts/examples_to_markdown_files.py \
5+
python .scripts/gen_markdown_pages.py \
66
--examples-dir examples \
77
--template templates/example_file.mustache \
88
--output-dir docs

.scripts/gen_single_markdown.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""Generate a Markdown page from Python example files.
33
44
Usage::
5-
python .scripts/examples_to_markdown.py \
5+
python .scripts/gen_single_markdown.py \
66
--examples-dir examples \
77
--template templates/examples_page.mustache \
88
--output examples.md

0 commit comments

Comments
 (0)