Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace isort and black with ruff #17620

Merged
merged 4 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions .github/workflows/fix_lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,9 @@ jobs:
with:
install-project: "false"

- name: Import order (isort)
- name: Run ruff
continue-on-error: true
run: poetry run isort .

- name: Code style (black)
continue-on-error: true
run: poetry run black .

- name: Semantic checks (ruff)
continue-on-error: true
run: poetry run ruff --fix .
run: poetry run ruff check --fix .

- run: cargo clippy --all-features --fix -- -D warnings
continue-on-error: true
Expand All @@ -49,4 +41,4 @@ jobs:

- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Attempt to fix linting"
commit_message: "Attempt to fix linting"
11 changes: 2 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,8 @@ jobs:
with:
install-project: "false"

- name: Import order (isort)
run: poetry run isort --check --diff .

- name: Code style (black)
run: poetry run black --check --diff .

- name: Semantic checks (ruff)
# --quiet suppresses the update check.
run: poetry run ruff check --quiet .
- name: Check style
run: poetry run ruff check --output-format=github .

lint-mypy:
runs-on: ubuntu-latest
Expand Down
4 changes: 1 addition & 3 deletions docs/code_style.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ errors in code.

The necessary tools are:

- [black](https://black.readthedocs.io/en/stable/), a source code formatter;
- [isort](https://pycqa.github.io/isort/), which organises each file's imports;
- [ruff](https://github.com/charliermarsh/ruff), which can spot common errors; and
- [ruff](https://github.com/charliermarsh/ruff), which can spot common errors and enforce a consistent style; and
- [mypy](https://mypy.readthedocs.io/en/stable/), a type checker.

See [the contributing guide](development/contributing_guide.md#run-the-linters) for instructions
Expand Down
126 changes: 20 additions & 106 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 18 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,9 @@
name = "Internal Changes"
showcontent = true

[tool.black]
target-version = ['py38', 'py39', 'py310', 'py311']
# black ignores everything in .gitignore by default, see
# https://black.readthedocs.io/en/stable/usage_and_configuration/file_collection_and_discovery.html#gitignore
# Use `extend-exclude` if you want to exclude something in addition to this.

[tool.ruff]
line-length = 88
target-version = "py38"

[tool.ruff.lint]
# See https://beta.ruff.rs/docs/rules/#error-e
Expand All @@ -63,6 +58,8 @@ select = [
"W",
# pyflakes
"F",
# isort
"I001",
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Contributor

Choose a reason for hiding this comment

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

isort isn't enabled by default, this enables it.

# flake8-bugbear
"B0",
# flake8-comprehensions
Expand All @@ -79,17 +76,20 @@ select = [
"EXE",
]

[tool.isort]
line_length = 88
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "TWISTED", "FIRSTPARTY", "TESTS", "LOCALFOLDER"]
default_section = "THIRDPARTY"
known_first_party = ["synapse"]
known_tests = ["tests"]
known_twisted = ["twisted", "OpenSSL"]
multi_line_output = 3
include_trailing_comma = true
combine_as_imports = true
skip_gitignore = true
[tool.ruff.lint.isort]
combine-as-imports = true
section-order = ["future", "standard-library", "third-party", "twisted", "first-party", "testing", "local-folder"]
known-first-party = ["synapse"]

[tool.ruff.lint.isort.sections]
twisted = ["twisted", "OpenSSL"]
testing = ["tests"]

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"

[tool.maturin]
manifest-path = "rust/Cargo.toml"
Expand Down Expand Up @@ -320,9 +320,7 @@ all = [
# failing on new releases. Keeping lower bounds loose here means that dependabot
# can bump versions without having to update the content-hash in the lockfile.
# This helps prevents merge conflicts when running a batch of dependabot updates.
isort = ">=5.10.1"
black = ">=22.7.0"
ruff = "0.5.5"
ruff = "0.6.2"
# Type checking only works with the pydantic.v1 compat module from pydantic v2
pydantic = "^2"

Expand Down
9 changes: 2 additions & 7 deletions scripts-dev/lint.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env bash
#
# Runs linting scripts over the local Synapse checkout
# black - opinionated code formatter
# ruff - lints and finds mistakes
# mypy - typechecks python code
# cargo clippy - lints rust code

set -e

Expand Down Expand Up @@ -101,12 +102,6 @@ echo
# Print out the commands being run
set -x

# Ensure the sort order of imports.
isort "${files[@]}"

# Ensure Python code conforms to an opinionated style.
python3 -m black "${files[@]}"

# Ensure the sample configuration file conforms to style checks.
./scripts-dev/config-lint.sh

Expand Down