@@ -1954,12 +1954,12 @@ def dump(self):
1954
1954
return_converters = {}
1955
1955
1956
1956
1957
- def write_file (filename , new_contents ):
1957
+ def write_file (filename , new_contents , force = False ):
1958
1958
try :
1959
1959
with open (filename , 'r' , encoding = "utf-8" ) as fp :
1960
1960
old_contents = fp .read ()
1961
1961
1962
- if old_contents == new_contents :
1962
+ if old_contents == new_contents and not force :
1963
1963
# no change: avoid modifying the file modification time
1964
1964
return
1965
1965
except FileNotFoundError :
@@ -2123,6 +2123,8 @@ def parse(self, input):
2123
2123
traceback .format_exc ().rstrip ())
2124
2124
printer .print_block (block )
2125
2125
2126
+ clinic_out = []
2127
+
2126
2128
# these are destinations not buffers
2127
2129
for name , destination in self .destinations .items ():
2128
2130
if destination .type == 'suppress' :
@@ -2162,10 +2164,11 @@ def parse(self, input):
2162
2164
block .input = 'preserve\n '
2163
2165
printer_2 = BlockPrinter (self .language )
2164
2166
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 )
2166
2169
continue
2167
2170
2168
- return printer .f .getvalue ()
2171
+ return printer .f .getvalue (), clinic_out
2169
2172
2170
2173
2171
2174
def _module_and_class (self , fields ):
@@ -2221,9 +2224,13 @@ def parse_file(filename, *, verify=True, output=None):
2221
2224
return
2222
2225
2223
2226
clinic = Clinic (language , verify = verify , filename = filename )
2224
- cooked = clinic .parse (raw )
2227
+ src_out , clinic_out = clinic .parse (raw )
2225
2228
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 )
2227
2234
2228
2235
2229
2236
def compute_checksum (input , length = None ):
0 commit comments