MCPcopy Create free account
hub / github.com/ipython/ipython / write_file

Method write_file

IPython/extensions/tests/test_autoreload.py:94–115  ·  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

92 return module_name, file_name
93
94 def write_file(self, filename, content):
95 """
96 Write a file, and force a timestamp difference of at least one second
97
98 Notes
99 -----
100 Python's .pyc files record the timestamp of their compilation
101 with a time resolution of one second.
102
103 Therefore, we need to force a timestamp difference between .py
104 and .pyc, without having the .py file be timestamped in the
105 future, and without changing the timestamp of the .pyc file
106 (because that is stored in the file). The only reliable way
107 to achieve this seems to be to sleep.
108 """
109 content = textwrap.dedent(content)
110 # Sleep one second + eps
111 time.sleep(1.05)
112
113 # Write
114 with open(filename, 'w') as f:
115 f.write(content)
116
117 def new_module(self, code):
118 code = textwrap.dedent(code)

Callers 4

test_reload_enumsMethod · 0.80
_check_smoketestMethod · 0.80

Calls 1

writeMethod · 0.45

Tested by

no test coverage detected