Skip to content

Commit 6ca580c

Browse files
pythongh-64595: Argument Clinic: Touch source file if any output file changed
1 parent 35d2738 commit 6ca580c

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Diff for: Tools/clinic/clinic.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -1943,12 +1943,12 @@ def dump(self):
19431943
return_converters = {}
19441944

19451945

1946-
def write_file(filename, new_contents):
1946+
def write_file(filename, new_contents, force=False):
19471947
try:
19481948
with open(filename, 'r', encoding="utf-8") as fp:
19491949
old_contents = fp.read()
19501950

1951-
if old_contents == new_contents:
1951+
if old_contents == new_contents and not force:
19521952
# no change: avoid modifying the file modification time
19531953
return
19541954
except FileNotFoundError:
@@ -2112,6 +2112,8 @@ def parse(self, input):
21122112
traceback.format_exc().rstrip())
21132113
printer.print_block(block)
21142114

2115+
clinic_out = []
2116+
21152117
# these are destinations not buffers
21162118
for name, destination in self.destinations.items():
21172119
if destination.type == 'suppress':
@@ -2151,10 +2153,11 @@ def parse(self, input):
21512153
block.input = 'preserve\n'
21522154
printer_2 = BlockPrinter(self.language)
21532155
printer_2.print_block(block, core_includes=True)
2154-
write_file(destination.filename, printer_2.f.getvalue())
2156+
pair = destination.filename, printer_2.f.getvalue()
2157+
clinic_out.append(pair)
21552158
continue
21562159

2157-
return printer.f.getvalue()
2160+
return printer.f.getvalue(), clinic_out
21582161

21592162

21602163
def _module_and_class(self, fields):
@@ -2210,9 +2213,12 @@ def parse_file(filename, *, verify=True, output=None):
22102213
return
22112214

22122215
clinic = Clinic(language, verify=verify, filename=filename)
2213-
cooked = clinic.parse(raw)
2216+
src_out, clinic_out = clinic.parse(raw)
22142217

2215-
write_file(output, cooked)
2218+
force = bool(clinic_out)
2219+
write_file(output, src_out, force=force)
2220+
for fn, data in clinic_out:
2221+
write_file(fn, data)
22162222

22172223

22182224
def compute_checksum(input, length=None):

0 commit comments

Comments
 (0)