MCPcopy Create free account
hub / github.com/pybind/pybind11 / preserve_file

Function preserve_file

tests/extra_python_package/test_files.py:149–156  ·  view source on GitHub ↗
(filename: Path)

Source from the content-addressed store, hash-verified

147
148@contextlib.contextmanager
149def preserve_file(filename: Path) -> Generator[str, None, None]:
150 old_stat = filename.stat()
151 old_file = filename.read_text(encoding="utf-8")
152 try:
153 yield old_file
154 finally:
155 filename.write_text(old_file, encoding="utf-8")
156 os.utime(filename, (old_stat.st_atime, old_stat.st_mtime))
157
158
159@contextlib.contextmanager

Callers 1

build_globalFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected