diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29a6aa07..36b63be7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,18 +32,11 @@ jobs: lint: runs-on: ubuntu-22.04 - timeout-minutes: 10 + timeout-minutes: 2 steps: - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: 3.9 - - name: Lint with flake8 - run: | - pip install flake8 - flake8 src scripts conftest.py + - uses: chartboost/ruff-action@v1 linux: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2ce85f8a..5b6d0d39 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,8 +3,7 @@ repos: rev: 23.1.0 hooks: - id: black -- repo: https://github.com/pycqa/flake8 - rev: 6.0.0 - hooks: - - id: flake8 - files: '(src|scripts|conftest.py)' +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.0.287 + hooks: + - id: ruff diff --git a/docs/conf.py b/docs/conf.py index 44d33d5a..4e5a6e17 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,7 +12,8 @@ # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -import sys, os +import sys +import os sys.path.insert(0, os.path.abspath("../src")) diff --git a/pyproject.toml b/pyproject.toml index eced3323..6912a82e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,3 +12,58 @@ write_to_template = "__version__ = version = {version!r}\n" [tool.black] line-length = 120 skip-magic-trailing-comma = true + +[tool.ruff] +line-length = 120 +target-version = "py39" + +# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default. +select = ["E", "F"] + +# for reference ... +# E402 module level import not at top +# E501 line too long +# F401 import unused +# F405 undefined or defined from star imports +# F811 redef of unused var + +# borg code style guidelines: +# Ignoring E203 due to https://github.com/PyCQA/pycodestyle/issues/373 +ignore = ["E203", "F405", "E402"] + +# 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 = [ + ".cache", + ".eggs", + ".git", + ".git-rewrite", + ".idea", + ".mypy_cache", + ".ruff_cache", + ".tox", + "build", + "dist", +] + +# Allow unused variables when underscore-prefixed. +dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" + +# Code style violation exceptions: +# please note that the values are adjusted so that they do not cause failures +# with existing code. if you want to change them, you should first fix all +# ruff failures that appear with your change. +[tool.ruff.per-file-ignores] +"setup_docs.py" = ["E501"] +"src/borg/archive.py" = ["E501"] +"src/borg/archiver/help_cmd.py" = ["E501"] +"src/borg/cache.py" = ["E501"] +"src/borg/helpers/__init__.py" = ["F401"] +"src/borg/platform/__init__.py" = ["F401"] +"src/borg/testsuite/archiver/disk_full.py" = ["F811"] +"src/borg/testsuite/archiver/return_codes.py" = ["F811"] +"src/borg/testsuite/benchmark.py" = ["F811"] +"src/borg/testsuite/platform.py" = ["F811"] diff --git a/setup.cfg b/setup.cfg index 90c52a95..afe4e95a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -74,39 +74,6 @@ python_files = testsuite/*.py markers = allow_cache_wipe -[flake8] -# for reference ... -# E402 module level import not at top -# E501 line too long -# F401 import unused -# F405 undefined or defined from star imports -# F811 redef of unused var -# #### Pick either W503, or W504 - latest recommendation from pep8 is to ignore W503 -# W503 line break before binary operator -# W504 line break after binary operator - -# borg code style guidelines: -# Ignoring E203 due to https://github.com/PyCQA/pycodestyle/issues/373 -ignore = W503, E203, F405, E402 - -# Code style violation exceptions: -# please note that the values are adjusted so that they do not cause failures -# with existing code. if you want to change them, you should first fix all -# flake8 failures that appear with your change. -per_file_ignores = - src/borg/archive.py:E501 - src/borg/archiver/help_cmd.py:E501 - src/borg/cache.py:E501 - src/borg/helpers/__init__.py:F401 - src/borg/platform/__init__.py:F401 - src/borg/testsuite/archiver/disk_full.py:F811 - src/borg/testsuite/archiver/return_codes.py:F811 - src/borg/testsuite/benchmark.py:F811 - src/borg/testsuite/platform.py:F811 - -max_line_length = 120 -exclude = build,dist,.git,.idea,.cache,.tox - [mypy] python_version = 3.9 strict_optional = False diff --git a/src/borg/item.pyi b/src/borg/item.pyi index 19192f52..8cb2df43 100644 --- a/src/borg/item.pyi +++ b/src/borg/item.pyi @@ -1,4 +1,4 @@ -from typing import FrozenSet, Set, NamedTuple, Tuple, Mapping, Dict, List, Iterator, Callable, Any, Optional +from typing import Set, NamedTuple, Tuple, Mapping, Dict, List, Iterator, Callable, Any, Optional from .helpers import StableDict @@ -96,7 +96,7 @@ class ArchiveItem(PropDict): def items(self, val: List) -> None: ... @property def item_ptrs(self) -> List: ... - @items.setter + @item_ptrs.setter def item_ptrs(self, val: List) -> None: ... class ChunkListEntry(NamedTuple): diff --git a/tox.ini b/tox.ini index a4a8b1d7..8dc396d5 100644 --- a/tox.ini +++ b/tox.ini @@ -28,13 +28,13 @@ passenv = * passenv = * # needed by tox4, so env vars are visible for building borg -[testenv:flake8] +[testenv:ruff] skip_sdist=true skip_install=true changedir = deps = - flake8 -commands = flake8 src scripts conftest.py + ruff +commands = ruff check . [testenv:mypy] changedir =