From f909538e602c64fbe0f3c492c09ad7e8d29f5ad6 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 12 Apr 2023 01:34:33 +0200 Subject: [PATCH 1/3] ci: replace flake8 with ruff --- .flake8 | 5 -- .github/workflows/lint_python.yml | 14 +++++ .github/workflows/push.yml | 24 --------- ansible/plugins/inventory/nodejs_yaml.py | 3 +- ansible/plugins/library/remmina_config.py | 4 +- ansible/plugins/library/ssh_config.py | 2 +- .../tools/metrics/country-lookup.py | 5 +- pyproject.toml | 52 +++++++++++++++++++ 8 files changed, 75 insertions(+), 34 deletions(-) delete mode 100644 .flake8 create mode 100644 .github/workflows/lint_python.yml delete mode 100644 .github/workflows/push.yml create mode 100644 pyproject.toml diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 6f8eaa111..000000000 --- a/.flake8 +++ /dev/null @@ -1,5 +0,0 @@ -[flake8] -exclude=.venv -max-line-length=250 -import-order-style=google -ignore=E111 diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml new file mode 100644 index 000000000..d9ab9469e --- /dev/null +++ b/.github/workflows/lint_python.yml @@ -0,0 +1,14 @@ +# https://beta.ruff.rs +name: lint_python +on: + push: + branches: [main] + pull_request: + branches: [main] +jobs: + lint_python: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: pip install --user ruff + - run: ruff --format=github . diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml deleted file mode 100644 index a98447bda..000000000 --- a/.github/workflows/push.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Lint -on: - push: - branches-ignore: - - "dependabot/*" - pull_request: -jobs: - Python: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v3 - - name: Set up Python 3.7 - uses: actions/setup-python@v4 - with: - python-version: 3.7 - - name: Install dependencies - run: | - python -m pip install --upgrade pip - # pip install -r requirements.txt # TODO: Add tap2junit - - name: Lint with flake8 - run: | - pip install flake8 - flake8 --version - flake8 . diff --git a/ansible/plugins/inventory/nodejs_yaml.py b/ansible/plugins/inventory/nodejs_yaml.py index ece586789..65ba340e5 100755 --- a/ansible/plugins/inventory/nodejs_yaml.py +++ b/ansible/plugins/inventory/nodejs_yaml.py @@ -32,6 +32,7 @@ from os import path import yaml + try: import configparser except ImportError: @@ -278,7 +279,7 @@ def parse_yaml(hosts, config): def parse_host(host): """Parses a host and validates it against our naming conventions""" - hostinfo = dict() + hostinfo = {} info = host.split('-') expected = ['type', 'provider', 'os', 'arch', 'uid'] diff --git a/ansible/plugins/library/remmina_config.py b/ansible/plugins/library/remmina_config.py index 1152e7008..e9a4b29fc 100755 --- a/ansible/plugins/library/remmina_config.py +++ b/ansible/plugins/library/remmina_config.py @@ -27,9 +27,11 @@ import base64 import os -from ansible.module_utils.basic import AnsibleModule from Crypto.Cipher import DES3 from jinja2 import Environment + +from ansible.module_utils.basic import AnsibleModule + try: import configparser # Python 3 except ImportError: diff --git a/ansible/plugins/library/ssh_config.py b/ansible/plugins/library/ssh_config.py index 7f89ee484..e13acf356 100755 --- a/ansible/plugins/library/ssh_config.py +++ b/ansible/plugins/library/ssh_config.py @@ -25,9 +25,9 @@ import os import re -from ansible.module_utils.basic import AnsibleModule from jinja2 import Environment +from ansible.module_utils.basic import AnsibleModule pre_match = '# begin: node.js template' post_match = '# end: node.js template' diff --git a/ansible/www-standalone/tools/metrics/country-lookup.py b/ansible/www-standalone/tools/metrics/country-lookup.py index b7bb25d3c..6a132f63c 100755 --- a/ansible/www-standalone/tools/metrics/country-lookup.py +++ b/ansible/www-standalone/tools/metrics/country-lookup.py @@ -1,9 +1,10 @@ #!/usr/bin/env python -import sys import csv -import geoip2.database import os +import sys + +import geoip2.database reader = geoip2.database.Reader(os.path.dirname(os.path.realpath(__file__)) + '/GeoLite2-City.mmdb') diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..69c5ae6d1 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,52 @@ +[tool.ruff] +select = [ + "A", # flake8-builtins + "ARG", # flake8-unused-arguments + "B", # flake8-bugbear + "C4", # flake8-comprehensions + "C90", # McCabe cyclomatic complexity + "E", # pycodestyle + "EM", # flake8-errmsg + "EXE", # flake8-executable + "F", # Pyflakes + "G", # flake8-logging-format + "I", # isort + "ICN", # flake8-import-conventions + "INT", # flake8-gettext + "ISC", # flake8-implicit-str-concat + "PGH", # pygrep-hooks + "PIE", # flake8-pie + "PL", # Pylint + "PT", # flake8-pytest-style + "PYI", # flake8-pyi + "RET", # flake8-return + "RSE", # flake8-raise + "RUF", # Ruff-specific rules + "S", # flake8-bandit + "SIM", # flake8-simplify + "SLF", # flake8-self + "T10", # flake8-debugger + "TCH", # flake8-type-checking + "TID", # flake8-tidy-imports + "W", # pycodestyle + "YTT", # flake8-2020 +] +ignore = [ + "B904", + "PLR2004", + "RET505", + "RUF005", + "S110", + "S701" +] +line-length = 223 +target-version = "py37" + +[tool.ruff.mccabe] +max-complexity = 15 + +[tool.ruff.pylint] +max-args = 5 +max-branches = 15 +max-returns = 7 +# max-statements = 50 \ No newline at end of file From bf11c08d10a26b365dca29660ea568b3f33d8238 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 12 Apr 2023 01:40:53 +0200 Subject: [PATCH 2/3] ci: replace flake8 with ruff --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 69c5ae6d1..de78ecd68 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,4 +49,4 @@ max-complexity = 15 max-args = 5 max-branches = 15 max-returns = 7 -# max-statements = 50 \ No newline at end of file +max-statements = 50 From 00f9f6e3a634f91793f895e2c79ed6bdcd5d3ff0 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 12 Apr 2023 03:29:55 +0200 Subject: [PATCH 3/3] Update .github/workflows/lint_python.yml Co-authored-by: Nick Schonning --- .github/workflows/lint_python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index d9ab9469e..5b5a5f480 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -1,5 +1,5 @@ # https://beta.ruff.rs -name: lint_python +name: Lint Python on: push: branches: [main]