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,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,
You can’t perform that action at this time.
0 commit comments