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/.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 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 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) ------------------ 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(): 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/*", +] 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 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