MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / process_file

Function process_file

scripts/website/bulk_mechanical_fix.py:134–154  ·  view source on GitHub ↗
(path, opts, counts)

Source from the content-addressed store, hash-verified

132
133
134def process_file(path, opts, counts):
135 with open(path, "r", encoding="utf-8") as fh:
136 original = fh.read()
137 front_matter, body, _start = blog_text.split_front_matter(original)
138 new_body = transform_body(body, opts, counts)
139 if new_body == body:
140 return None
141 # Guardrails: front matter byte-identical; protected constructs and the word
142 # sequence unchanged (we only ever delete whitespace, never characters).
143 new_full = front_matter + new_body
144 assert new_full.startswith(front_matter), f"front matter changed in {path}"
145 before, after = _invariants(body), _invariants(new_body)
146 for key in ("code_spans", "shortcodes", "links", "words"):
147 if before[key] != after[key]:
148 raise AssertionError(
149 f"{path}: transform changed protected content ({key}); refusing to write"
150 )
151 if opts["write"]:
152 with open(path, "w", encoding="utf-8") as fh:
153 fh.write(new_full)
154 return path
155
156
157def expand_paths(paths):

Callers 1

mainFunction · 0.70

Calls 5

transform_bodyFunction · 0.85
_invariantsFunction · 0.85
readMethod · 0.65
writeMethod · 0.65
AssertionErrorClass · 0.50

Tested by

no test coverage detected