Skip to content

Commit

Permalink
Swap out Flake8 for ruff in linting
Browse files Browse the repository at this point in the history
  • Loading branch information
chouinar committed Jun 20, 2024
1 parent e6093b3 commit 716ae2f
Show file tree
Hide file tree
Showing 8 changed files with 871 additions and 1,024 deletions.
11 changes: 4 additions & 7 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@ DECODE_LOG := 2>&1 | python3 -u src/logging/util/decodelog.py
SHELL = /bin/bash -o pipefail

# The APP_DIR variable is the path from the root of the repository to this Makefile.
# This variable is used to display errors from Flake8 and MyPy in the 'Files Changed'
# This variable is used to display errors from MyPy in the 'Files Changed'
# section of a pull request. If this is set to the incorrect value, you won't be able
# to see the errors on the correct files in that section
APP_DIR := app
ifdef CI
DOCKER_EXEC_ARGS := -T -e CI -e PYTEST_ADDOPTS="--color=yes"
FLAKE8_FORMAT := '::warning file=$(APP_DIR)/%(path)s,line=%(row)d,col=%(col)d::%(path)s:%(row)d:%(col)d: %(code)s %(text)s'
MYPY_FLAGS := --no-pretty
MYPY_POSTPROC := | perl -pe "s/^(.+):(\d+):(\d+): error: (.*)/::warning file=$(APP_DIR)\/\1,line=\2,col=\3::\4/"
else
FLAKE8_FORMAT := default
endif

# By default, all python/poetry commands will run inside of the docker container
Expand Down Expand Up @@ -199,10 +196,10 @@ format-check: ## Check file formatting

lint: lint-py ## Lint

lint-py: lint-flake lint-mypy
lint-py: lint-ruff lint-mypy

lint-flake:
$(PY_RUN_CMD) flake8 --format=$(FLAKE8_FORMAT) src tests
lint-ruff:
$(PY_RUN_CMD) ruff check src tests

lint-mypy:
$(PY_RUN_CMD) mypy --show-error-codes $(MYPY_FLAGS) src $(MYPY_POSTPROC)
Expand Down
1,829 changes: 841 additions & 988 deletions app/poetry.lock

Large diffs are not rendered by default.

25 changes: 22 additions & 3 deletions app/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ pydantic-settings = "^2.0.3"

[tool.poetry.group.dev.dependencies]
black = "^23.9.1"
flake8 = "^6.1.0"
flake8-bugbear = "^23.9.16"
flake8-alfred = "^1.1.1"
isort = "^5.12.0"
mypy = "^1.5.1"
moto = {extras = ["s3"], version = "^4.0.2"}
Expand All @@ -41,6 +38,7 @@ pytest-lazy-fixture = "^0.6.3"
types-pyyaml = "^6.0.12.11"
setuptools = "^68.2.2"
debugpy = "^1.8.1"
ruff = "^0.4.9"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand All @@ -61,6 +59,27 @@ force_grid_wrap = 0
use_parentheses = true
line_length = 100

[tool.ruff]
line-length = 100
# Some rules are considered preview-only, this allows them
# assuming we enabled them below
preview = true

[tool.ruff.lint]
# See: https://docs.astral.sh/ruff/rules/ for all possible rules
select = ["B", "C", "E", "F", "W", "B9"]
ignore = [
# too many leading '#' for block comment, we can format our comments however we want
"E266",
# Ignore line-too-long errors, assume the formatter handles that appropriately
"E501",
# Ignore rules regarding unecessary list / generator usage which complains about [e for e in MyEnum]
"C4",
# Ignore rule that flags functions with many branches - sometimes we just have a lot of
# business rules that make sense to aggregate in one place.
"C901"
]

[tool.mypy]
# https://mypy.readthedocs.io/en/stable/config_file.html
color_output = true
Expand Down
20 changes: 0 additions & 20 deletions app/setup.cfg

This file was deleted.

5 changes: 1 addition & 4 deletions app/src/adapters/db/flask_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,4 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:

return wrapper

# mypy says the type should be something slightly different
# Callable[[Arg(Callable[[Session, **P], T], 'f')], Callable[P, T]]
# but also mentions that "Arg" is deprecated, so not sure how to make it happy
return decorator # type: ignore
return decorator
2 changes: 2 additions & 0 deletions app/src/db/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from . import bulk_ops

__all__ = ["bulk_ops"]
1 change: 0 additions & 1 deletion app/src/logging/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
logger = logging.getLogger(__name__)

AUDIT = 32
logging.INFO
logging.addLevelName(AUDIT, "AUDIT")


Expand Down
2 changes: 1 addition & 1 deletion docs/app/formatting-and-linting.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ When we run migrations via alembic, we autorun the formatters on the generated f
Run `make lint` to run all of the linters. It's recommended you run the formatters first as they fix several linting issues automatically.

### Flake
[flake](https://flake8.pycqa.org/en/latest/) is used to validate the format of our Python code. Configuration options can be found in [setup.cfg](/app/setup.cfg).
[ruff](https://flake8.pycqa.org/en/latest/) is used to enforce a set of best practices for our Python code. Configuration options can be found in [pyproject.toml - tool.ruff](/app/pyproject.toml).

We use two flake extensions:
* [bugbear](https://pypi.org/project/flake8-bugbear/) for finding likely bugs and design problems.
Expand Down

0 comments on commit 716ae2f

Please sign in to comment.