MCPcopy Index your code
hub / github.com/ipython/ipython / write_file

Method write_file

tests/test_zzz_autoreload.py:129–150  ·  view source on GitHub ↗

Write a file, and force a timestamp difference of at least one second Notes ----- Python's .pyc files record the timestamp of their compilation with a time resolution of one second. Therefore, we need to force a timestamp difference between .py

(self, filename, content)

Source from the content-addressed store, hash-verified

127 return module_name, file_name
128
129 def write_file(self, filename, content):
130 """
131 Write a file, and force a timestamp difference of at least one second
132
133 Notes
134 -----
135 Python's .pyc files record the timestamp of their compilation
136 with a time resolution of one second.
137
138 Therefore, we need to force a timestamp difference between .py
139 and .pyc, without having the .py file be timestamped in the
140 future, and without changing the timestamp of the .pyc file
141 (because that is stored in the file). The only reliable way
142 to achieve this seems to be to sleep.
143 """
144 content = textwrap.dedent(content)
145 # Sleep one second + eps
146 time.sleep(1.05)
147
148 # Write
149 with open(filename, "w", encoding="utf-8") as f:
150 f.write(content)
151
152 def new_module(self, code):
153 code = textwrap.dedent(code)

Calls 1

writeMethod · 0.45

Tested by

no test coverage detected