Skip to content

Commit 011c5dc

Browse files
Optimize file reading in init script (#142)
1 parent 2a1780f commit 011c5dc

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎scripts/init.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ def toml_escape(s: str) -> str:
125125

126126
def update_file(filepath: str, file_replacements: list[tuple[re.Pattern, str]]):
127127
path = Path(filepath)
128-
if not path.exists():
128+
try:
129+
content = path.read_text()
130+
except FileNotFoundError:
129131
secho(f" Warning: File {filepath} not found, skipping. ⚠️", fg="yellow")
130132
return
131-
132-
content = path.read_text()
133133
new_content = content
134134
for pattern, replacement in file_replacements:
135135
# Use a lambda for replacement to avoid regex backreference injection

0 commit comments

Comments
 (0)