From bfc06c8605536ba4c6aebfaa89ba2d0e34b526d1 Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Tue, 6 Dec 2022 23:54:53 -0500 Subject: [PATCH] Update linting and test environments (#26) --- .flake8 | 6 ---- .github/workflows/test.yml | 4 +-- README.md | 2 +- hatch.toml | 32 ++++++++++------- hatch_mypyc/hooks.py | 2 +- hatch_mypyc/plugin.py | 2 +- mypy.ini | 8 ----- pyproject.toml | 72 ++++++++++++++++++++++++++++++++------ 8 files changed, 86 insertions(+), 42 deletions(-) delete mode 100644 .flake8 delete mode 100644 mypy.ini diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 5e48b58..0000000 --- a/.flake8 +++ /dev/null @@ -1,6 +0,0 @@ -# TODO: move this to pyproject.toml when supported, see https://github.com/PyCQA/flake8/issues/234 - -[flake8] -select = B,C,E,F,W,B001,B003,B006,B007,B301,B305,B306,B902,Q000,Q001,Q002,Q003 -ignore = E203,E722,W503 -max-line-length = 120 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8416cbd..71daeae 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,7 +24,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11.0-beta.4 - 3.11'] + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] steps: - uses: actions/checkout@v3 @@ -35,7 +35,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install Hatch - run: pip install --upgrade --pre hatch + run: pip install --upgrade hatch - if: matrix.python-version == '3.9' && runner.os == 'Linux' name: Lint diff --git a/README.md b/README.md index 6d3faef..8616f76 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ | --- | --- | | CI/CD | [![CI - Test](https://github.com/ofek/hatch-mypyc/actions/workflows/test.yml/badge.svg)](https://github.com/ofek/hatch-mypyc/actions/workflows/test.yml) [![CD - Build](https://github.com/ofek/hatch-mypyc/actions/workflows/build.yml/badge.svg)](https://github.com/ofek/hatch-mypyc/actions/workflows/build.yml) | | Package | [![PyPI - Version](https://img.shields.io/pypi/v/hatch-mypyc.svg?logo=pypi&label=PyPI&logoColor=gold)](https://pypi.org/project/hatch-mypyc/) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/hatch-mypyc.svg?logo=python&label=Python&logoColor=gold)](https://pypi.org/project/hatch-mypyc/) | -| Meta | [![Hatch project](https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg)](https://github.com/pypa/hatch) [![code style - black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![types - Mypy](https://img.shields.io/badge/types-Mypy-blue.svg)](https://github.com/ambv/black) [![imports - isort](https://img.shields.io/badge/imports-isort-ef8336.svg)](https://github.com/pycqa/isort) [![License - MIT](https://img.shields.io/badge/license-MIT-9400d3.svg)](https://spdx.org/licenses/) [![GitHub Sponsors](https://img.shields.io/github/sponsors/ofek?logo=GitHub%20Sponsors&style=social)](https://github.com/sponsors/ofek) | +| Meta | [![Hatch project](https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg)](https://github.com/pypa/hatch) [![code style - black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![types - Mypy](https://img.shields.io/badge/types-Mypy-blue.svg)](https://github.com/ambv/black) [![License - MIT](https://img.shields.io/badge/license-MIT-9400d3.svg)](https://spdx.org/licenses/) [![GitHub Sponsors](https://img.shields.io/github/sponsors/ofek?logo=GitHub%20Sponsors&style=social)](https://github.com/sponsors/ofek) | ----- diff --git a/hatch.toml b/hatch.toml index 324bc58..509149b 100644 --- a/hatch.toml +++ b/hatch.toml @@ -1,36 +1,42 @@ [envs.default] dependencies = [ - "coverage[toml]>=6.2", + "coverage[toml]>=6.5", "pytest", - "pytest-cov", "pytest-mock", "packaging", "build[virtualenv]", ] [envs.default.scripts] -cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=hatch_mypyc --cov=tests {args:tests}" -no-cov = "pytest --no-cov {args:tests}" +test = "pytest {args:tests}" +test-cov = "coverage run -m pytest {args:tests}" +cov-report = [ + "- coverage combine", + "coverage report --show-missing", +] +cov = [ + "test-cov", + "cov-report", +] + +[[envs.all.matrix]] +python = ["3.7", "3.8", "3.9", "3.10", "3.11"] [envs.lint] detached = true dependencies = [ - "flake8>=4.0.1", - "flake8-bugbear>=22.3.23", - "flake8-quotes>=3.3.1", - "black>=22.3.0", - "isort>=5.10.1", - "mypy>=0.942", + "black>=22.10.0", + "mypy>=0.991", + "ruff>=0.0.166", ] [envs.lint.scripts] typing = "mypy --install-types --non-interactive {args:hatch_mypyc tests}" style = [ - "flake8 {args:.}", + "ruff {args:.}", "black --check --diff {args:.}", - "isort --check-only --diff {args:.}", ] fmt = [ - "isort {args:.}", "black {args:.}", + "ruff --fix {args:.}", "style", ] all = [ diff --git a/hatch_mypyc/hooks.py b/hatch_mypyc/hooks.py index 19ccbf6..f682af8 100644 --- a/hatch_mypyc/hooks.py +++ b/hatch_mypyc/hooks.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: MIT from hatchling.plugin import hookimpl -from .plugin import MypycBuildHook +from hatch_mypyc.plugin import MypycBuildHook @hookimpl diff --git a/hatch_mypyc/plugin.py b/hatch_mypyc/plugin.py index bbd06d8..b05f139 100644 --- a/hatch_mypyc/plugin.py +++ b/hatch_mypyc/plugin.py @@ -13,7 +13,7 @@ import pathspec from hatchling.builders.hooks.plugin.interface import BuildHookInterface -from .utils import construct_setup_file, installed_in_prefix +from hatch_mypyc.utils import construct_setup_file, installed_in_prefix class MypycBuildHook(BuildHookInterface): diff --git a/mypy.ini b/mypy.ini deleted file mode 100644 index 1772231..0000000 --- a/mypy.ini +++ /dev/null @@ -1,8 +0,0 @@ -[mypy] -disallow_untyped_defs = false -follow_imports = normal -ignore_missing_imports = true -pretty = true -show_column_numbers = true -warn_no_return = false -warn_unused_ignores = true diff --git a/pyproject.toml b/pyproject.toml index 4d21da4..499ec0f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,27 +54,79 @@ mypyc = "hatch_mypyc.hooks" path = "hatch_mypyc/__about__.py" [tool.black] -include = '\.pyi?$' +target-version = ["py37"] line-length = 120 skip-string-normalization = true -target-version = ["py37"] -[tool.isort] -default_section = "THIRDPARTY" -force_grid_wrap = 0 -include_trailing_comma = true -known_first_party = ["hatch_mypyc"] -line_length = 120 -multi_line_output = 3 -use_parentheses = true +[tool.ruff] +target-version = "py37" +line-length = 120 +select = [ + "A", + "B", + "C", + "E", + "F", + "FBT", + "I", + "N", + "Q", + "RUF", + "S", + "T", + "UP", + "W", + "YTT", +] +ignore = [ + # Allow non-abstract empty methods in abstract base classes + "B027", + # Ignore McCabe complexity + "C901", + # Allow boolean positional values in function calls, like `dict.get(... True)` + "FBT003", + # Ignore checks for possible passwords + "S105", "S106", "S107", +] +unfixable = [ + # Don't touch unused imports + "F401", +] + +[tool.ruff.isort] +known-first-party = ["hatch_mypyc"] + +[tool.ruff.flake8-quotes] +inline-quotes = "single" + +[tool.ruff.flake8-tidy-imports] +ban-relative-imports = "all" + +[tool.ruff.per-file-ignores] +# Tests can use relative imports and assertions +"tests/**/*" = ["I252", "S101"] + +[tool.mypy] +disallow_untyped_defs = false +follow_imports = "normal" +ignore_missing_imports = true +pretty = true +show_column_numbers = true +warn_no_return = false +warn_unused_ignores = true [tool.coverage.run] +source_pkgs = ["hatch_mypyc", "tests"] branch = true parallel = true omit = [ "hatch_mypyc/__about__.py", ] +[tool.coverage.paths] +hatch_mypyc = ["hatch_mypyc", "*/hatch-mypyc/hatch_mypyc"] +tests = ["tests", "*/hatch-mypyc/tests"] + [tool.coverage.report] exclude_lines = [ "no cov",