Skip to content

Commit

Permalink
Upgrade linters and refactor how they run (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Aug 5, 2024
1 parent d5a2040 commit 1021e53
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 79 deletions.
1 change: 1 addition & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ rulebook
rulebooks
ruleset
servicebus
skipsdist
snakeoil
storepass
testenv
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/ack.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
---
# See https://github.com/ansible/devtools/blob/main/.github/workflows/ack.yml
name: ack
"on":
on:
pull_request_target:
types: [opened, labeled, unlabeled, synchronize]

permissions:
checks: write
contents: write # needed to update release
pull-requests: write # pr approval and merge

jobs:
ack:
uses: ansible/team-devtools/.github/workflows/ack.yml@main
Expand Down
43 changes: 0 additions & 43 deletions .github/workflows/linters.yml

This file was deleted.

2 changes: 0 additions & 2 deletions .isort.cfg

This file was deleted.

43 changes: 41 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,54 @@ ci:
exclude: "^.*\\.md$"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
language_version: python3
- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v8.13.0
rev: v8.13.1
hooks:
- id: cspell
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.5.6"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/PyCQA/flake8
rev: 7.1.0
hooks:
- id: flake8
- repo: https://github.com/pycqa/pylint
rev: v3.2.6
hooks:
- id: pylint
args:
- --output-format=colorized
additional_dependencies:
- aiobotocore
- aiohttp
- aiokafka
- asyncmock
- azure-servicebus
- dpath
- kafka-python
- psycopg
- pytest
- pyyaml
- requests
- watchdog
- xxhash
- ansible-core
- repo: local
hooks:
- id: ansible-test-sanity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class PathNotExistError(Exception):
"""Cannot find the path in the event."""


# pylint: disable=too-many-arguments
def main(
event: dict[str, Any],
host_path: str | None = None,
Expand Down
6 changes: 5 additions & 1 deletion extensions/eda/plugins/event_source/journald.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
import asyncio
from typing import Any

from systemd import journal
# https://github.com/pylint-dev/pylint/issues/7240
# Also systemd-python fails to install on pre-commit.ci due to:
# No such file or directory: 'pkg-config'
# pylint: disable=import-error
from systemd import journal # type: ignore


async def main(queue: asyncio.Queue, args: dict[str, Any]) -> str: # noqa: D417
Expand Down
3 changes: 3 additions & 0 deletions extensions/eda/plugins/event_source/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ async def _hmac_verify(request: web.Request) -> bool:
event_digest = base64.b64encode(event_hmac.digest()).decode("utf-8")
elif hmac_format == "hex":
event_digest = event_hmac.hexdigest()
else:
msg = f"Unsupported HMAC header format {hmac_format}"
raise ValueError(msg)

return hmac.compare_digest(hmac_header_digest, event_digest)

Expand Down
2 changes: 0 additions & 2 deletions lint_requirements.txt

This file was deleted.

22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[tool.black]
target-version = ["py310"]

[tool.isort]
profile = "black"
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
ensure_newline_before_comments = true
line_length = 88

[tool.pylint.MASTER]
# Temporary ignore until we are able to address issues on these:
ignore-paths = "^(demos/dynatrace-demo/fake_app.py|tests/|plugins/modules).*$"

[tool.pylint."MESSAGES CONTROL"]
disable = [
"duplicate-code",
"pointless-string-statement",
"too-few-public-methods",
]
1 change: 0 additions & 1 deletion test_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
-r requirements.txt
-r lint_requirements.txt
pytest
asyncmock
pytest-asyncio
Expand Down
31 changes: 4 additions & 27 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,20 @@
# {posargs} in this case would be the path to collection root relative from the .github/workflows dir (`../..`)

[tox]
# envlist = ruff, darglint, pylint-event-source, pylint-event-filter
envlist = lint, ruff, pylint-event-source, pylint-event-filter, isort, black
envlist = lint
requires =
lint
ruff
darglint
pylint
skipsdist = true # this repo is not a python package

[testenv]
basepython = python3.9, python3.10

[testenv:lint]
deps = pre-commit
desc = Run linters
description = Run linters
commands = pre-commit run -a

[testenv:ruff]
deps = -r{toxinidir}/lint_requirements.txt
commands = ruff check --select ALL --ignore INP001,RUF100,FA102,PLR0913 -q extensions/eda/plugins

[testenv:darglint]
deps = darglint
commands = darglint -s numpy -z full extensions/eda/plugins

[testenv:isort]
deps = isort
commands = isort {toxinidir}

[testenv:black]
deps = black
commands = black {toxinidir}

[testenv:pylint-event-source]
deps = -r{toxinidir}/lint_requirements.txt
-r{toxinidir}/requirements.txt
commands = pylint extensions/eda/plugins/event_source/*.py --output-format=parseable -sn --disable R0801,R0903,W0105

[testenv:pylint-event-filter]
deps = -r{toxinidir}/lint_requirements.txt
-r{toxinidir}/requirements.txt
commands = pylint extensions/eda/plugins/event_filter/*.py --output-format=parseable -sn --disable R0801

0 comments on commit 1021e53

Please sign in to comment.