File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change 1818import re
1919from 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+
2126def to_title (name : str ) -> str :
2227 """Return *name* in title format with spaces and preserved acronyms."""
2328
@@ -27,19 +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 :
3738 # Skip empty parts that may result from leading/trailing separators
3839 if not part :
3940 continue
4041
41- # Check user-defined acronyms from `docs/ acronyms.txt `
42- if part .upper () in user_acronyms :
42+ # Check user-defined acronyms loaded from `` acronyms.json` `
43+ if part .upper () in USER_ACRONYMS :
4344 words .append (part .upper ())
4445
4546 # If the part is all uppercase and contains only alphanumeric characters,
You can’t perform that action at this time.
0 commit comments