From de91830af79964cc9a443a6eb95ee7a20cc77959 Mon Sep 17 00:00:00 2001 From: Christian Beiwinkel Date: Tue, 4 Jun 2024 18:33:03 +0200 Subject: [PATCH] that's it, no more flake8 --- .pre-commit-config.yaml | 21 ++++---- CONTRIBUTING.md | 18 ++++--- pyproject.toml | 61 ++++++++++++++++++++++ routing_packager_app/api_v1/models.py | 1 - routing_packager_app/api_v1/routes/jobs.py | 2 +- setup.cfg | 6 --- tests/conftest.py | 4 +- tests/users/test_users.py | 1 - 8 files changed, 87 insertions(+), 27 deletions(-) delete mode 100644 setup.cfg diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1f83e83..50ea39d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,12 @@ repos: -- repo: https://github.com/psf/black - rev: 22.3.0 - hooks: - - id: black - language_version: python3 - args: [routing_packager_app, tests] -- repo: https://github.com/pycqa/flake8 - rev: 4.0.1 # pick a git hash / tag to point to - hooks: - - id: flake8 + - repo: https://github.com/ambv/black + rev: 23.9.1 + hooks: + - id: black + language_version: python3 + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.0.289 + hooks: + - id: ruff + args: [--fix] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6e233e9..a3c22b1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,10 +5,12 @@ We :heart: patches, fixes & feature PRs and want to make sure everything goes smoothly for you before and while while submitting a PR. For development we use: + - [`poetry`](https://github.com/python-poetry/poetry/) as package manager - `pytest` for testing -- Google's [`yapf`](https://github.com/google/yapf) to make sure the formatting is consistent. -- [`pre-commit`](https://pre-commit.com) hook for yapf +- [`black`](https://github.com/psf/black) to make sure the formatting is consistent. +- [`ruff`](https://github.com/astral-sh/ruff) for linting +- [`pre-commit`](https://pre-commit.com) hook for formatting and linting When contributing, ideally you: @@ -23,11 +25,13 @@ When contributing, ideally you: 1. Create and activate a new virtual environment 2. Install development dependencies: + ```bash poetry install ``` - -3. Please add a pre-commit hook for `yapf`, so your code gets auto-formatted before committing it: + +3. Please add a pre-commit hook, so your code gets auto-formatted and linted before committing it: + ```bash pre-commit install ``` @@ -39,13 +43,13 @@ You'll need a few things to run the tests: - PostreSQL installation with a DB named `gis_test` (or define another db name using `POSTGRES_DB_TEST`) **and PostGIS enabled** - Redis database, best done with `docker run --name redis -p 6379:6379 -d redis:6.0`, then you can use the project's defaults, i.e. `REDIS_URL=redis://localhost:6379/0` - some fake SMTP service to handle email tests, our recommendations: - - [fake-smtp-server](https://www.npmjs.com/package/fake-smtp-server): NodeJS app with a frontend on `http://localhost:1080` and SMTP port 1025 - - pure Python one-liner in a separate terminal window: `sudo python -m smtpd -n -c DebuggingServer localhost:1025` + - [fake-smtp-server](https://www.npmjs.com/package/fake-smtp-server): NodeJS app with a frontend on `http://localhost:1080` and SMTP port 1025 + - pure Python one-liner in a separate terminal window: `sudo python -m smtpd -n -c DebuggingServer localhost:1025` We use `pytest` in this project with `coverage`: ```bash pytest --cov=routing_packager_app -``` +``` A `coverage` bot will report the coverage in every PR and we might ask you to increase coverage on new code. diff --git a/pyproject.toml b/pyproject.toml index 8d7abfb..ea22bbd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,3 +54,64 @@ exclude = ''' | build )/ ''' + +[tool.ruff] +# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default. +select = ["E", "F"] +ignore = [] + +# Allow autofix for all enabled rules (when `--fix`) is provided. +fixable = [ + "A", + "B", + "C", + "D", + "E", + "F", + "G", + "I", + "N", + "Q", + "S", + "T", + "W", + "ANN", + "ARG", + "BLE", + "COM", + "DJ", + "DTZ", + "EM", + "ERA", + "EXE", + "FBT", + "ICN", + "INP", + "ISC", + "NPY", + "PD", + "PGH", + "PIE", + "PL", + "PT", + "PTH", + "PYI", + "RET", + "RSE", + "RUF", + "SIM", + "SLF", + "TCH", + "TID", + "TRY", + "UP", + "YTT", +] +unfixable = [] + +# Exclude a variety of commonly ignored directories. +exclude = [".venv", "__pycache__", ".git"] + +# Same as Black. +line-length = 105 +target-version = "py312" diff --git a/routing_packager_app/api_v1/models.py b/routing_packager_app/api_v1/models.py index a7463ef..9733fac 100644 --- a/routing_packager_app/api_v1/models.py +++ b/routing_packager_app/api_v1/models.py @@ -41,7 +41,6 @@ class JobCreate(JobBase): class Job(JobBase, table=True): - __tablename__ = "jobs" id: Optional[int] = Field(primary_key=True) diff --git a/routing_packager_app/api_v1/routes/jobs.py b/routing_packager_app/api_v1/routes/jobs.py index 6eee65f..b3baa1e 100644 --- a/routing_packager_app/api_v1/routes/jobs.py +++ b/routing_packager_app/api_v1/routes/jobs.py @@ -26,7 +26,7 @@ from ...auth.basic_auth import BasicAuth from ...utils.geom_utils import bbox_to_wkt from ...utils.file_utils import make_package_path -from ...constants import * +from ...constants import Providers, Statuses router = APIRouter() diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index f27303f..0000000 --- a/setup.cfg +++ /dev/null @@ -1,6 +0,0 @@ -[flake8] -# ignore some errors to play nicely with black -ignore = E203,E266,E501,W503,F403,E722,F405 -max-complexity = 15 -max-line-length = 105 -exclude = .venv,.git,__pycache__,docs,dist,ssl,cron,ciso_reports diff --git a/tests/conftest.py b/tests/conftest.py index 45484fb..6b18947 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,9 +12,11 @@ from routing_packager_app.worker import create_package from contextlib import asynccontextmanager + @asynccontextmanager async def lifespan(app: FastAPI): - pass + pass + @pytest.fixture(scope="session", autouse=True) def create_worker(): diff --git a/tests/users/test_users.py b/tests/users/test_users.py index 4a56a05..a05b7f4 100644 --- a/tests/users/test_users.py +++ b/tests/users/test_users.py @@ -81,7 +81,6 @@ def test_new_user_unauthorized(get_client, basic_auth_header): def test_new_user_forbidden(get_client): - response = create_new_user( get_client, auth_header={},