@@ -392,36 +392,35 @@ def _run_post_processor(output: str, library_id: str, is_mono_repo: bool):
392392 # This replaces both 'isort' and 'black' and runs in < 1 second.
393393 # We hardcode flags here to match Black defaults so you don't need config files.
394394 # logger.info("🚀 Running Ruff (Fast Formatter)...")
395+ ruff_config_path = Path ("/usr/local/google/home/omairn/git/googleapis/google-cloud-python/.generator/ruff.toml" ).resolve ()
396+
397+ if not ruff_config_path .exists ():
398+ logger .warning (f"⚠️ Could not find Ruff config at { ruff_config_path } . Using defaults." )
399+
395400 try :
401+
402+ subprocess .run (["ruff" , "--version" ], check = False )
403+ logger .info ("Running Ruff Check (Imports)..." )
404+ base_args = ["ruff" , "--config" , str (ruff_config_path )]
405+
396406 # STEP A: Fix Imports (like isort)
397407 subprocess .run (
398- [
399- "ruff" , "check" ,
400- "--select" , "I" , # Only run Import sorting rules
401- "--fix" , # Auto-fix them
402- "--line-length=88" , # Match Black default
403- "--known-first-party=google" , # Prevent 'google' moving to 3rd party block
404- output
405- ],
406- check = False ,
407- stdout = subprocess .DEVNULL ,
408- stderr = subprocess .DEVNULL
408+ base_args + ["check" , "--fix" , "." ],
409+ check = True ,
409410 )
410411
411412 # STEP B: Format Code (like black)
412413 subprocess .run (
413- [
414- "ruff" , "format" ,
415- "--line-length=88" , # Match Black default
416- output
417- ],
418- check = False ,
419- stdout = subprocess .DEVNULL ,
420- stderr = subprocess .DEVNULL
414+ base_args + ["format" , "." ],
415+ check = True ,
421416 )
417+ logger .info ("Ruff formatting completed successfully." )
418+
422419 except FileNotFoundError :
423420 logger .warning ("⚠️ Ruff binary not found. Code will be unformatted." )
424421 logger .warning (" Please run: pip install ruff" )
422+ except subprocess .CalledProcessError as e :
423+ logger .error (f"❌ Ruff failed with exit code { e .returncode } ." )
425424
426425 logger .info ("Python post-processor ran successfully." )
427426
0 commit comments