Skip to content

Commit

Permalink
Alternative implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
erlend-aasland committed May 15, 2023
1 parent 15bf463 commit 2a20f90
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1975,11 +1975,7 @@ def file_changed(filename: str, new_contents: str) -> bool:
return True


def write_file(filename: str, new_contents: str, force=False):
if not force and not file_changed(filename, new_contents):
# no change: avoid modifying the file modification time
return

def write_file(filename: str, new_contents: str):
# Atomic write using a temporary file and os.replace()
filename_new = f"{filename}.new"
with open(filename_new, "w", encoding="utf-8") as fp:
Expand Down Expand Up @@ -2241,11 +2237,12 @@ def parse_file(filename, *, verify=True, output=None):
clinic = Clinic(language, verify=verify, filename=filename)
src_out, clinic_out = clinic.parse(raw)

# If clinic output changed, force updating the source file as well.
force = any(file_changed(fn, data) for fn, data in clinic_out)
write_file(output, src_out, force=force)
for fn, data in clinic_out:
write_file(fn, data)
changes = [(fn, data) for fn, data in clinic_out if file_changed(fn, data)]
if changes:
# Always (re)write the source file.
write_file(output, src_out)
for fn, data in clinic_out:
write_file(fn, data)


def compute_checksum(input, length=None):
Expand Down

0 comments on commit 2a20f90

Please sign in to comment.