@@ -1966,22 +1966,20 @@ def dump(self):
1966
1966
extensions ['py' ] = PythonLanguage
1967
1967
1968
1968
1969
- def file_changed (filename : str , new_contents : str ) -> bool :
1970
- """Return true if file contents changed (meaning we must update it)"""
1969
+ def write_file (filename : str , new_contents : str ) -> None :
1971
1970
try :
1972
- with open (filename , encoding = "utf-8" ) as fp :
1971
+ with open (filename , 'r' , encoding = "utf-8" ) as fp :
1973
1972
old_contents = fp .read ()
1974
- return old_contents != new_contents
1975
- except FileNotFoundError :
1976
- return True
1977
-
1978
1973
1979
- def write_file (filename : str , new_contents : str ):
1974
+ if old_contents == new_contents :
1975
+ # no change: avoid modifying the file modification time
1976
+ return
1977
+ except FileNotFoundError :
1978
+ pass
1980
1979
# Atomic write using a temporary file and os.replace()
1981
1980
filename_new = f"{ filename } .new"
1982
1981
with open (filename_new , "w" , encoding = "utf-8" ) as fp :
1983
1982
fp .write (new_contents )
1984
-
1985
1983
try :
1986
1984
os .replace (filename_new , filename )
1987
1985
except :
@@ -2159,16 +2157,13 @@ def parse(self, input):
2159
2157
traceback .format_exc ().rstrip ())
2160
2158
printer .print_block (block )
2161
2159
2162
- clinic_out = []
2163
-
2164
2160
# these are destinations not buffers
2165
2161
for name , destination in self .destinations .items ():
2166
2162
if destination .type == 'suppress' :
2167
2163
continue
2168
2164
output = destination .dump ()
2169
2165
2170
2166
if output :
2171
-
2172
2167
block = Block ("" , dsl_name = "clinic" , output = output )
2173
2168
2174
2169
if destination .type == 'buffer' :
@@ -2200,11 +2195,10 @@ def parse(self, input):
2200
2195
block .input = 'preserve\n '
2201
2196
printer_2 = BlockPrinter (self .language )
2202
2197
printer_2 .print_block (block , core_includes = True )
2203
- pair = destination .filename , printer_2 .f .getvalue ()
2204
- clinic_out .append (pair )
2198
+ write_file (destination .filename , printer_2 .f .getvalue ())
2205
2199
continue
2206
2200
2207
- return printer .f .getvalue (), clinic_out
2201
+ return printer .f .getvalue ()
2208
2202
2209
2203
2210
2204
def _module_and_class (self , fields ):
@@ -2266,14 +2260,9 @@ def parse_file(
2266
2260
2267
2261
assert isinstance (language , CLanguage )
2268
2262
clinic = Clinic (language , verify = verify , filename = filename )
2269
- src_out , clinic_out = clinic .parse (raw )
2270
-
2271
- changes = [(fn , data ) for fn , data in clinic_out if file_changed (fn , data )]
2272
- if changes :
2273
- # Always (re)write the source file.
2274
- write_file (output , src_out )
2275
- for fn , data in clinic_out :
2276
- write_file (fn , data )
2263
+ cooked = clinic .parse (raw )
2264
+
2265
+ write_file (output , cooked )
2277
2266
2278
2267
2279
2268
def compute_checksum (
0 commit comments