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

Improve tooling #117

Merged
merged 10 commits into from
Nov 2, 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
13 changes: 13 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -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,
67 changes: 30 additions & 37 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
50 changes: 50 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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
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:
- 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
4 changes: 2 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
--------------------
Expand Down
12 changes: 3 additions & 9 deletions flake8_builtins.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
from flake8 import utils as stdin_utils

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:
Expand Down Expand Up @@ -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):
Expand Down
14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -44,3 +45,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/*",
]
18 changes: 0 additions & 18 deletions requirements-lint.in

This file was deleted.

133 changes: 0 additions & 133 deletions requirements-lint.txt

This file was deleted.

4 changes: 0 additions & 4 deletions requirements.in

This file was deleted.

Loading