From ffd96ee33c0f0e8bc350d64d85181ef77fcfb90a Mon Sep 17 00:00:00 2001 From: Aaron Miller Date: Fri, 26 Dec 2025 18:39:23 -0800 Subject: [PATCH] Fix ruff format of types from wheel format_py_dir doesn't work because it doesn't use the ruff config. Example failure: https://github.com/symforce-org/symforce/actions/runs/20531137563/job/58982549124?pr=450 Here we have a line between 80 and 100 chars, so with the correct config, it stays on the same line. If you format it with an 80-char config and then a 100-char config though, it's broken across lines and the trailing comma is added, so formatting with 100 chars doesn't put it back on one line. And it has to be a list for the trailing comma thing to happen, that's why this is pretty rare. Topic: sf-ruff-wheel-types --- symforce/codegen/codegen_util.py | 3 ++- symforce/codegen/format_util.py | 15 --------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/symforce/codegen/codegen_util.py b/symforce/codegen/codegen_util.py index 440c53f0..8165489f 100644 --- a/symforce/codegen/codegen_util.py +++ b/symforce/codegen/codegen_util.py @@ -772,7 +772,8 @@ def generate_lcm_types( ) # Autoformat generated python files - format_util.format_py_dir(python_types_dir) + for f in python_types_dir.rglob("*.py"): + f.write_text(format_util.format_py(f.read_text(), str(Path(__file__).parent / f.name))) return result diff --git a/symforce/codegen/format_util.py b/symforce/codegen/format_util.py index 558f1193..3c4a360e 100644 --- a/symforce/codegen/format_util.py +++ b/symforce/codegen/format_util.py @@ -91,21 +91,6 @@ def format_py(file_contents: str, filename: str) -> str: return result.stdout -def format_py_dir(dirname: T.Openable) -> None: - """ - Autoformat python files in a directory (recursively) in-place - """ - subprocess.run( - [find_ruff_bin(), "format", dirname], - check=True, - # Disable the ruff cache. This is important for running in a hermetic context like a bazel - # test, and shouldn't really hurt other use cases. If it does, we should work around this - # differently. - env=dict(os.environ, RUFF_NO_CACHE="true"), - text=True, - ) - - _rustfmt_path: T.Optional[Path] = None