symforce.codegen.format_util module

format_cpp(file_contents, filename)[source]

Autoformat a given C++ file using clang-format

Parameters:
  • file_contents (str) – The unformatted contents of the file

  • filename (str) – A name that this file might have on disk; this does not have to be a real path, it’s only used for clang-format to find the correct style file (by traversing upwards from this location) and to decide if an include is the corresponding .h file for a .cc file that’s being formatted (this affects the include order)

Returns:

formatted_file_contents (str) – The contents of the file after formatting

Return type:

str

format_py(file_contents, filename)[source]

Autoformat a given Python file using ruff

Parameters:
  • filename (str) – A name that this file might have on disk; this does not have to be a real path, it’s only used for ruff to find the correct style file (by traversing upwards from this location)

  • file_contents (str) –

Return type:

str

format_py_dir(dirname)[source]

Autoformat python files in a directory (recursively) in-place

Parameters:

dirname (str | PathLike) –

Return type:

None