Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 45a9e38

Browse filesBrowse files
gh-64595: Argument Clinic: Touch source file if any output file changed (#104152)
1 parent d0b4abe commit 45a9e38
Copy full SHA for 45a9e38

File tree

Expand file treeCollapse file tree

2 files changed

+17
-9
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-9
lines changed

‎Lib/test/test_clinic.py

Copy file name to clipboardExpand all lines: Lib/test/test_clinic.py
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ def test_eol(self):
9999
# the last line of the block got corrupted.
100100
c = clinic.Clinic(clinic.CLanguage(None), filename="file")
101101
raw = "/*[clinic]\nfoo\n[clinic]*/"
102-
cooked = c.parse(raw).splitlines()
103-
end_line = cooked[2].rstrip()
102+
cooked, _ = c.parse(raw)
103+
lines = cooked.splitlines()
104+
end_line = lines[2].rstrip()
104105
# this test is redundant, it's just here explicitly to catch
105106
# the regression test so we don't forget what it looked like
106107
self.assertNotEqual(end_line, "[clinic]*/[clinic]*/")
@@ -259,7 +260,7 @@ def _test_clinic(self, input, output):
259260
c = clinic.Clinic(language, filename="file")
260261
c.parsers['inert'] = InertParser(c)
261262
c.parsers['copy'] = CopyParser(c)
262-
computed = c.parse(input)
263+
computed, _ = c.parse(input)
263264
self.assertEqual(output, computed)
264265

265266
def test_clinic_1(self):

‎Tools/clinic/clinic.py

Copy file name to clipboardExpand all lines: Tools/clinic/clinic.py
+13-6Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,12 +1954,12 @@ def dump(self):
19541954
return_converters = {}
19551955

19561956

1957-
def write_file(filename, new_contents):
1957+
def write_file(filename, new_contents, force=False):
19581958
try:
19591959
with open(filename, 'r', encoding="utf-8") as fp:
19601960
old_contents = fp.read()
19611961

1962-
if old_contents == new_contents:
1962+
if old_contents == new_contents and not force:
19631963
# no change: avoid modifying the file modification time
19641964
return
19651965
except FileNotFoundError:
@@ -2123,6 +2123,8 @@ def parse(self, input):
21232123
traceback.format_exc().rstrip())
21242124
printer.print_block(block)
21252125

2126+
clinic_out = []
2127+
21262128
# these are destinations not buffers
21272129
for name, destination in self.destinations.items():
21282130
if destination.type == 'suppress':
@@ -2162,10 +2164,11 @@ def parse(self, input):
21622164
block.input = 'preserve\n'
21632165
printer_2 = BlockPrinter(self.language)
21642166
printer_2.print_block(block, core_includes=True)
2165-
write_file(destination.filename, printer_2.f.getvalue())
2167+
pair = destination.filename, printer_2.f.getvalue()
2168+
clinic_out.append(pair)
21662169
continue
21672170

2168-
return printer.f.getvalue()
2171+
return printer.f.getvalue(), clinic_out
21692172

21702173

21712174
def _module_and_class(self, fields):
@@ -2221,9 +2224,13 @@ def parse_file(filename, *, verify=True, output=None):
22212224
return
22222225

22232226
clinic = Clinic(language, verify=verify, filename=filename)
2224-
cooked = clinic.parse(raw)
2227+
src_out, clinic_out = clinic.parse(raw)
22252228

2226-
write_file(output, cooked)
2229+
# If clinic output changed, force updating the source file as well.
2230+
force = bool(clinic_out)
2231+
write_file(output, src_out, force=force)
2232+
for fn, data in clinic_out:
2233+
write_file(fn, data)
22272234

22282235

22292236
def compute_checksum(input, length=None):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.