Skip to content

Commit

Permalink
Bump linters, drop 3.6 support
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <[email protected]>
  • Loading branch information
gaborbernat committed Dec 28, 2021
1 parent 36e4e42 commit 0ad22b2
Show file tree
Hide file tree
Showing 24 changed files with 206 additions and 154 deletions.
66 changes: 20 additions & 46 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,22 @@ concurrency:
cancel-in-progress: true

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
- uses: pre-commit/[email protected]

test:
name: test ${{ matrix.py }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}-latest
name: test ${{ matrix.py }}
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
os:
- Ubuntu
py:
- 3.9
- 3.8
- 3.7
- 3.6
- pypy3
- "3.10"
- "3.9"
- "3.8"
- "3.7"
steps:
- name: setup python for tox
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: "3.10"
- name: install tox
run: python -m pip install tox
- uses: actions/checkout@v2
Expand All @@ -45,47 +35,31 @@ jobs:
python-version: ${{ matrix.py }}
- name: pick environment to run
run: |
import subprocess; import json; import os
major, minor, impl = json.loads(subprocess.check_output(["python", "-c", "import json; import sys; import platform; print(json.dumps([sys.version_info[0], sys.version_info[1], platform.python_implementation()]));"], universal_newlines=True))
import os
with open(os.environ['GITHUB_ENV'], 'a') as file_handler:
file_handler.write('TOXENV=' + ("py" if impl == "CPython" else "pypy") + ("{}{}".format(major, minor) if impl == "CPython" else ("3" if major == 3 else "")) + "\n")
file_handler.write('TOXENV=py${{matrix.py}}'.replace('.', ''))
shell: python
- name: setup test suite
run: tox -vv --notest
- name: run test suite
run: tox --skip-pkg-install
env:
PYTEST_ADDOPTS: "-vv --durations=20"
CI_RUN: "yes"
DIFF_AGAINST: HEAD
- name: rename coverage report file
run: |
import os; os.rename('.tox/coverage.{}.xml'.format(os.environ['TOXENV']), '.tox/coverage.xml')
shell: python
- uses: codecov/codecov-action@v1
with:
file: ./.tox/coverage.xml
flags: tests
name: ${{ matrix.py }} - ${{ matrix.os }}

check:
name: check ${{ matrix.tox_env }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}-latest
name: tox env ${{ matrix.tox_env }}
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
os:
- Ubuntu
tox_env:
- type
- dev
- pkg_check
- readme
steps:
- uses: actions/checkout@v2
- name: setup Python 3.8
- name: setup Python 3.10
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: "3.10"
- name: install tox
run: python -m pip install tox
- name: run check for ${{ matrix.tox_env }}
Expand All @@ -95,18 +69,18 @@ jobs:

publish:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
needs: [check, test, pre-commit]
runs-on: ubuntu-latest
needs: [check, test]
runs-on: ubuntu-20.04
steps:
- name: setup python to build package
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: install pep517
run: python -m pip install pep517
python-version: "3.10"
- name: install build
run: python -m pip install build
- uses: actions/checkout@v2
- name: build package
run: python -m pep517.build -s -b . -o dist
run: python -m build --sdist --wheel . -o dist
- name: publish to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
Expand Down
44 changes: 33 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,37 +1,59 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.0.1
hooks:
- id: check-ast
- id: check-builtin-literals
- id: check-docstring-first
- id: check-merge-conflict
- id: check-yaml
- id: check-toml
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v2.29.1
rev: v2.30.0
hooks:
- id: pyupgrade
args: [ "--py36-plus" ]
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.9.3
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 21.12b0
rev: 21.9b0
hooks:
- id: black
args: [--safe]
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.20.0
args: [ --safe ]
- repo: https://github.com/asottile/blacken-docs
rev: v1.11.0
hooks:
- id: setup-cfg-fmt
- id: blacken-docs
additional_dependencies: [ black==21.9b0 ]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
- id: rst-backticks
- repo: https://github.com/tox-dev/tox-ini-fmt
rev: "0.5.1"
hooks:
- id: tox-ini-fmt
- id: tox-ini-fmt
args: [ "-p", "fix" ]
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.17.0
hooks:
- id: setup-cfg-fmt
args: [ --min-py3-version, "3.7", "--max-py-version", "3.10" ]
- repo: https://github.com/PyCQA/flake8
rev: "4.0.1"
rev: 3.9.2
hooks:
- id: flake8
additional_dependencies: ["flake8-bugbear == 21.9.2"]
additional_dependencies:
- flake8-bugbear==21.9.1
- flake8-comprehensions==3.6.1
- flake8-pytest-style==1.5
- flake8-spellcheck==0.24
- flake8-unused-arguments==0.0.6
- flake8-noqa==1.1.0
- flake8-eradicate==1.1.0
- pep8-naming==0.12.1
6 changes: 0 additions & 6 deletions codecov.yml

This file was deleted.

