Skip to content

Commit

Permalink
Add linter ruff
Browse files Browse the repository at this point in the history
Signed-off-by: Aisuko <[email protected]>
  • Loading branch information
Aisuko authored Jun 18, 2024
1 parent e35749f commit fa3aff2
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 9 deletions.
16 changes: 7 additions & 9 deletions .github/workflows/ci-backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ jobs:
- ubuntu-latest
python-version:
- "3.11"
defaults:
run:
working-directory: backend/
# No need to set to specific directory
# defaults:
# run:
# working-directory: backend/
runs-on: ${{ matrix.os }}

steps:
Expand All @@ -33,13 +34,10 @@ jobs:
cache: 'pip'
- name: Install Dependencies for Linting
run: |
pip install flake8
- name: Lint with Flake8
pip install ruff==0.4.9
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
make ruff
# test:
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,10 @@ gpu-logs:
.PHONY: gpu-remove
gpu-remove:
docker compose -f docker-compose.gpu.yaml down

############################################################################################################
# Linter

.PHONY: ruff
ruff:
@ruff check --output-format=github backend/src/ --config ruff.toml
53 changes: 53 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# https://docs.astral.sh/ruff/configuration/

# ignored directories
exclude = [
".devcontainer",
".github",
".git",
".vscode",
]


# Same as Black
line-length = 120
indent-width = 4

# Assume Python 3.11
target-version = "py311"

[lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F"]
ignore = []

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []


# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"


# Example of ignore files
# Ignore `E402` (import violations) in all `__init__.py` files, and in select subdirectories.
[lint.per-file-ignores]
"__init__.py" = ["E402"]
"**/{tests,docs,tools}/*" = ["E402"]


[format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

0 comments on commit fa3aff2

Please sign in to comment.