@@ -363,8 +363,6 @@ def _run_datamodel_codegen(input_path: Path, output_path: Path) -> subprocess.Co
363363 "--set-default-enum-member" ,
364364 "--enum-field-as-literal" ,
365365 "one" ,
366- "--formatters" ,
367- "ruff-format" ,
368366 ]
369367
370368 return subprocess .run (
@@ -379,57 +377,56 @@ def _print_codegen_output(result: subprocess.CompletedProcess[str]) -> None:
379377 print (result .stdout )
380378
381379
382- def _generate_split_bundled_media_buy (input_dir : Path ) -> bool :
383- """Generate bundled/media_buy schemas separately.
380+ def _restore_optional_temp_dir (source : Path , target : Path ) -> None :
381+ if source .exists ():
382+ target .parent .mkdir (parents = True , exist_ok = True )
383+ shutil .move (str (source ), str (target ))
384384
385- The fully bundled media-buy directory is large enough that
386- datamodel-code-generator can spend minutes trying to deduplicate the
387- combined inline graph. Generating those bundled message schemas one file
388- at a time preserves the import surface while keeping regeneration bounded.
389- """
390- split_dir = input_dir / "bundled" / "media_buy"
391- if not split_dir .exists ():
392- return True
393-
394- output_dir = OUTPUT_DIR / "bundled" / "media_buy"
395- output_dir .mkdir (parents = True , exist_ok = True )
396- for package_dir in (OUTPUT_DIR / "bundled" , output_dir ):
397- init_file = package_dir / "__init__.py"
398- init_file .touch (exist_ok = True )
399-
400- print (f"Generating split bundled media-buy types from { split_dir } ..." )
401- for schema_file in sorted (split_dir .glob ("*.json" )):
402- output_file = output_dir / f"{ schema_file .stem } .py"
403- print (f" { schema_file .name } " )
404- result = _run_datamodel_codegen (schema_file , output_file )
405- _print_codegen_output (result )
406- if result .returncode != 0 :
407- print ("\n ✗ Split bundled media-buy generation failed:" , file = sys .stderr )
408- print (result .stderr , file = sys .stderr )
409- return False
410385
411- return True
386+ def _hold_unused_bundled_dirs (input_dir : Path ) -> Path :
387+ """Move bundled subtrees that are pruned later out of the generator input."""
388+ bundled_dir = input_dir / BUNDLED_DIR_NAME
389+ held_bundled_dir = input_dir .parent / f"{ input_dir .name } _bundled_held"
390+
391+ if held_bundled_dir .exists ():
392+ shutil .rmtree (held_bundled_dir )
393+ if not bundled_dir .exists ():
394+ return held_bundled_dir
395+
396+ shutil .move (str (bundled_dir ), str (held_bundled_dir ))
397+
398+ protocol_dir = held_bundled_dir / "protocol"
399+ if protocol_dir .exists ():
400+ bundled_dir .mkdir (parents = True , exist_ok = True )
401+ shutil .move (str (protocol_dir ), str (bundled_dir / "protocol" ))
402+
403+ return held_bundled_dir
404+
405+
406+ def _restore_unused_bundled_dirs (input_dir : Path , held_bundled_dir : Path ) -> None :
407+ bundled_dir = input_dir / BUNDLED_DIR_NAME
408+ protocol_dir = bundled_dir / "protocol"
409+
410+ if protocol_dir .exists ():
411+ held_bundled_dir .mkdir (parents = True , exist_ok = True )
412+ shutil .move (str (protocol_dir ), str (held_bundled_dir / "protocol" ))
413+
414+ if bundled_dir .exists () and not any (bundled_dir .iterdir ()):
415+ bundled_dir .rmdir ()
416+
417+ _restore_optional_temp_dir (held_bundled_dir , bundled_dir )
412418
413419
414420def generate_types (input_dir : Path ):
415421 """Generate types using datamodel-code-generator."""
416422 print (f"Generating types from { input_dir } ..." )
417423
418- split_dir = input_dir / "bundled" / "media_buy"
419- held_split_dir = input_dir .parent / f"{ input_dir .name } _bundled_media_buy_split"
420-
421- if held_split_dir .exists ():
422- shutil .rmtree (held_split_dir )
423-
424- if split_dir .exists ():
425- shutil .move (str (split_dir ), str (held_split_dir ))
424+ held_bundled_dir = _hold_unused_bundled_dirs (input_dir )
426425
427426 try :
428427 result = _run_datamodel_codegen (input_dir , OUTPUT_DIR )
429428 finally :
430- if held_split_dir .exists ():
431- split_dir .parent .mkdir (parents = True , exist_ok = True )
432- shutil .move (str (held_split_dir ), str (split_dir ))
429+ _restore_unused_bundled_dirs (input_dir , held_bundled_dir )
433430
434431 _print_codegen_output (result )
435432
@@ -438,9 +435,6 @@ def generate_types(input_dir: Path):
438435 print (result .stderr , file = sys .stderr )
439436 return False
440437
441- if not _generate_split_bundled_media_buy (input_dir ):
442- return False
443-
444438 return True
445439
446440
0 commit comments