@@ -271,26 +271,32 @@ async def _async_main() -> None:
271271 for i , part in enumerate (gen .split_sources ()):
272272 output = Path (args .output )
273273 output = output .with_suffix (f'.{ i } { output .suffix } ' )
274- with open (output , 'w' , encoding = 'utf-8' ) as fp :
275- json .dump (part , fp , indent = ManifestGenerator .JSON_INDENT )
274+ await asyncio .to_thread (
275+ output .write_text ,
276+ json .dumps (part , indent = ManifestGenerator .JSON_INDENT ),
277+ encoding = 'utf-8' ,
278+ )
276279 delattr (gen , '_upgraded_sources' )
277280 print (f'Wrote { gen .source_count } to { i + 1 } file(s).' )
278281 else :
279282 sources = list (gen .ordered_sources ())
280283 await Requests .instance .upgrade_to_sha256 (sources )
281- with open (args .output , 'w' , encoding = 'utf-8' ) as fp :
282- json .dump (
283- sources ,
284- fp ,
285- indent = ManifestGenerator .JSON_INDENT ,
284+ output_path = Path (args .output )
285+ data = json .dumps (
286+ sources ,
287+ indent = ManifestGenerator .JSON_INDENT ,
288+ )
289+ await asyncio .to_thread (
290+ output_path .write_text ,
291+ data ,
292+ encoding = 'utf-8' ,
293+ )
294+ if len (data .encode ('utf-8' )) >= gen .split_size :
295+ print (
296+ 'WARNING: generated-sources.json is too large for GitHub.' ,
297+ file = sys .stderr ,
286298 )
287-
288- if fp .tell () >= gen .split_size :
289- print (
290- 'WARNING: generated-sources.json is too large for GitHub.' ,
291- file = sys .stderr ,
292- )
293- print (' (Pass -s to enable splitting.)' )
299+ print (' (Pass -s to enable splitting.)' )
294300
295301 print (f'Wrote { gen .source_count } source(s).' )
296302
0 commit comments