From a1578ff608c14ef43b54a1caaa658664681b792c Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Fri, 3 Nov 2023 00:03:03 +0100 Subject: [PATCH 1/8] feat: switch from setup.py to pyproject.toml --- pyproject.toml | 47 ++++++++++++++++++++++++++++++++++++++++++ setup.py | 56 -------------------------------------------------- 2 files changed, 47 insertions(+), 56 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..38b99e4 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,47 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "flake8-pep3101" +version = "2.0.1.dev0" +authors = [ + { name="Gil Forcada Codinachs", email="gil.gnome@gmail.com" }, +] +description = "Checks for old string formatting" +keywords = ["pep8", "flake8", "python", "pycodestyle", "string formatting"] +license = {file = "LICENSE"} +readme = "README.rst" +requires-python = ">=3.8" +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "Framework :: Flake8", + "Intended Audience :: Developers", + "License :: OSI Approved :: GNU General Public License v2 (GPLv2)", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.8", + "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", + "Topic :: Software Development :: Quality Assurance", +] +dependencies = ["flake8"] + +[project.urls] +"Homepage" = "https://github.com/gforcada/flake8-pep3101" +"Bug Tracker" = "https://github.com/gforcada/flake8-pep3101/issues" +"Changelog" = "https://github.com/gforcada/flake8-pep3101/blob/main/CHANGES.rst" + +[project.optional-dependencies] +test = ["pytest"] + +[project.entry-points."flake8.extension"] +S001 = "flake8_pep3101:Flake8Pep3101" diff --git a/setup.py b/setup.py deleted file mode 100644 index 065abfa..0000000 --- a/setup.py +++ /dev/null @@ -1,56 +0,0 @@ -from setuptools import setup - -short_description = 'Checks for old string formatting.' - - -def read_file(filename): - with open(filename) as file_obj: - file_contents = file_obj.read() - return file_contents - - -long_description = f""" -{read_file('README.rst')} -{read_file('CHANGES.rst')} -""" - - -setup( - name='flake8-pep3101', - version='2.0.1.dev0', - description=short_description, - long_description=long_description, - # Get more from https://pypi.org/classifiers/ - classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Environment :: Console', - 'Framework :: Flake8', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: GNU General Public License v2 (GPLv2)', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3 :: Only', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'Programming Language :: Python :: Implementation :: CPython', - 'Programming Language :: Python :: Implementation :: PyPy', - 'Topic :: Software Development', - 'Topic :: Software Development :: Quality Assurance', - ], - python_requires='>=3.8', - keywords='pep8 pycodestyle flake8 python string formatting', - author='Gil Forcada', - author_email='gil.gnome@gmail.com', - url='https://github.com/gforcada/flake8-pep3101', - license='GPL version 2', - py_modules=['flake8_pep3101'], - include_package_data=True, - test_suite='run_tests', - zip_safe=False, - install_requires=['flake8'], - extras_require={'test': ['pytest']}, - entry_points={'flake8.extension': ['S001 = flake8_pep3101:Flake8Pep3101']}, -) From d2122cbcd2546184673e6029fbfab87307cbb780 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Fri, 3 Nov 2023 00:03:35 +0100 Subject: [PATCH 2/8] feat: configure tools --- .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 38b99e4..22a18b8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,3 +45,16 @@ test = ["pytest"] [project.entry-points."flake8.extension"] S001 = "flake8_pep3101:Flake8Pep3101" + +[tool.isort] +profile = "plone" + +[tool.black] +target-version = ["py38"] +skip-string-normalization = true + +[tool.check-manifest] +ignore = [ + ".vscode/*", + "venv/*", +] From dfd7d79b6aab27655765e9cad8928874cd916fb0 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Fri, 3 Nov 2023 00:04:28 +0100 Subject: [PATCH 3/8] feat: add pre-commit configuration --- .pre-commit-config.yaml | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 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..58350c5 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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-builtins + - flake8-comprehensions + - flake8-debugger + - flake8-deprecated + - flake8-isort + - 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 From b03fe6b71863f16280e22766a4e9d6bc02943708 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Fri, 3 Nov 2023 00:04:46 +0100 Subject: [PATCH 4/8] 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 4d8bde1da8778c2cd8a661bef30b4fe52954e463 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Fri, 3 Nov 2023 00:05:04 +0100 Subject: [PATCH 5/8] chore: isort --- flake8_pep3101.py | 4 ++-- run_tests.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/flake8_pep3101.py b/flake8_pep3101.py index ee12194..f97750e 100644 --- a/flake8_pep3101.py +++ b/flake8_pep3101.py @@ -1,7 +1,7 @@ -import ast - from flake8 import utils as stdin_utils +import ast + class Flake8Pep3101: name = 'flake8_pep3101' diff --git a/run_tests.py b/run_tests.py index 15de663..73d323a 100644 --- a/run_tests.py +++ b/run_tests.py @@ -1,9 +1,9 @@ +from flake8_pep3101 import Flake8Pep3101 +from unittest import mock + import ast import textwrap import unittest -from unittest import mock - -from flake8_pep3101 import Flake8Pep3101 class NewTestFlake8Pep3101(unittest.TestCase): From ca5ea29b6582f65a76d826a4973e1cbf3fbd611e Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Fri, 3 Nov 2023 00:06:04 +0100 Subject: [PATCH 6/8] feat: use tox on GHA --- .github/workflows/testing.yml | 76 ++++++++++++++++------------------- 1 file changed, 34 insertions(+), 42 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 3ab1685..79f07ff 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -1,20 +1,20 @@ name: Testing on: push: - branches: [master] + branches: [main] pull_request: - branches: [master] + branches: [main] env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: test: name: Testing on - runs-on: ubuntu-latest + runs-on: "ubuntu-latest" strategy: matrix: - python-version: ["3.12.0-beta.2", "3.11", "3.10", 3.9, 3.8, pypy-3.9] + python-version: ["3.12", "3.11", "3.10", 3.9, 3.8, pypy-3.9] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v4 with: @@ -23,44 +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.txt - - name: Install dependencies - if: matrix.python-version == '3.9' - run: python -m pip install -r requirements-lint.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 - - name: Lint with mypy - if: matrix.python-version == '3.9' - run: | - mkdir --parents --verbose .mypy_cache - mypy --ignore-missing-imports --install-types --non-interactive *.py || true - # 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 a454ee3c2d12afa336bd3870bc749beb9cebf820 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Fri, 3 Nov 2023 00:06:14 +0100 Subject: [PATCH 7/8] cleanup: remove unused files --- requirements-lint.in | 20 ------ requirements-lint.txt | 142 ------------------------------------------ requirements.in | 4 -- requirements.txt | 50 --------------- 4 files changed, 216 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/requirements-lint.in b/requirements-lint.in deleted file mode 100644 index 8d78dd7..0000000 --- a/requirements-lint.in +++ /dev/null @@ -1,20 +0,0 @@ -bandit -black -codespell -coveralls -flake8-blind-except -flake8-builtins -flake8-bugbear -flake8-comprehensions -flake8-debugger -flake8-deprecated -flake8-isort -flake8-pep3101 -flake8-print -flake8-quotes -flake8-todo -isort -mypy -pytest -pytest-cov -pyupgrade diff --git a/requirements-lint.txt b/requirements-lint.txt deleted file mode 100644 index 8c7df3d..0000000 --- a/requirements-lint.txt +++ /dev/null @@ -1,142 +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.9.1 - # via -r requirements-lint.in -certifi==2023.7.22 - # via requests -charset-normalizer==3.2.0 - # via requests -click==8.1.7 - # via black -codespell==2.2.5 - # 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-builtins - # 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.7.10 - # via -r requirements-lint.in -flake8-builtins==2.1.0 - # 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.10 - # via gitpython -gitpython==3.1.36 - # 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==1.5.1 - # via -r requirements-lint.in -mypy-extensions==1.0.0 - # via - # black - # mypy -packaging==23.1 - # via - # black - # pytest -pathspec==0.11.2 - # via black -pbr==5.11.1 - # via stevedore -platformdirs==3.10.0 - # via black -pluggy==1.3.0 - # via pytest -pycodestyle==2.11.0 - # via - # flake8 - # flake8-debugger - # flake8-print - # flake8-todo -pyflakes==3.1.0 - # via flake8 -pygments==2.16.1 - # via rich -pytest==7.4.2 - # via - # -r requirements-lint.in - # pytest-cov -pytest-cov==4.1.0 - # via -r requirements-lint.in -pyupgrade==3.11.0 - # via -r requirements-lint.in -pyyaml==6.0.1 - # via bandit -requests==2.31.0 - # via coveralls -rich==13.5.2 - # via bandit -smmap==5.0.0 - # via gitdb -stevedore==5.1.0 - # via bandit -tokenize-rt==5.2.0 - # via pyupgrade -tomli==2.0.1 - # via - # black - # coverage - # mypy - # pytest -typing-extensions==4.7.1 - # via - # black - # mypy - # rich -urllib3==2.0.4 - # 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 d64309e..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.2.0 - # 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.1 - # via pytest -pluggy==1.3.0 - # via pytest -pycodestyle==2.11.0 - # via flake8 -pyflakes==3.1.0 - # via flake8 -pytest==7.4.2 - # 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.4 - # via requests From f8ab5ffd4157c7b35e14562d6364a8694be6a15e Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Fri, 3 Nov 2023 00:06:51 +0100 Subject: [PATCH 8/8] Update CHANGES --- CHANGES.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 320a1b1..6575b7b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -9,7 +9,19 @@ Changelog - Drop python 3.7 support. [gforcada] -- Test against python 3.12 pre-release. +- Test against python 3.12. + [gforcada] + +- Use `pyproject.toml` rather than `setup.py`. + [gforcada] + +- Switch from `setuptools` to `hatchling`. + [gforcada] + +- Switch to `main` branch. + [gforcada] + +- Use `tox` and `pre-commit` to ease project maintenance. [gforcada] 2.0.0 (2022-10-08)