@@ -2021,22 +2021,20 @@ def dump(self):
2021
2021
extensions ['py' ] = PythonLanguage
2022
2022
2023
2023
2024
- def file_changed (filename : str , new_contents : str ) -> bool :
2025
- """Return true if file contents changed (meaning we must update it)"""
2024
+ def write_file (filename : str , new_contents : str ) -> None :
2026
2025
try :
2027
- with open (filename , encoding = "utf-8" ) as fp :
2026
+ with open (filename , 'r' , encoding = "utf-8" ) as fp :
2028
2027
old_contents = fp .read ()
2029
- return old_contents != new_contents
2030
- except FileNotFoundError :
2031
- return True
2032
2028
2033
-
2034
- def write_file (filename : str , new_contents : str ) -> None :
2029
+ if old_contents == new_contents :
2030
+ # no change: avoid modifying the file modification time
2031
+ return
2032
+ except FileNotFoundError :
2033
+ pass
2035
2034
# Atomic write using a temporary file and os.replace()
2036
2035
filename_new = f"{ filename } .new"
2037
2036
with open (filename_new , "w" , encoding = "utf-8" ) as fp :
2038
2037
fp .write (new_contents )
2039
-
2040
2038
try :
2041
2039
os .replace (filename_new , filename )
2042
2040
except :
@@ -2214,16 +2212,13 @@ def parse(self, input):
2214
2212
traceback .format_exc ().rstrip ())
2215
2213
printer .print_block (block )
2216
2214
2217
- clinic_out = []
2218
-
2219
2215
# these are destinations not buffers
2220
2216
for name , destination in self .destinations .items ():
2221
2217
if destination .type == 'suppress' :
2222
2218
continue
2223
2219
output = destination .dump ()
2224
2220
2225
2221
if output :
2226
-
2227
2222
block = Block ("" , dsl_name = "clinic" , output = output )
2228
2223
2229
2224
if destination .type == 'buffer' :
@@ -2255,11 +2250,10 @@ def parse(self, input):
2255
2250
block .input = 'preserve\n '
2256
2251
printer_2 = BlockPrinter (self .language )
2257
2252
printer_2 .print_block (block , core_includes = True )
2258
- pair = destination .filename , printer_2 .f .getvalue ()
2259
- clinic_out .append (pair )
2253
+ write_file (destination .filename , printer_2 .f .getvalue ())
2260
2254
continue
2261
2255
2262
- return printer .f .getvalue (), clinic_out
2256
+ return printer .f .getvalue ()
2263
2257
2264
2258
2265
2259
def _module_and_class (self , fields ):
@@ -2321,14 +2315,9 @@ def parse_file(
2321
2315
2322
2316
assert isinstance (language , CLanguage )
2323
2317
clinic = Clinic (language , verify = verify , filename = filename )
2324
- src_out , clinic_out = clinic .parse (raw )
2325
-
2326
- changes = [(fn , data ) for fn , data in clinic_out if file_changed (fn , data )]
2327
- if changes :
2328
- # Always (re)write the source file.
2329
- write_file (output , src_out )
2330
- for fn , data in clinic_out :
2331
- write_file (fn , data )
2318
+ cooked = clinic .parse (raw )
2319
+
2320
+ write_file (output , cooked )
2332
2321
2333
2322
2334
2323
def compute_checksum (
0 commit comments