Skip to content

Commit

Permalink
Migrate to ruff tooling and config
Browse files Browse the repository at this point in the history
Signed-off-by: Shah, Karan <[email protected]>
  • Loading branch information
MasterSkepticista committed Nov 28, 2024
1 parent a26bdb2 commit 0f7dc74
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 56 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pip install -r linters-requirements.txt

## Code style

OpenFL uses [black](https://black.readthedocs.io/en/stable/), [isort](https://pycqa.github.io/isort/) and [precommit](https://pre-commit.com/) to format the code.
OpenFL uses [ruff](https://github.com/astral-sh/ruff) to lint/format code and [precommit](https://pre-commit.com/) checks.

Run the following command at the **root** directory of the repo to format your code.

Expand Down
4 changes: 1 addition & 3 deletions linters-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
black
flake8
isort
pre-commit
ruff
30 changes: 25 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
[tool.black]
[tool.ruff]
line-length = 100

[tool.isort]
profile = "black"
force_single_line = "False"
line_length = 100
[tool.ruff.lint]
select = [
"B", # Bandit security checks (e.g., detecting insecure function use).
"C", # Cyclomatic complexity, used to flag overly complex functions.
"E", # PEP8 errors (e.g., style issues).
"F", # Pyflakes errors, like unused imports or undefined names.
"W", # PEP8 warnings (e.g., deprecations).
"B9", # Bugbear, for additional warnings about potentially error-prone code.
"I", # isort
]
ignore = [
"E266", # too many leading '#' for block comments
"E741", # ambiguous variable name
"E731", # do not assign a `lambda` expression, use a `def`
"B904", # ignore exception distinguishing
"B006", # mutable data structures as default args
]

[tool.ruff.lint.per-file-ignores]
"**/__init__.py" = ["E501", "F401"] # lines too long; imported but unused

[tool.ruff.lint.isort]
force-single-line = false
known-first-party = ["openfl"]
39 changes: 0 additions & 39 deletions setup.cfg

This file was deleted.

6 changes: 2 additions & 4 deletions shell/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ base_dir=$(dirname $(dirname $0))
# Run the pre-commit checks
pre-commit run --all-files

isort --sp "${base_dir}/pyproject.toml" openfl
ruff check --config "${base_dir}/pyproject.toml" --fix openfl/

black --config "${base_dir}/pyproject.toml" openfl

flake8 --config "${base_dir}/setup.cfg" openfl
ruff format --config "${base_dir}/pyproject.toml" openfl/
6 changes: 2 additions & 4 deletions shell/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ base_dir=$(dirname $(dirname $0))
# Run the pre-commit checks
pre-commit run --all-files

isort --sp "${base_dir}/pyproject.toml" --check openfl
ruff check --config "${base_dir}/pyproject.toml" openfl/

black --config "${base_dir}/pyproject.toml" --check openfl

flake8 --config "${base_dir}/setup.cfg" --show-source openfl
ruff format --check --config "${base_dir}/pyproject.toml" openfl/

0 comments on commit 0f7dc74

Please sign in to comment.