diff --git a/crates/re_types/build.rs b/crates/re_types/build.rs index 532085e1a243..9474f9454160 100644 --- a/crates/re_types/build.rs +++ b/crates/re_types/build.rs @@ -133,37 +133,52 @@ fn main() { .to_string_lossy() .to_string(); + // NOTE: This requires both `black` and `ruff` to be in $PATH, but only for contributors, + // not end users. + // Even for contributors, `black` and `ruff` won't be needed unless they edit some of the + // .fbs files... and even then, this won't crash if they are missing, it will just fail to pass + // the CI! + // + // The order below is important and sadly we need to call black twice. Ruff does not yet + // fix line-length (See: https://github.com/astral-sh/ruff/issues/1904). + // + // 1) Call black, which among others things fixes line-length + // 2) Call ruff, which requires line-lengths to be correct + // 3) Call black again to cleanup some whitespace issues ruff might introduce + + call_black(&sh, &pyproject_path); + call_ruff(&sh, &pyproject_path); + call_black(&sh, &pyproject_path); + + write_versioning_hash(SOURCE_HASH_PATH, new_hash); +} + +fn call_black(sh: &Shell, pyproject_path: &String) { // NOTE: We're purposefully ignoring the error here. // - // If the user doesn't have `ruff` in their $PATH, there's still no good reason to fail + // If the user doesn't have `black` in their $PATH, there's still no good reason to fail // the build. // // The CI will catch the unformatted files at PR time and complain appropriately anyhow. cmd!( sh, - "ruff --config {pyproject_path} --fix {PYTHON_OUTPUT_DIR_PATH}" + "black --config {pyproject_path} {PYTHON_OUTPUT_DIR_PATH}" ) .run() .ok(); +} - // NOTE: This requires both `black` and `ruff` to be in $PATH, but only for contributors, - // not end users. - // Even for contributors, `black` and `ruff` won't be needed unless they edit some of the - // .fbs files... and even then, this won't crash if they are missing, it will just fail to pass - // the CI! - +fn call_ruff(sh: &Shell, pyproject_path: &String) { // NOTE: We're purposefully ignoring the error here. // - // If the user doesn't have `black` in their $PATH, there's still no good reason to fail + // If the user doesn't have `ruff` in their $PATH, there's still no good reason to fail // the build. // // The CI will catch the unformatted files at PR time and complain appropriately anyhow. cmd!( sh, - "black --config {pyproject_path} {PYTHON_OUTPUT_DIR_PATH}" + "ruff --config {pyproject_path} --fix {PYTHON_OUTPUT_DIR_PATH}" ) .run() .ok(); - - write_versioning_hash(SOURCE_HASH_PATH, new_hash); } diff --git a/justfile b/justfile index 3bc2251aca71..b059e4c803d8 100644 --- a/justfile +++ b/justfile @@ -75,6 +75,13 @@ py-format: # Note: proto.py relies on old-style annotation to work, and pyupgrade is too opinionated to be disabled from comments # See https://github.com/rerun-io/rerun/pull/2559 for details pyupgrade --py38-plus `find {{py_folders}} -name "*.py" -type f ! -path "examples/python/objectron/proto/objectron/proto.py"` + # The order below is important and sadly we need to call black twice. Ruff does not yet + # fix line-length (See: https://github.com/astral-sh/ruff/issues/1904). + # + # 1) Call black, which among others things fixes line-length + # 2) Call ruff, which requires line-lengths to be correct + # 3) Call black again to cleanup some whitespace issues ruff might introduce + black --config rerun_py/pyproject.toml {{py_folders}} ruff --fix --config rerun_py/pyproject.toml {{py_folders}} black --config rerun_py/pyproject.toml {{py_folders}} blackdoc {{py_folders}}