From 3ea6c368d4c557a99551f3d511519ed9039b8597 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Fri, 3 Nov 2023 11:59:05 +0100 Subject: [PATCH 1/8] chore: adjust pyproject.toml Use the same template as `flake8-deprecated` and all other flake8 plugins I maintain. --- pyproject.toml | 80 +++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 09834cf..0fbcaad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,55 +1,61 @@ [build-system] -requires = ["setuptools>=61.2"] -build-backend = "setuptools.build_meta" +requires = ["hatchling"] +build-backend = "hatchling.build" [project] name = "flake8-isort" version = "6.1.1.dev0" -authors = [{ name = "Gil Forcada", email = "gil.gnome@gmail.com" }] -license = { text = "GPL version 2" } -description = "flake8 plugin that integrates isort ." +authors = [ + { name="Gil Forcada Codinachs", email="gil.gnome@gmail.com" }, +] +description = "flake8 plugin that integrates isort" keywords = ["pep8", "flake8", "python", "isort", "imports"] +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 :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: PyPy", - "Topic :: Software Development", - "Topic :: Software Development :: Quality Assurance", + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "Framework :: Flake8", + 'Framework :: Plone', + "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", ] -urls = { Homepage = "https://github.com/gforcada/flake8-isort" } -requires-python = ">=3.8" dependencies = ["flake8", "isort >= 5.0.0, <6"] -[project.entry-points] -"flake8.extension" = { I00 = "flake8_isort:Flake8Isort" } +[project.urls] +"Homepage" = "https://github.com/gforcada/flake8-isort" +"Bug Tracker" = "https://github.com/gforcada/flake8-isort/issues" +"Changelog" = "https://github.com/gforcada/flake8-isort/blob/main/CHANGES.rst" [project.optional-dependencies] test = ["pytest"] -[tool.setuptools] -py-modules = ["flake8_isort"] -zip-safe = false -include-package-data = true +[project.entry-points."flake8.extension"] +I00 = "flake8_isort:Flake8Isort" + +[tool.isort] +profile = "plone" -[tool."zest.releaser"] -create-wheel = "yes" +[tool.black] +target-version = ["py38"] +skip-string-normalization = true [tool.check-manifest] -ignore = """ -.installed.cfg""" - -[tool.isort] -profile = "black" +ignore = [ + ".vscode/*", + "venv/*", +] From 9d16c8305b5aba5dab882db25fd5c7cf4b40651e Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Fri, 3 Nov 2023 11:59:53 +0100 Subject: [PATCH 2/8] feat: add pre-commit configuration --- .pre-commit-config.yaml | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 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..3f26833 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,51 @@ +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-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 From 6312c05e2346345cbadc5bc4ecfc51424d59c19c Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Fri, 3 Nov 2023 12:00:20 +0100 Subject: [PATCH 3/8] feat: update tox configuration --- tox.ini | 54 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/tox.ini b/tox.ini index a2df03a..bfb4fc1 100644 --- a/tox.ini +++ b/tox.ini @@ -1,13 +1,51 @@ [tox] -env_list = +min_version = 4.4.0 +envlist = + format + lint + coverage + py38 + py39 py310 -minversion = 4.11.3 + py311 + py312 + pypy3 -[testenv] -description = run the tests with pytest -package = wheel -wheel_build_env = .pkg +[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 = - pytest>=6 + coverage commands = - pytest {tty:--color=yes} run_tests.py {posargs} + pytest run_tests.py --cov --cov-report term-missing +extras = + test From 8676edc89ad0e8ca479bd09bb78ad1ddbd713214 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Fri, 3 Nov 2023 12:00:55 +0100 Subject: [PATCH 4/8] chore: isort --- flake8_isort.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/flake8_isort.py b/flake8_isort.py index 8de084e..ae1b173 100644 --- a/flake8_isort.py +++ b/flake8_isort.py @@ -1,11 +1,12 @@ -import warnings from contextlib import redirect_stdout from difflib import unified_diff -from importlib.metadata import PackageNotFoundError, version +from importlib.metadata import PackageNotFoundError +from importlib.metadata import version from io import StringIO from pathlib import Path import isort +import warnings def _version(): From cfea8b12f09b0b438775c8086a548a01d6cd5af0 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Fri, 3 Nov 2023 12:01:04 +0100 Subject: [PATCH 5/8] feat: configure tools --- .flake8 | 13 +++++++++++++ 1 file changed, 13 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, From a5f19e962fa5ff3f98c7a68f85f667a183892630 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Fri, 3 Nov 2023 12:01:18 +0100 Subject: [PATCH 6/8] feat: use tox on GHA --- .github/workflows/tests.yml | 99 +++++++++++++------------------------ 1 file changed, 35 insertions(+), 64 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1df8c91..79f07ff 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,33 +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: py-${{ matrix.python-version }}/isort-${{ matrix.isort }}/flake8-${{ matrix.flake8 }} - runs-on: ubuntu-latest + name: Testing on + runs-on: "ubuntu-latest" strategy: matrix: - python-version: ["3.12.0-beta.2", "3.11", "3.10", 3.9, 3.8, pypy-3.9] - isort: [5.11.2] - flake8: [5.0.4] - include: - - python-version: 3.9 - isort: 5.11.2 - flake8: 4.0.1 - qa: 'true' - - python-version: 3.9 - isort: 5.11.2 - flake8: 3.9.2 - - python-version: 3.9 - isort: 5.11.2 - flake8: 6.0.0 + 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: @@ -36,52 +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.qa != 'true' - run: | - python -m pip install -r requirements.txt - pip install 'isort==${{ matrix.isort }}' 'flake8==${{ matrix.flake8 }}' - - name: Install dependencies - if: matrix.qa == 'true' - run: | - python -m pip install -r requirements-lint.txt - pip install 'isort==${{ matrix.isort }}' 'flake8==${{ matrix.flake8 }}' - # isort 4.x requires `toml` to be able to read pyproject.toml, so install it... - - name: Install toml if required - run: pip install toml - if: matrix.isort == '4.3.21' - # formatters - - name: Run pyupgrade - if: matrix.qa == 'true' - run: pyupgrade --py37-plus *.py - - name: Run isort - if: matrix.qa == 'true' - run: isort --check-only *.py - - name: Run black - if: matrix.qa == 'true' - run: black --check --skip-string-normalization *.py - # linters - - name: Lint with bandit - if: matrix.qa == 'true' - run: bandit --skip B101 *.py # B101 is assert statements - - name: Lint with codespell - if: matrix.qa == 'true' - run: codespell *.rst *.py - - name: Lint with flake8 - if: matrix.qa == 'true' - run: flake8 *.py --count --max-complexity=18 --max-line-length=88 --show-source --statistics - - name: Lint with mypy - if: matrix.qa == 'true' - 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 6ef3dc54050a8aea275fd5c9d8f10a4cc7b7b151 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Fri, 3 Nov 2023 12:01:33 +0100 Subject: [PATCH 7/8] cleanup: remove unused files --- requirements-lint.in | 22 ------- requirements-lint.txt | 139 ------------------------------------------ requirements.in | 5 -- requirements.txt | 52 ---------------- 4 files changed, 218 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 85e1ab8..0000000 --- a/requirements-lint.in +++ /dev/null @@ -1,22 +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 -importlib-metadata; python_version < '3.8' -isort -mypy -pytest -pytest-cov -pyupgrade -typed-ast; python_version < '3.8' # dependency of black and mypy -zipp; python_version < '3.8' # dependency of importlib-metadata diff --git a/requirements-lint.txt b/requirements-lint.txt deleted file mode 100644 index 7a6fac0..0000000 --- a/requirements-lint.txt +++ /dev/null @@ -1,139 +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-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-comprehensions==3.14.0 - # via -r requirements-lint.in -flake8-debugger==4.1.2 - # via -r requirements-lint.in -flake8-deprecated==2.0.1 - # via -r requirements-lint.in -flake8-isort==6.0.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.10.1 - # 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 09ff3bd..0000000 --- a/requirements.in +++ /dev/null @@ -1,5 +0,0 @@ -coveralls -flake8 -isort -pytest -pytest-cov diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 269819b..0000000 --- a/requirements.txt +++ /dev/null @@ -1,52 +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 -isort==5.12.0 - # via -r requirements.in -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 3335735b60c602e6f85afa56c23bdbeb5fbc5c74 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Fri, 3 Nov 2023 12:02:49 +0100 Subject: [PATCH 8/8] Update CHANGES --- CHANGES.rst | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 2871390..434cb46 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,8 +6,17 @@ Changelog 6.1.1 (unreleased) ------------------ -- Nothing changed yet. +- Switch from `setup.cfg` to `setup.py`. + [deronnax] + +- Switch from `setuptools` to `hatchling`. + [gforcada] +- Switch to `main` branch. + [gforcada] + +- Use `tox` and `pre-commit` to ease project maintenance. + [gforcada] 6.1.0 (2023-09-15) ------------------