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

Function preserve_file

noxfile.py:118–128  ·  view source on GitHub ↗

Causes a file to be stored and preserved when the context manager exits.

(filename: Path)

Source from the content-addressed store, hash-verified

116
117@contextlib.contextmanager
118def preserve_file(filename: Path) -> Generator[str, None, None]:
119 """
120 Causes a file to be stored and preserved when the context manager exits.
121 """
122 old_stat = filename.stat()
123 old_file = filename.read_text(encoding="utf-8")
124 try:
125 yield old_file
126 finally:
127 filename.write_text(old_file, encoding="utf-8")
128 os.utime(filename, (old_stat.st_atime, old_stat.st_mtime))
129
130
131@nox.session(reuse_venv=True)

Callers 1

build_globalFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected