From 6dbbd16bc6e7478f98046ca16ae5c82b58b81ddb Mon Sep 17 00:00:00 2001 From: TeKrop Date: Thu, 26 Oct 2023 16:57:39 +0200 Subject: [PATCH] replaced isort and black by ruff format --- .pre-commit-config.yaml | 21 ++++---------- app/commands/update_test_fixtures.py | 2 +- pyproject.toml | 42 +++++++++++++++++----------- tests/parsers/test_helpers.py | 2 +- 4 files changed, 33 insertions(+), 34 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ef033f7..d441a79 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,25 +1,16 @@ default_language_version: python: python3.11 repos: - - repo: https://github.com/pycqa/isort - rev: 5.12.0 - hooks: - - id: isort - name: (isort) Sorting python imports - args: ["--profile", "black", "--filter-files"] - - repo: https://github.com/psf/black - rev: 23.7.0 - hooks: - - id: black - name: (black) Formatting code - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.284 + rev: v0.1.3 hooks: - id: ruff - name: (ruff) Checking code quality - args: [ --fix, --exit-non-zero-on-fix ] + name: (ruff) Linting and fixing code + args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format + name: (ruff) Formatting code - repo: https://github.com/sourcery-ai/sourcery - rev: v1.7.0 + rev: v1.11.0 hooks: - id: sourcery name: (sourcery) Checking code quality diff --git a/app/commands/update_test_fixtures.py b/app/commands/update_test_fixtures.py index 186d68a..8f713c1 100644 --- a/app/commands/update_test_fixtures.py +++ b/app/commands/update_test_fixtures.py @@ -119,7 +119,7 @@ async def main(): response.status_code, response.elapsed.total_seconds(), ) - if response.status_code in (status.HTTP_200_OK, status.HTTP_404_NOT_FOUND): + if response.status_code in {status.HTTP_200_OK, status.HTTP_404_NOT_FOUND}: save_fixture_file(f"{test_data_path}{filepath}", response.text) else: logger.error("Error while getting the page : {}", response.text) diff --git a/pyproject.toml b/pyproject.toml index 9a2b0fa..22e8efe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ documentation = "https://overfast-api.tekrop.fr/" [tool.poetry.dependencies] python = "^3.11" beautifulsoup4 = "^4.12.2" -fastapi = "^0.103.2" +fastapi = "^0.104.0" httpx = {extras = ["http2"], version = "^0.25.0"} loguru = "^0.7.2" lxml = "^4.9.3" @@ -22,37 +22,30 @@ pydantic = "^2.4.2" pydantic-settings = "^2.0.3" [tool.poetry.group.dev.dependencies] -black = "^23.9.1" -fakeredis = "^2.19.0" +fakeredis = "^2.20.0" ipdb = "^0.13.13" -isort = "^5.12.0" -pytest = "^7.4.2" +pytest = "^7.4.3" pytest-asyncio = "^0.21.1" pytest-clarity = "^1.0.1" pytest-cov = "^4.1.0" pytest-randomly = "^3.15.0" pytest-xdist = "^3.3.1" -refurb = "^1.21.0" -ruff = "^0.0.292" -pre-commit = "^3.4.0" -sourcery = "^1.10.1" +refurb = "^1.22.1" +ruff = "^0.1.3" +pre-commit = "^3.5.0" +sourcery = "^1.11.0" [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" -[tool.isort] -profile = "black" - [tool.ruff] -# Same configuration as black default -line-length = 88 - select = [ "E", # pycodestyle errors "W", # pycodestyle warnings "F", # pyflakes "C90", # mccabe complexity checker + "I001", # isort "N", # pep8-naming "UP", # pyupgrade "ASYNC", # flake8-async @@ -60,7 +53,6 @@ select = [ "BLE", # flake8-blind-except "B", # flake8-bugbear "COM", # flake8-commas - "CPY", # flake8-copyright "C4", # flake8-comprehensions "DTZ", # flake8-datetimez "T10", # flake8-debugger @@ -75,6 +67,7 @@ select = [ "INP", # flake8-no-pep420 "PIE", # flake8-pie "T20", # flake8-print + "PYI", # flake8-pyi "PT", # flake8-pytest-style "Q", # flake8-quotes "RSE", # flake8-raise @@ -96,13 +89,24 @@ select = [ "RUF", # ruff-specific rules ] ignore = [ - "E501", # line too long, handled by black + # General rules to ignore "B008", # do not perform function calls in argument defaults "S101", # using "assert" is not a security issue "S311", # there is no cryptographic usage of random here "RET505", # allow using else after return statement "PLE1205", # error checking doesn't support {} format "PLR0913", # allow 6/7 arguments for some functions + + # Rules already handled by ruff formatter + "E501", # line too long + "COM812", # missing trailing comma + "COM819", # prohibited trailing comma + "ISC001", # single line implicit string concatenation + "Q000", # bad quotes in inline string + "Q001", # bad quotes in multiline string + "Q002", # bad quotes in docstring + "Q003", # avoidable escape quote + "W191" # tab indentation detected instead of spaces ] # Check app code and tests @@ -110,3 +114,7 @@ src = ["app", "tests"] # Assume Python 3.11 target-version = "py311" + +[tool.ruff.isort] +# Consider app as first-party for imports in tests +known-first-party = ["app"] diff --git a/tests/parsers/test_helpers.py b/tests/parsers/test_helpers.py index 23260dc..ce2b6f1 100644 --- a/tests/parsers/test_helpers.py +++ b/tests/parsers/test_helpers.py @@ -38,7 +38,7 @@ ("string", "string"), ], ) -def test_get_computed_stat_value(input_str: str, result: int | float | str): +def test_get_computed_stat_value(input_str: str, result: float | str): assert helpers.get_computed_stat_value(input_str) == result