samples-python icon indicating copy to clipboard operation
samples-python copied to clipboard

Adds ruff as a drop in replacement for black

Open rachfop opened this issue 2 years ago • 6 comments

What was changed

Replaces Black with Ruff formatter.

Recently, ruff added the ability to format: https://docs.astral.sh/ruff/formatter/

Known deviations:

https://docs.astral.sh/ruff/formatter/black/#newlines-are-inserted-after-all-class-docstrings

Removed isort:

Added a skip isort in the .giitignore file: https://pycqa.github.io/isort/docs/configuration/action_comments.html

Ruff respects isort's action comments (# isort: skip_file, # isort: on, # isort: off, # isort: skip, and # isort: split), which enable selectively enabling and disabling import sorting for blocks of code and other inline configuration.

Ruff uses isort's profile = black by default: https://docs.astral.sh/ruff/faq/#how-does-ruffs-import-sorting-compare-to-isort>

Ruff's import sorting is intended to be near-equivalent to isort's when using isort's profile = "black".

Why?

Faster 🐎

Checklist

  1. Closes

  2. How was this tested:

  1. Any docs updates needed?

rachfop avatar Nov 03 '23 20:11 rachfop

Nice! I'd like to see about doing this to our SDK repo too. Can it replace isort too?

cretz avatar Nov 03 '23 22:11 cretz

Good call. Removed isort and updated the description of this pr with how it works.

rachfop avatar Nov 05 '23 04:11 rachfop

@rachfop - Not understanding exactly. So does this provide all the import sorting benefit of isort? If we're removing isort, why have a comment in the gitignore relating to the tool we don't use/support anymore?

cretz avatar Nov 06 '23 14:11 cretz

Ruff supports isort's action comments, so we can remove isort from the pyproject.tom, but use isort's skip_file and ruff wil respect that. I only included that because it was a part of the original pyproject.toml sorting logic.

rachfop avatar Nov 06 '23 18:11 rachfop

Looks like a lock conflict. I think you can merge main and just run poetry lock --no-update to fix

cretz avatar Nov 09 '23 15:11 cretz

Resolved merge!

rachfop avatar Nov 09 '23 17:11 rachfop