42 changes: 20 additions & 22 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ classifiers =
License :: OSI Approved :: MIT License
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Expand All @@ -33,7 +32,7 @@ project_urls =

[options]
packages = find:
python_requires = >=3.6
python_requires = >=3.7
include_package_data = True
package_dir =
=src
Expand All @@ -48,43 +47,42 @@ console_scripts =

[options.extras_require]
docs =
Sphinx>=3
Sphinx>=4
test =
coverage>=5
coverage-enable-subprocess>=1
pytest>=4
covdefaults>=2
pytest>=6
pytest-cov>=3

[options.package_data]
tox_ini_fmt = py.typed

[flake8]
max-line-length = 120
ignore = F401, H301, E203
noqa-require-code = true

[coverage:report]
show_missing = True
exclude_lines =
\#\s*pragma: no cover
^\s*raise AssertionError\b
^\s*raise NotImplementedError\b
^\s*raise$
^if __name__ == ['"]__main__['"]:$
[coverage:run]
plugins = covdefaults
parallel = true

[coverage:paths]
source =
src =
src
.tox/*/lib/python*/site-packages
.tox/pypy*/site-packages
.tox\*\Lib\site-packages\
*/src
*\src
other =
.
*/tox-ini-fmt
*\tox-ini-fmt

[coverage:run]
branch = true
parallel = true
dynamic_context = test_function
source =
${_COVERAGE_SRC}
[coverage:report]
fail_under = 100

[coverage:html]
show_contexts = true
skip_covered = false

[coverage:covdefaults]
subtract_omit = */.tox/*
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from setuptools import setup

setup()
2 changes: 2 additions & 0 deletions src/tox_ini_fmt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from .version import __version__

__all__ = ("__version__",)
6 changes: 4 additions & 2 deletions src/tox_ini_fmt/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import annotations

import difflib
import sys
from pathlib import Path
from typing import Iterable, Optional, Sequence
from typing import Iterable, Sequence

from tox_ini_fmt.cli import cli_args
from tox_ini_fmt.formatter import format_tox_ini
Expand All @@ -21,7 +23,7 @@ def color_diff(diff: Iterable[str]) -> Iterable[str]:
yield line


def run(args: Optional[Sequence[str]] = None) -> int:
def run(args: Sequence[str] | None = None) -> int:
opts = cli_args(sys.argv[1:] if args is None else args)
formatted = format_tox_ini(opts.tox_ini, opts)
before = opts.tox_ini.read_text()
Expand Down
12 changes: 7 additions & 5 deletions src/tox_ini_fmt/cli.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from __future__ import annotations

import os
from argparse import Action, ArgumentParser, ArgumentTypeError, Namespace
from pathlib import Path
from typing import Any, List, Optional, Sequence, Union
from typing import Any, Sequence


class ToxIniFmtNamespace(Namespace):
"""Options for tox-ini-fmt tool"""

tox_ini: Path
stdout: bool
pin_toxenvs: List[str]
pin_toxenvs: list[str]


def tox_ini_path_creator(argument: str) -> Path:
Expand Down Expand Up @@ -49,11 +51,11 @@ def __call__(
self,
parser: ArgumentParser,
namespace: Namespace,
values: Union[str, Sequence[Any], None],
option_string: Optional[str] = None,
values: str | Sequence[Any] | None,
option_string: str | None = None,
) -> None:
if isinstance(values, str): # pragma: no cover
setattr(namespace, self.dest, list(i.strip() for i in values.split(",")))
setattr(namespace, self.dest, [i.strip() for i in values.split(",")])

parser.add_argument(
"-p",
Expand Down
5 changes: 3 additions & 2 deletions src/tox_ini_fmt/formatter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from configparser import ConfigParser
from io import StringIO
from pathlib import Path
from typing import Optional

from tox_ini_fmt.cli import ToxIniFmtNamespace

Expand All @@ -12,7 +13,7 @@
INDENTATION = " "


def format_tox_ini(tox_ini: Path, opts: Optional[ToxIniFmtNamespace] = None) -> str:
def format_tox_ini(tox_ini: Path, opts: ToxIniFmtNamespace | None = None) -> str:
if opts is None:
opts = ToxIniFmtNamespace(pin_toxenvs=[])
parser = ConfigParser(interpolation=None)
Expand Down
5 changes: 3 additions & 2 deletions src/tox_ini_fmt/formatter/requires.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import annotations

import re
from typing import List

BASE_NAME_REGEX = re.compile(r"[^!=><~\s@]+")
REQ_REGEX = re.compile(r"(===|==|!=|~=|>=?|<=?|@)\s*([^,]+)")


def requires(raws: List[str]) -> List[str]:
def requires(raws: list[str]) -> list[str]:
values = (_normalize_req(req) for req in raws if req)
normalized = sorted(values, key=lambda req: (";" in req, _req_base(req), req))
return normalized
Expand Down
Loading

0 comments on commit 0ad22b2

Please sign in to comment.