From eb04a6f98b53410fc6f2348d65b88e24f539cba2 Mon Sep 17 00:00:00 2001 From: gram Date: Thu, 28 Sep 2023 08:21:43 +0200 Subject: [PATCH 1/5] sort imports, unify quotes --- flake8_warnings/_extractors/__init__.py | 2 +- flake8_warnings/_pylint_plugin.py | 2 +- tests/samples/warnings_function.py | 6 +++--- tests/samples/warnings_module.py | 4 ++-- tests/test_finder.py | 8 ++++---- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/flake8_warnings/_extractors/__init__.py b/flake8_warnings/_extractors/__init__.py index 6083a10..6b7aa65 100644 --- a/flake8_warnings/_extractors/__init__.py +++ b/flake8_warnings/_extractors/__init__.py @@ -7,7 +7,7 @@ from ._warnings import WarningsExtractor -__all__ = ["CODES", "EXTRACTORS", "Extractor", "WarningInfo"] +__all__ = ['CODES', 'EXTRACTORS', 'Extractor', 'WarningInfo'] EXTRACTORS: Tuple[Type[Extractor], ...] = ( DecoratorsExtractor, DocstringsExtractor, diff --git a/flake8_warnings/_pylint_plugin.py b/flake8_warnings/_pylint_plugin.py index 69f3f1c..7366ed6 100644 --- a/flake8_warnings/_pylint_plugin.py +++ b/flake8_warnings/_pylint_plugin.py @@ -20,7 +20,7 @@ CODE = 'W99{:02}' -def register(linter: "PyLinter") -> None: +def register(linter: 'PyLinter') -> None: linter.register_checker(PyLintChecker(linter)) diff --git a/tests/samples/warnings_function.py b/tests/samples/warnings_function.py index 6c8c4c2..ee98898 100644 --- a/tests/samples/warnings_function.py +++ b/tests/samples/warnings_function.py @@ -2,10 +2,10 @@ def func(): - warnings.warn("func warn", DeprecationWarning) + warnings.warn('func warn', DeprecationWarning) return 1 - warnings.warn("this one is ignored") # type: ignore + warnings.warn('this one is ignored') # type: ignore def not_imported_func(): - warnings.warn("this one is ignored") + warnings.warn('this one is ignored') diff --git a/tests/samples/warnings_module.py b/tests/samples/warnings_module.py index 62439af..bc1a187 100644 --- a/tests/samples/warnings_module.py +++ b/tests/samples/warnings_module.py @@ -1,7 +1,7 @@ import warnings -warnings.warn("mod warn", DeprecationWarning) +warnings.warn('mod warn', DeprecationWarning) def func(): @@ -9,4 +9,4 @@ def func(): def not_imported_func(): - warnings.warn("this one is ignored") + warnings.warn('this one is ignored') diff --git a/tests/test_finder.py b/tests/test_finder.py index 1808dd6..0f9b532 100644 --- a/tests/test_finder.py +++ b/tests/test_finder.py @@ -16,10 +16,10 @@ def e(node): return [(w.category, w.message) for w in WarningFinder(node).find()] -@pytest.mark.parametrize("given, etype, emsg", [ - ("import tests.samples.warnings_module", DeprecationWarning, "mod warn"), - ("from tests.samples.warnings_module import fun", DeprecationWarning, "mod warn"), - ("from tests.samples.warnings_function import func", DeprecationWarning, "func warn"), +@pytest.mark.parametrize('given, etype, emsg', [ + ('import tests.samples.warnings_module', DeprecationWarning, 'mod warn'), + ('from tests.samples.warnings_module import fun', DeprecationWarning, 'mod warn'), + ('from tests.samples.warnings_function import func', DeprecationWarning, 'func warn'), ]) def test_finder__import(given, etype, emsg): r = e(p(given)) From 7ec276a282f0527ca419c62a0f8db85d3043e36d Mon Sep 17 00:00:00 2001 From: gram Date: Thu, 28 Sep 2023 08:21:59 +0200 Subject: [PATCH 2/5] improve taskfile --- Taskfile.yml | 116 +++++++++++++++++++++++++++++++++++++------------ pyproject.toml | 19 ++++---- 2 files changed, 98 insertions(+), 37 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 1c974e5..1ba2cd0 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,73 +1,133 @@ -# https://taskfile.dev - +# https://taskfile.dev/ version: "3" vars: PYTHON: python3 + VENVS: .venvs + TEST_ENV: .venvs/test + LINT_ENV: .venvs/lint + TEST_PYTHON: "{{.TEST_ENV}}/bin/python3" + LINT_PYTHON: "{{.LINT_ENV}}/bin/python3" + env: FLIT_ROOT_INSTALL: "1" tasks: - install:base: + install:flit: status: - - test -f .venvs/base/bin/flitenv + - which flit cmds: - - "{{.PYTHON}} -m venv .venvs/base" - - .venvs/base/bin/python3 -m pip install -U flitenv pip-tools + - python3 -m pip install flit + venv:test: + status: + - test -d {{.TEST_ENV}} + cmds: + - "{{.PYTHON}} -m venv {{.TEST_ENV}}" + venv:lint: + status: + - test -d {{.LINT_ENV}} + cmds: + - "{{.PYTHON}} -m venv {{.LINT_ENV}}" install:test: sources: - pyproject.toml deps: - - install:base + - install:flit + - venv:test cmds: - - .venvs/base/bin/flitenv test install + - > + flit install + --python {{.TEST_PYTHON}} + --extras=test,integrations + --deps=production + --symlink install:lint: sources: - pyproject.toml deps: - - install:base + - install:flit + - venv:lint + cmds: + - > + flit install + --python {{.LINT_PYTHON}} + --extras=lint,integrations + --deps=production + --symlink + + release: + desc: generate and upload a new release + deps: + - install:flit cmds: - - .venvs/base/bin/flitenv lint install + - which gh + - test {{.CLI_ARGS}} + - cat flake8_warnings/__init__.py | grep {{.CLI_ARGS}} + - rm -rf dist/ + - flit build + - flit publish + - git tag {{.CLI_ARGS}} + - git push + - git push --tags + - gh release create --generate-notes {{.CLI_ARGS}} + - gh release upload {{.CLI_ARGS}} ./dist/* - pytest:run: + pytest: desc: "run Python tests" deps: - install:test cmds: - - .venvs/base/bin/flitenv test run pytest {{.CLI_ARGS}} - flake8_warnings:run: - desc: "run flake8_warnings" + - "{{.TEST_PYTHON}} -m pytest {{.CLI_ARGS}}" + flake8: + desc: "lint Python code" deps: - install:lint cmds: - - .venvs/base/bin/flitenv lint run python3 -m flake8_warnings {{.CLI_ARGS}} - flake8:run: - desc: "lint Python code" + - "{{.LINT_PYTHON}} -m flake8 {{.CLI_ARGS}} ." + mypy: + desc: "check type annotations" deps: - install:lint cmds: - - .venvs/base/bin/flitenv lint run flake8 {{.CLI_ARGS}} - mypy:run: - desc: "check type annotations" + - "{{.LINT_PYTHON}} -m mypy {{.CLI_ARGS}}" + unify: + desc: "convert double quotes to single ones" deps: - install:lint cmds: - - .venvs/base/bin/flitenv lint run mypy {{.CLI_ARGS}} - isort:run: + - "{{.LINT_PYTHON}} -m unify -r -i --quote=\\' {{.CLI_ARGS}} flake8_warnings tests" + isort: desc: "sort imports" deps: - install:lint cmds: - - .venvs/base/bin/flitenv lint run isort {{.CLI_ARGS}} . + - "{{.LINT_PYTHON}} -m isort {{.CLI_ARGS}} ." isort:check: - desc: "check if all imports are sorted" + desc: "sort imports" deps: - install:lint cmds: - - .venvs/base/bin/flitenv lint run isort {{.CLI_ARGS}} --check . - linters:run: + - "{{.LINT_PYTHON}} -m isort --check {{.CLI_ARGS}} ." + + # groups + format: + desc: "run all code formatters" + cmds: + - task: isort + - task: unify + lint: desc: "run all linters" cmds: - - task: flake8:run - - task: mypy:run + - task: flake8 + - task: mypy - task: isort:check + test: + desc: "run all tests" + cmds: + - task: pytest + all: + desc: "run all code formatters, linters, and tests" + cmds: + - task: format + - task: lint + - task: test diff --git a/pyproject.toml b/pyproject.toml index 27f0c68..f522b2b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,15 +4,13 @@ build-backend = "flit_core.buildapi" [project] name = "flake8-warnings" -authors = [ - {name = "Gram", email = "gram@orsinium.dev"}, -] -license = {file = "LICENSE"} +authors = [{ name = "Gram", email = "gram@orsinium.dev" }] +license = { file = "LICENSE" } readme = "README.md" requires-python = ">=3.6" dynamic = ["version", "description"] classifiers = [ - "Development Status :: 5 - Production/Stable", + "Development Status :: 5 - Production/Stable", "Environment :: Plugins", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", @@ -21,20 +19,23 @@ classifiers = [ "Topic :: Software Development :: Quality Assurance", ] keywords = [ + "deprecation", "flake8", "pylint", "warnings", "linter", "flakehell", ] -dependencies = ["astroid"] +dependencies = ["astroid>=3.0.0"] [project.optional-dependencies] test = ["pytest"] lint = [ - "flake8-length", - "mypy", - "isort", + "flake8", # linter + "flake8-length", # allow long strings + "mypy", # type checker + "isort", # sort imports + "unify", # use single quotes everywhere ] From c186854c39c6da742040b95e4a608d811e507196 Mon Sep 17 00:00:00 2001 From: gram Date: Thu, 28 Sep 2023 08:23:28 +0200 Subject: [PATCH 3/5] GitHub Actions --- .github/workflows/main.yml | 56 ++++++++++++++++++++++++++++++++++++++ .markdownlint.yaml | 8 ++++++ 2 files changed, 64 insertions(+) create mode 100644 .github/workflows/main.yml create mode 100644 .markdownlint.yaml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..db6a722 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,56 @@ +name: main + +on: + push: + branches: + - master + pull_request: + workflow_dispatch: + +concurrency: + group: ${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.8" + - uses: arduino/setup-task@v1 + with: + repo-token: ${{ github.token }} + - run: task lint + + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12.0rc3" + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - uses: arduino/setup-task@v1 + with: + repo-token: ${{ github.token }} + - run: task test + + markdownlint-cli: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: nosborn/github-action-markdown-cli@v3.2.0 + with: + files: . + config_file: .markdownlint.yaml + dot: true diff --git a/.markdownlint.yaml b/.markdownlint.yaml new file mode 100644 index 0000000..808d2a6 --- /dev/null +++ b/.markdownlint.yaml @@ -0,0 +1,8 @@ +# https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.yaml +default: true # enable all by default +MD007: # unordered list indentation + indent: 2 +MD013: false # do not validate line length +MD014: false # allow $ before command output +MD029: # ordered list prefix + style: "one" From acbf99312f91f2ad7cbe796b1ef07c702b4cc164 Mon Sep 17 00:00:00 2001 From: gram Date: Thu, 28 Sep 2023 08:27:28 +0200 Subject: [PATCH 4/5] fix Python 3.12 version --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index db6a722..b7f8166 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,7 +34,7 @@ jobs: - "3.9" - "3.10" - "3.11" - - "3.12.0rc3" + - "3.12.0-rc.3" steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 From a4ee4b5509b1807d98f1ea79f32af2638357d2c3 Mon Sep 17 00:00:00 2001 From: gram Date: Thu, 28 Sep 2023 08:40:38 +0200 Subject: [PATCH 5/5] disable 3.12 on CI --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b7f8166..164dc7e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,7 +34,7 @@ jobs: - "3.9" - "3.10" - "3.11" - - "3.12.0-rc.3" + # - "3.12.0-rc.3" steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4