Skip to content

Commit

Permalink
Replace Flake8 with Ruff (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored Dec 9, 2023
2 parents 7ba3c29 + 2bb027c commit 025cbfb
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 37 deletions.
5 changes: 1 addition & 4 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma:
pragma: no cover

exclude_also =
# Don't complain if non-runnable code isn't run:
if __name__ == .__main__.:
def main
Expand Down
2 changes: 0 additions & 2 deletions .flake8

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- uses: pre-commit/[email protected]
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ jobs:
run: |
tox -e py
- name: Test CLI
run: |
tox -e cli
- name: Cog
if: matrix.python-version == '3.12' && matrix.os == 'ubuntu-latest'
run: |
Expand Down
34 changes: 8 additions & 26 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.7
hooks:
- id: pyupgrade
args: [--py38-plus]
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.10.1
rev: 23.11.0
hooks:
- id: black

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
args: [--add-import=from __future__ import annotations]

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
[flake8-2020, flake8-errmsg, flake8-implicit-str-concat, flake8-logging]

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand All @@ -41,7 +23,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.1
rev: v1.7.1
hooks:
- id: mypy
args: [--strict, --pretty, --show-error-codes]
Expand All @@ -56,7 +38,7 @@ repos:
]

- repo: https://github.com/tox-dev/pyproject-fmt
rev: 1.4.1
rev: 1.5.3
hooks:
- id: pyproject-fmt
additional_dependencies: [tox]
Expand All @@ -72,7 +54,7 @@ repos:
- id: tox-ini-fmt

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
rev: v4.0.0-alpha.3-1
hooks:
- id: prettier
args: [--prose-wrap=always, --print-width=88]
Expand Down
27 changes: 25 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,31 @@ version.source = "vcs"
[tool.hatch.version.raw-options]
local_scheme = "no-local-version"

[tool.isort]
profile = "black"
[tool.ruff]
select = [
"C4", # flake8-comprehensions
"E", # pycodestyle errors
"EM", # flake8-errmsg
"F", # pyflakes errors
"I", # isort
"ISC", # flake8-implicit-str-concat
"PGH", # pygrep-hooks
"RUF100", # unused noqa (yesqa)
"UP", # pyupgrade
"W", # pycodestyle warnings
"YTT", # flake8-2020
# "LOG", # TODO: enable flake8-logging when it's not in preview anymore
]
extend-ignore = [
"E203", # Whitespace before ':'
"E221", # Multiple spaces before operator
"E226", # Missing whitespace around arithmetic operator
"E241", # Multiple spaces after ','
]

[tool.ruff.isort]
known-first-party = ["pepotron"]
required-imports = ["from __future__ import annotations"]

[tool.pytest.ini_options]
addopts = "--color=yes"
4 changes: 2 additions & 2 deletions src/pepotron/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _next_available_pep() -> int:
from itertools import pairwise
except ImportError:
# Python 3.9 and below
def pairwise(iterable): # type: ignore
def pairwise(iterable): # type: ignore[no-redef,no-untyped-def]
from itertools import tee

a, b = tee(iterable)
Expand All @@ -118,7 +118,7 @@ def pairwise(iterable): # type: ignore


def _get_github_prs() -> list[Any]:
from ghapi.all import GhApi # type: ignore
from ghapi.all import GhApi # type: ignore[import-not-found]

api = GhApi(owner="python", repo="peps", authenticate=False)
return api.pulls.list(per_page=100) # type: ignore[no-any-return]
Expand Down
8 changes: 8 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
requires =
tox>=4.2
env_list =
cli
cog
lint
py{py3, 313, 312, 311, 310, 39, 38}
Expand All @@ -17,8 +18,15 @@ commands =
--cov-report term \
--cov-report xml \
{posargs}

[testenv:cli]
commands =
pep --version
pep --help
pep --dry-run 8
pep --dry-run 3.13
pep --dry-run dead batteries
pep next

[testenv:cog]
deps =
Expand Down

0 comments on commit 025cbfb

Please sign in to comment.