Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a10471a
Clean up _freeze_importlib.c.
ericsnowcurrently Jun 10, 2021
6252a37
_freeze_importlib -> _freeze_module
ericsnowcurrently Aug 10, 2021
b230af8
Add tooling to freeze stdlib modules.
ericsnowcurrently Jun 8, 2021
e4ef8fc
Support freezing a package's submodules.
ericsnowcurrently Aug 10, 2021
6bcc8c9
Use freeze_modules.py for all frozen modules.
ericsnowcurrently Aug 11, 2021
1cae771
Regen frozen.c and Makefile.pre.in.
ericsnowcurrently Aug 11, 2021
ba9417c
Add the updating_file_with_tmpfile() "tool".
ericsnowcurrently Aug 11, 2021
6dcb926
Regen frozen.c in place.
ericsnowcurrently Aug 11, 2021
8a2b4b7
Clean up.
ericsnowcurrently Aug 11, 2021
8ad3c1d
Add --no-regen.
ericsnowcurrently Aug 11, 2021
1e88d34
Be consistent about the frozen module filename (frozen_*.h).
ericsnowcurrently Aug 12, 2021
c4874f2
Use consistently named make targets for regen-frozen-*.
ericsnowcurrently Aug 12, 2021
06af093
Drop the stdlib placeholders.
ericsnowcurrently Aug 12, 2021
3a036b7
Simplify FROZEN a little.
ericsnowcurrently Aug 12, 2021
6a27a1d
Combine FROZEN and MODULES.
ericsnowcurrently Aug 12, 2021
e3e07a9
Drop the frozen module groups.
ericsnowcurrently Aug 12, 2021
3d2ebdb
Fix a typo.
ericsnowcurrently Aug 12, 2021
9a5141f
Fix the Makefile.
ericsnowcurrently Aug 24, 2021
3687fda
Make freeze_modules.py less fragile.
gvanrossum Aug 24, 2021
1331a77
Simplify specs.
ericsnowcurrently Aug 25, 2021
30972b2
Explicitly freeze modules in Makefile.
ericsnowcurrently Aug 25, 2021
7a4a876
Fix a typo.
ericsnowcurrently Aug 25, 2021
1306a4e
Fix dependencies.
ericsnowcurrently Aug 25, 2021
f724deb
Drop some dead code.
ericsnowcurrently Aug 25, 2021
9a4d120
Fix another typo.
ericsnowcurrently Aug 25, 2021
54b0116
Generate the frozen file in-place rather than with a temp file.
ericsnowcurrently Aug 25, 2021
16adb8e
Update Windows build config.
ericsnowcurrently Aug 24, 2021
2d51cba
Move frozen modules into their own directory.
ericsnowcurrently Aug 26, 2021
5cfd853
Add a NEWS entry.
ericsnowcurrently Aug 26, 2021
0905b51
Fix a typo.
ericsnowcurrently Aug 26, 2021
55e1ffc
Fix outdated comments.
ericsnowcurrently Aug 30, 2021
b970fa3
Avoid buffer overflows.
ericsnowcurrently Aug 30, 2021
99daab4
Freeze the modules when running "make regen-frozen".
ericsnowcurrently Aug 30, 2021
10a14de
Be more verbose about what is running in freeze_modules.py.
ericsnowcurrently Aug 30, 2021
2651962
Update the explanation in frozen.c.
ericsnowcurrently Aug 30, 2021
7406c58
Mark all frozen modules as "generated".
ericsnowcurrently Aug 30, 2021
f4c136e
Drop a superfluous comment.
ericsnowcurrently Aug 30, 2021
2730169
Drop the CLI.
ericsnowcurrently Aug 30, 2021
d84fd85
Use update_file_with_tmpfile() in updating_file_with_tmpfile().
ericsnowcurrently Aug 30, 2021
cd8fe0a
Do not update the file if there was an error.
ericsnowcurrently Aug 30, 2021
9a97726
Fix the check_generated_files CI job.
ericsnowcurrently Aug 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add the updating_file_with_tmpfile() "tool".
  • Loading branch information
ericsnowcurrently committed Aug 26, 2021
commit ba9417cf169e15facca67578f01c0e0a618b47ba
40 changes: 34 additions & 6 deletions Tools/scripts/update_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,51 @@
actually change the in-tree generated code.
"""

import contextlib
import os
import os.path
import sys


def main(old_path, new_path):
with open(old_path, 'rb') as f:
@contextlib.contextmanager
def updating_file_with_tmpfile(filename, tmpfile=None):
"""A context manager for updating a file via a temp file.

The context manager provides two open files: the source file open
for reading, and the temp file, open for writing.

Upon exiting: both files are closed, and the source file is replaced
with the temp file.
"""
# XXX Optionally use tempfile.TemporaryFile?
if not tmpfile:
tmpfile = filename + '.tmp'
elif os.path.isdir(tmpfile):
tmpfile = os.path.join(tmpfile, filename + '.tmp')

try:
with open(tmpfile, 'w') as outfile:
with open(filename) as infile:
yield infile, outfile
os.replace(tmpfile, filename)
finally:
if os.path.exists(tmpfile):
os.remove(tmpfile)


def update_file_with_tmpfile(filename, tmpfile):
Comment thread
gvanrossum marked this conversation as resolved.
with open(filename, 'rb') as f:
old_contents = f.read()
with open(new_path, 'rb') as f:
with open(tmpfile, 'rb') as f:
new_contents = f.read()
if old_contents != new_contents:
os.replace(new_path, old_path)
os.replace(tmpfile, filename)
else:
os.unlink(new_path)
os.unlink(tmpfile)


if __name__ == '__main__':
if len(sys.argv) != 3:
print("Usage: %s <path to be updated> <path with new contents>" % (sys.argv[0],))
sys.exit(1)
main(sys.argv[1], sys.argv[2])
update_file_with_tmpfile(sys.argv[1], sys.argv[2])