Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace bandit, isort, pylint, pyupgrade, and flake8 plus plugins with ruff #2779

Merged
merged 1 commit into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/codespell-private.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Install dependencies
run: |
python --version # just to check
pip install -U pip wheel # upgrade to latest pip find 3.5 wheels; wheel to avoid errors
pip install --upgrade pip wheel # upgrade to latest pip find 3.5 wheels; wheel to avoid errors
pip install --upgrade "setuptools!=47.2.0" docutils setuptools_scm[toml] twine
pip install aspell-python-py3
pip install -e ".[dev]" # install the codespell dev packages
Expand All @@ -68,13 +68,13 @@ jobs:
with:
persist-credentials: false
- name: Install general dependencies
run: pip install -U pip wheel # upgrade to latest pip find 3.5 wheels; wheel to avoid errors
run: pip install --upgrade pip wheel # upgrade to latest pip find 3.5 wheels; wheel to avoid errors
- name: Install codespell dependencies
run: pip install -e ".[dev]"
- uses: codespell-project/sort-problem-matcher@v1
- run: make check-dictionaries

flake8-annotation:
ruff-annotation:
runs-on: ubuntu-latest
steps:
- name: Setup python
Expand All @@ -86,5 +86,5 @@ jobs:
persist-credentials: false
- name: Install codespell dependencies
run: pip install -e ".[dev]"
- name: Flake8 with annotations
uses: TrueBrain/actions-flake8@v2
- name: Ruff with annotations
run: ruff --select=ANN --ignore=ANN101,ANN401 .
16 changes: 0 additions & 16 deletions .github/workflows/isort.yml

This file was deleted.

15 changes: 15 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: ruff
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: pip install --user ruff
- run: ruff --format=github .
Comment on lines +1 to +15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this at all given that it's run in .github/workflows/codespell-private.yml already?

Copy link
Contributor Author

@cclauss cclauss Mar 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not really understand the purpose / differentiation of "private" but it is only testing --select=ANN which is a much narrower set of rules than this Ruff action.

I disabled ANN101 in one and ANN401 in the other so we could see that both do their thing.

43 changes: 10 additions & 33 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,12 @@ repos:
rev: v1.0.1
hooks:
- id: rst-linter
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py37-plus]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: no-commit-to-branch
args: [--branch, main]
- id: check-toml
- id: check-yaml
args: [--unsafe]
- id: debug-statements
Expand All @@ -59,48 +55,29 @@ repos:
- --no-warnings
- -d
- '{extends: relaxed, rules: {line-length: {max: 90}}}'
- repo: https://github.com/psf/black
rev: 23.1.0
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.254
hooks:
- id: black
- repo: https://github.com/Lucas-C/pre-commit-hooks-bandit
rev: v1.0.6
hooks:
- id: python-bandit-vulnerability-check
- id: ruff
- repo: https://github.com/PyCQA/autoflake
rev: v2.0.1
hooks:
- id: autoflake
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-pyproject>=1.2.2
- flake8-bugbear>=22.7.1
- flake8-comprehensions>=3.10.0
- flake8-2020>=1.7.0
- mccabe>=0.7.0
- pycodestyle>=2.9.1
- pyflakes>=2.5.0
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: isort
- id: black
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
hooks:
- id: codespell
args: [--toml, pyproject-codespell.precommit-toml]
additional_dependencies:
- tomli
- repo: https://github.com/pre-commit/mirrors-pylint
rev: v3.0.0a5
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.12.1
hooks:
- id: pylint
additional_dependencies:
- chardet
- pytest
- id: validate-pyproject
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
hooks:
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ SORT_ARGS := -f -b

DICTIONARIES := codespell_lib/data/dictionary*.txt

PHONY := all check check-dictionaries sort-dictionaries trim-dictionaries check-dist flake8 pytest pypi clean
PHONY := all check check-dictionaries sort-dictionaries trim-dictionaries check-dist pytest pypi ruff clean

all: check-dictionaries codespell.1

check: check-dictionaries check-dist flake8 pytest
check: check-dictionaries check-dist pytest ruff

codespell.1: codespell.1.include Makefile
PYTHONPATH=. help2man codespell --include codespell.1.include --no-info --output codespell.1
Expand Down Expand Up @@ -46,8 +46,8 @@ check-dist:
twine check --strict $(TMP)/*
rm -rf $(TMP)

flake8:
flake8
ruff:
ruff .

pytest:
@if command -v pytest > /dev/null; then \
Expand Down
100 changes: 46 additions & 54 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ dynamic = ["version"]
dev = [
"build",
"chardet",
"flake8",
"flake8-pyproject",
"pytest",
"pytest-cov",
"pytest-dependency",
"Pygments",
"ruff",
"tomli"
]
hard-encoding-detection = [
Expand All @@ -64,16 +63,16 @@ homepage = "https://github.com/codespell-project/codespell"
repository = "https://github.com/codespell-project/codespell"

[build-system]
requires = ["setuptools>=64", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"
requires = ["setuptools>=64", "setuptools_scm[toml]>=6.2"]

[tool.setuptools_scm]
write_to = "codespell_lib/_version.py"

[tool.setuptools.packages.find]
exclude = [
"dist",
"snap",
"dist"
]

[tool.setuptools.package-data]
Expand All @@ -88,67 +87,60 @@ in-place = true
recursive = true
expand-star-imports = true

[tool.bandit]
skip = "B101,B404,B603"
recursive = true

# TODO: reintegrate codespell configuration after updating test cases
#[tool.codespell]
#builtin = ["clear","rare","informal","usage","code","names"]
#ignore-words-list = ["uint"]
#skip=[ "./.*","codespell_lib/data/*","codespell_lib/tests/*"]

[tool.flake8]
max-line-length = "88"
extend-ignore = "E203"

[tool.isort]
profile = "black"

[tool.mypy]
pretty = true
show_error_codes = true
strict = true

[tool.pylint]
reports=false
py-version="3.7"
disable = [
"broad-except",
"consider-using-f-string",
"consider-using-dict-items",
"consider-using-with",
"fixme",
"import-error",
"import-outside-toplevel",
"invalid-name",
"line-too-long",
"missing-class-docstring",
"missing-module-docstring",
"missing-function-docstring",
"no-else-raise",
"no-else-return",
"raise-missing-from",
"redefined-outer-name",
"subprocess-run-check",
"too-many-arguments",
"too-many-lines",
"too-many-locals",
"too-many-branches",
"too-many-statements",
"too-many-return-statements",
"too-few-public-methods",
"unneeded-not",
"unspecified-encoding",
"unused-argument",
"unused-variable",
"use-maxsplit-arg"
]
[tool.pytest.ini_options]
addopts = "--cov=codespell_lib -rs --cov-report= --tb=short --junit-xml=junit-results.xml"

[tool.ruff]
extend-ignore = [
"A003",
"ANN101",
"ANN401",
"B904",
"N802",
"N812",
"PLW2901",
"S101",
"UP031",
]
line-length = 88
select = [
"A",
"ANN",
"B",
"C4",
"C9",
"E",
"F",
"I",
"N",
"PLC",
"PLE",
"PLR",
"PLW",
"S",
"U",
"W",
"YTT",
]
target-version = "py37"

[tool.pylint.FORMAT]
good-names=["F","r","i","n"]
# include-naming-hint=yes
[tool.ruff.mccabe]
max-complexity = 45

[tool.pytest.ini_options]
addopts = "--cov=codespell_lib -rs --cov-report= --tb=short --junit-xml=junit-results.xml"
[tool.ruff.pylint]
allow-magic-value-types = ["bytes", "int", "str",]
max-args = 12
max-branches = 48
max-returns = 10
max-statements = 111