Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI (Github Actions) #5

Merged
merged 5 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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.0-rc.3"
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
8 changes: 8 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -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"
116 changes: 88 additions & 28 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion flake8_warnings/_extractors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ._warnings import WarningsExtractor


__all__ = ["CODES", "EXTRACTORS", "Extractor", "WarningInfo"]
__all__ = ['CODES', 'EXTRACTORS', 'Extractor', 'WarningInfo']
EXTRACTORS: Tuple[Type[Extractor], ...] = (
DecoratorsExtractor,
DocstringsExtractor,
Expand Down
2 changes: 1 addition & 1 deletion flake8_warnings/_pylint_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
CODE = 'W99{:02}'


def register(linter: "PyLinter") -> None:
def register(linter: 'PyLinter') -> None:
linter.register_checker(PyLintChecker(linter))


Expand Down
19 changes: 10 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
]


Expand Down
6 changes: 3 additions & 3 deletions tests/samples/warnings_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
4 changes: 2 additions & 2 deletions tests/samples/warnings_module.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import warnings


warnings.warn("mod warn", DeprecationWarning)
warnings.warn('mod warn', DeprecationWarning)


def func():
pass


def not_imported_func():
warnings.warn("this one is ignored")
warnings.warn('this one is ignored')
8 changes: 4 additions & 4 deletions tests/test_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down