Skip to content

Conversation

@jhamon
Copy link
Collaborator

@jhamon jhamon commented Sep 25, 2024

Problem

While researching how to integrate some rust extensions into our python, I heard about this alternative tool for code formatting that also does linting. This tool is much faster than black and can also do codestyle linting to enforce some best practices for python.

Ruff is implemented by Astral, which is a company aiming to create a "cargo for python" type experience with python tools that are implemented in rust making them both fast and reliable. I'm interested in some other stuff they are doing (e.g. uv for dependency management), but this seemed like a lower stakes way to test the waters with their stuff.

Solution

Main changes are in:

  • Dev dependency changes: add ruff, remove black
  • Remove black configs in pyproject.toml.
  • Add ruff configs to pyproject.toml. Mostly stuck with defaults, although I disabled a few of the more annoying lint rules for now on a per-file basis.
  • Adjust CI to run ruff checks instead of black.
  • Update CONTRIBUTING

The rest of this large diff is due to formatting and lint fixes for various code style things.

These checks can be run manually with poetry run ruff check --fix and poetry run ruff format, but otherwise they should automatically be triggered by pre-commit hooks. I documented this in CONTRIBUTING.

Type of Change

  • Infrastructure change (CI configs, etc)

Test Plan

Tests should still be green. No functional impact expected.

@jhamon jhamon marked this pull request as ready for review September 25, 2024 20:26
poetry run ruff format # formatting
```

If you want to adjust the behavior of ruff, configurations are in `pyproject.toml`.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1000% nit, but you probs want to put ruff in backticks, or else it's sorta confusing to read at first glance

Copy link

@aulorbe aulorbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

Copy link
Contributor

@rohanshah18 rohanshah18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a widely used library with frequent updates. LGTM!

@jhamon jhamon merged commit 587a5d5 into main Sep 25, 2024
84 checks passed
@jhamon jhamon deleted the jhamon/add-ruff-linter branch September 25, 2024 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants