From 370667b2e3718eaf3faeb8971ba9621cf279a09d Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Wed, 1 Nov 2023 23:31:34 +0100 Subject: [PATCH 01/10] feat: add pre-commit configuration --- .pre-commit-config.yaml | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..f54ae1c --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,40 @@ +ci: + autofix_prs: false + autoupdate_schedule: monthly + +repos: +- repo: https://github.com/asottile/pyupgrade + rev: v3.14.0 + hooks: + - id: pyupgrade + args: [--py38-plus] +- repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort +- repo: https://github.com/psf/black + rev: 23.9.1 + hooks: + - id: black +- repo: https://github.com/PyCQA/flake8 + rev: 6.1.0 + hooks: + - id: flake8 +- repo: https://github.com/codespell-project/codespell + rev: v2.2.6 + hooks: + - id: codespell + additional_dependencies: + - tomli +- repo: https://github.com/mgedmin/check-manifest + rev: "0.49" + hooks: + - id: check-manifest +- repo: https://github.com/regebro/pyroma + rev: "4.2" + hooks: + - id: pyroma +- repo: https://github.com/mgedmin/check-python-versions + rev: "0.21.3" + hooks: + - id: check-python-versions From f7bb890b45c2c78413f83d54322090c90572007d Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Thu, 2 Nov 2023 09:46:24 +0100 Subject: [PATCH 02/10] cleanup: drop requirements files We are not using them anyway since we moved linting and testing to `tox` and `pre-commit`. Anyway, pinning, as good as it is, is by no means critical to this project, as we are not the ones deciding in which environment this `flake8` plugin gets installed. --- .pre-commit-config.yaml | 10 +++ requirements-lint.in | 18 ------ requirements-lint.txt | 133 ---------------------------------------- requirements.in | 4 -- requirements.txt | 50 --------------- 5 files changed, 10 insertions(+), 205 deletions(-) delete mode 100644 requirements-lint.in delete mode 100644 requirements-lint.txt delete mode 100644 requirements.in delete mode 100644 requirements.txt diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f54ae1c..67c1a80 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,6 +20,16 @@ repos: rev: 6.1.0 hooks: - id: flake8 + additional_dependencies: + - flake8-bugbear + - flake8-comprehensions + - flake8-debugger + - flake8-deprecated + - flake8-isort + - flake8-pep3101 + - flake8-print + - flake8-quotes + - repo: https://github.com/codespell-project/codespell rev: v2.2.6 hooks: diff --git a/requirements-lint.in b/requirements-lint.in deleted file mode 100644 index f1303d1..0000000 --- a/requirements-lint.in +++ /dev/null @@ -1,18 +0,0 @@ -bandit -black -codespell -coveralls -flake8-blind-except -flake8-bugbear -flake8-comprehensions -flake8-debugger -flake8-deprecated -flake8-isort -flake8-pep3101 -flake8-print -flake8-quotes -flake8-todo -isort -pytest -pytest-cov -pyupgrade diff --git a/requirements-lint.txt b/requirements-lint.txt deleted file mode 100644 index a6e1cc4..0000000 --- a/requirements-lint.txt +++ /dev/null @@ -1,133 +0,0 @@ -# -# This file is autogenerated by pip-compile with Python 3.8 -# by the following command: -# -# pip-compile requirements-lint.in -# -attrs==23.1.0 - # via flake8-bugbear -bandit==1.7.5 - # via -r requirements-lint.in -black==23.10.1 - # via -r requirements-lint.in -certifi==2023.7.22 - # via requests -charset-normalizer==3.3.2 - # via requests -click==8.1.7 - # via black -codespell==2.2.6 - # via -r requirements-lint.in -coverage[toml]==6.5.0 - # via - # coveralls - # pytest-cov -coveralls==3.3.1 - # via -r requirements-lint.in -docopt==0.6.2 - # via coveralls -exceptiongroup==1.1.3 - # via pytest -flake8==6.1.0 - # via - # flake8-bugbear - # flake8-comprehensions - # flake8-debugger - # flake8-deprecated - # flake8-isort - # flake8-pep3101 - # flake8-print - # flake8-quotes -flake8-blind-except==0.2.1 - # via -r requirements-lint.in -flake8-bugbear==23.9.16 - # via -r requirements-lint.in -flake8-comprehensions==3.14.0 - # via -r requirements-lint.in -flake8-debugger==4.1.2 - # via -r requirements-lint.in -flake8-deprecated==2.1.0 - # via -r requirements-lint.in -flake8-isort==6.1.0 - # via -r requirements-lint.in -flake8-pep3101==2.0.0 - # via -r requirements-lint.in -flake8-print==5.0.0 - # via -r requirements-lint.in -flake8-quotes==3.3.2 - # via -r requirements-lint.in -flake8-todo==0.7 - # via -r requirements-lint.in -gitdb==4.0.11 - # via gitpython -gitpython==3.1.40 - # via bandit -idna==3.4 - # via requests -iniconfig==2.0.0 - # via pytest -isort==5.12.0 - # via - # -r requirements-lint.in - # flake8-isort -markdown-it-py==3.0.0 - # via rich -mccabe==0.7.0 - # via flake8 -mdurl==0.1.2 - # via markdown-it-py -mypy-extensions==1.0.0 - # via black -packaging==23.2 - # via - # black - # pytest -pathspec==0.11.2 - # via black -pbr==5.11.1 - # via stevedore -platformdirs==3.11.0 - # via black -pluggy==1.3.0 - # via pytest -pycodestyle==2.11.1 - # via - # flake8 - # flake8-debugger - # flake8-print - # flake8-todo -pyflakes==3.1.0 - # via flake8 -pygments==2.16.1 - # via rich -pytest==7.4.3 - # via - # -r requirements-lint.in - # pytest-cov -pytest-cov==4.1.0 - # via -r requirements-lint.in -pyupgrade==3.15.0 - # via -r requirements-lint.in -pyyaml==6.0.1 - # via bandit -requests==2.31.0 - # via coveralls -rich==13.6.0 - # via bandit -smmap==5.0.1 - # via gitdb -stevedore==5.1.0 - # via bandit -tokenize-rt==5.2.0 - # via pyupgrade -tomli==2.0.1 - # via - # black - # coverage - # pytest -typing-extensions==4.8.0 - # via - # black - # rich -urllib3==2.0.7 - # via requests diff --git a/requirements.in b/requirements.in deleted file mode 100644 index 55594fb..0000000 --- a/requirements.in +++ /dev/null @@ -1,4 +0,0 @@ -coveralls -flake8 -pytest -pytest-cov diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 8427cff..0000000 --- a/requirements.txt +++ /dev/null @@ -1,50 +0,0 @@ -# -# This file is autogenerated by pip-compile with Python 3.8 -# by the following command: -# -# pip-compile requirements.in -# -certifi==2023.7.22 - # via requests -charset-normalizer==3.3.2 - # via requests -coverage[toml]==6.5.0 - # via - # coveralls - # pytest-cov -coveralls==3.3.1 - # via -r requirements.in -docopt==0.6.2 - # via coveralls -exceptiongroup==1.1.3 - # via pytest -flake8==6.1.0 - # via -r requirements.in -idna==3.4 - # via requests -iniconfig==2.0.0 - # via pytest -mccabe==0.7.0 - # via flake8 -packaging==23.2 - # via pytest -pluggy==1.3.0 - # via pytest -pycodestyle==2.11.1 - # via flake8 -pyflakes==3.1.0 - # via flake8 -pytest==7.4.3 - # via - # -r requirements.in - # pytest-cov -pytest-cov==4.1.0 - # via -r requirements.in -requests==2.31.0 - # via coveralls -tomli==2.0.1 - # via - # coverage - # pytest -urllib3==2.0.7 - # via requests From c4b89aa866d0967b7b663a393535b35bc699ea92 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Wed, 1 Nov 2023 23:31:44 +0100 Subject: [PATCH 03/10] feat: add tox configuration --- tox.ini | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tox.ini diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..bfb4fc1 --- /dev/null +++ b/tox.ini @@ -0,0 +1,51 @@ +[tox] +min_version = 4.4.0 +envlist = + format + lint + coverage + py38 + py39 + py310 + py311 + py312 + pypy3 + +[testenv:test] +description = run the distribution tests +use_develop = true +skip_install = false +constrain_package_deps = true +commands = + pytest run_tests.py +extras = + test + +[testenv:format] +description = automatically reformat code +skip_install = true +deps = + pre-commit +commands = + pre-commit run -a pyupgrade + pre-commit run -a isort + pre-commit run -a black + +[testenv:lint] +description = run linters that will help improve the code style +skip_install = true +deps = + pre-commit +commands = + pre-commit run -a + +[testenv:coverage] +description = get a test coverage report +use_develop = true +skip_install = false +deps = + coverage +commands = + pytest run_tests.py --cov --cov-report term-missing +extras = + test From 821cd313230600bdbe79d35641f6332c525d32c6 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Thu, 2 Nov 2023 09:49:34 +0100 Subject: [PATCH 04/10] feat(gha): use tox environments --- .github/workflows/testing.yml | 67 ++++++++++++++++------------------- 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index fef5e62..79f07ff 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -9,14 +9,10 @@ env: jobs: test: name: Testing on - runs-on: ${{ matrix.os }} + runs-on: "ubuntu-latest" strategy: matrix: python-version: ["3.12", "3.11", "3.10", 3.9, 3.8, pypy-3.9] - os: ["ubuntu-22.04"] - include: - - os: "ubuntu-latest" - python-version: 3.11 steps: - uses: actions/checkout@v4 - name: Set up Python @@ -27,39 +23,36 @@ jobs: uses: actions/cache@v3 with: path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }} + key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('tox.ini') }} restore-keys: | ${{ runner.os }}-pip-${{ matrix.python-version }}- - - name: pip version - run: pip --version - name: Install dependencies - if: matrix.python-version == '3.9' - run: python -m pip install -r requirements-lint.txt - - name: Install dependencies - if: matrix.python-version != '3.9' - run: python -m pip install -r requirements.txt - # formatters - - name: Run pyupgrade - if: matrix.python-version == '3.9' - run: pyupgrade --py37-plus *.py - - name: Run isort - if: matrix.python-version == '3.9' - run: isort --check-only *.py - - name: Run black - if: matrix.python-version == '3.9' - run: black --check --skip-string-normalization *.py - # linters - - name: Lint with bandit - if: matrix.python-version == '3.9' - run: bandit --skip B101 *.py # B101 is assert statements - - name: Lint with codespell - if: matrix.python-version == '3.9' - run: codespell *.rst *.py - - name: Lint with flake8 - if: matrix.python-version == '3.9' - run: flake8 *.py --count --max-complexity=18 --max-line-length=88 --show-source --statistics - # tests and coverage + run: python -m pip install tox - name: Test - run: pytest run_tests.py --cov --cov-report term-missing - - name: Coverage - run: coveralls --service=github + run: tox -e test + + lint: + name: Lint code + runs-on: "ubuntu-latest" + strategy: + matrix: + python-version: [3.8] + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Cache packages + uses: actions/cache@v3 + with: + path: | + ~/.cache/pre-commit + ~/.cache/pip + key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('tox.ini') }} + restore-keys: | + ${{ runner.os }}-pip-${{ matrix.python-version }}- + - name: Install dependencies + run: python -m pip install tox + - name: Run linting + run: tox -e lint From 4f1a5fb4caa2e118136392b741d184fe7c06e681 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Wed, 1 Nov 2023 23:30:11 +0100 Subject: [PATCH 05/10] feat: configure tools - isort - black - flake8 - check-manifest --- .flake8 | 13 +++++++++++++ pyproject.toml | 13 +++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..e8429c6 --- /dev/null +++ b/.flake8 @@ -0,0 +1,13 @@ +[flake8] +doctests = 1 +ignore = + # black takes care of line length + E501, + # black takes care of where to break lines + W503, + # black takes care of spaces within slicing (list[:]) + E203, + # black takes care of spaces after commas + E231, + # as one has to use self.XX it should not be a problem + A003, diff --git a/pyproject.toml b/pyproject.toml index 4cce79c..bb8986f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,3 +44,16 @@ test = ["pytest"] [project.entry-points."flake8.extension"] A00 = "flake8_builtins:BuiltinsChecker" + +[tool.isort] +profile = "plone" + +[tool.black] +target-version = ["py38"] +skip-string-normalization = true + +[tool.check-manifest] +ignore = [ + ".vscode/*", + "venv/*", +] From 48b589a6a24a854f0ea582c14f4cc4a446b31696 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Wed, 1 Nov 2023 23:33:21 +0100 Subject: [PATCH 06/10] chore: pyupgrade --- flake8_builtins.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/flake8_builtins.py b/flake8_builtins.py index d178daf..40e55c0 100644 --- a/flake8_builtins.py +++ b/flake8_builtins.py @@ -1,15 +1,9 @@ import ast import builtins import inspect -import sys from flake8 import utils as stdin_utils -if sys.version_info >= (3, 8): - NamedExpr = ast.NamedExpr -else: # There was no walrus operator before python3.8 - NamedExpr = type('NamedExpr', (ast.AST,), {}) - class BuiltinsChecker: name = 'flake8_builtins' @@ -88,7 +82,7 @@ def run(self): value = None for statement in ast.walk(tree): - if isinstance(statement, (ast.Assign, ast.AnnAssign, NamedExpr)): + if isinstance(statement, (ast.Assign, ast.AnnAssign, ast.NamedExpr)): value = self.check_assignment(statement) elif isinstance(statement, function_nodes): From be05b65673792229a66e25af034ec2fcd498e71a Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Wed, 1 Nov 2023 23:33:41 +0100 Subject: [PATCH 07/10] chore: isort --- flake8_builtins.py | 4 ++-- run_tests.py | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/flake8_builtins.py b/flake8_builtins.py index 40e55c0..1473b9f 100644 --- a/flake8_builtins.py +++ b/flake8_builtins.py @@ -1,9 +1,9 @@ +from flake8 import utils as stdin_utils + import ast import builtins import inspect -from flake8 import utils as stdin_utils - class BuiltinsChecker: name = 'flake8_builtins' diff --git a/run_tests.py b/run_tests.py index d665529..d886e59 100644 --- a/run_tests.py +++ b/run_tests.py @@ -1,11 +1,10 @@ -import ast -import sys -import textwrap +from flake8_builtins import BuiltinsChecker from unittest import mock +import ast import pytest - -from flake8_builtins import BuiltinsChecker +import sys +import textwrap class FakeOptions: From 16d0bf780b7987f54fb470b5e184e4636927edad Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Wed, 1 Nov 2023 23:36:59 +0100 Subject: [PATCH 08/10] chore: black --- run_tests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/run_tests.py b/run_tests.py index d886e59..522edec 100644 --- a/run_tests.py +++ b/run_tests.py @@ -146,6 +146,7 @@ def bla(dict=3): b = 4""" check_code(source, 'A002') + def test_kwonly_argument_message(): source = """ def bla(*, list): From 68a4e754bdc6bef6a5985d61e19c891c067934d1 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Wed, 1 Nov 2023 23:42:11 +0100 Subject: [PATCH 09/10] chore: add missing trove classifier --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index bb8986f..cb05cef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,6 +27,7 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development", From a2c9aefc57105003f516850ec03f7ce34dd7423a Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Thu, 2 Nov 2023 09:18:59 +0100 Subject: [PATCH 10/10] Update CHANGES --- CHANGES.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 93f4b1f..8827bbc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,8 +6,8 @@ Changelog 2.2.0a1 (unreleased) -------------------- -- Nothing changed yet. - +- Use `tox` and `pre-commit` to ease project maintenance. + [gforcada] 2.2.0a0 (2023-11-01) --------------------