MCPcopy
hub / github.com/astral-sh/python-build-standalone / static_replace_in_file

Function static_replace_in_file

cpython-windows/build.py:293–311  ·  view source on GitHub ↗

Replace occurrences of a string in a file. The updated file contents are written out in place.

(p: pathlib.Path, search, replace)

Source from the content-addressed store, hash-verified

291
292
293def static_replace_in_file(p: pathlib.Path, search, replace):
294 """Replace occurrences of a string in a file.
295
296 The updated file contents are written out in place.
297 """
298
299 with p.open("rb") as fh:
300 data = fh.read()
301
302 # Build should be as deterministic as possible. Assert that wanted changes
303 # actually occur.
304 if search not in data:
305 raise NoSearchStringError("search string (%s) not in %s" % (search, p))
306
307 log("replacing `%s` with `%s` in %s" % (search, replace, p))
308 data = data.replace(search, replace)
309
310 with p.open("wb") as fh:
311 fh.write(data)
312
313
314def apply_source_patch(cpython_source_path: pathlib.Path, patch_path: pathlib.Path):

Callers 3

hack_propsFunction · 0.85
hack_project_filesFunction · 0.85
build_openssl_for_archFunction · 0.85

Calls 2

NoSearchStringErrorClass · 0.85
logFunction · 0.70

Tested by

no test coverage detected