From 2eb01a86004956952200eb27c49be6186688e1e9 Mon Sep 17 00:00:00 2001 From: Ondřej Nosek Date: Nov 26 2025 01:13:19 +0000 Subject: Use ruff code checker instead of bandit In the testing CI (Jenkins), stop using bandit in favour of ruff. Bandit is deprecated in the latest Fedora release (F43). Added an environment for code coverage analysis. JIRA: RHELCMP-14986 Signed-off-by: Ondřej Nosek --- diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 84fb911..20c3cfa 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,11 +32,13 @@ You can increase the chance of your Pull Request being merged by: * having good test coverage * writing documentation * following PEP 8 for code formatting -* don't have [bandit][bandit] complains +* ~~don't have [bandit][bandit] complains~~ (not active in the Jenkins) +* don't have [ruff][ruff] complains (some categories are currently excluded in the configuration) * writing [a good commit message][commit-message] [commit-message]: https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html [bandit]: https://bandit.readthedocs.io +[ruff]: https://github.com/astral-sh/ruff [places]: diff --git a/Jenkinsfile b/Jenkinsfile index 51833be..b972475 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -52,7 +52,7 @@ git merge --no-ff "proposed/$params.BRANCH" -m "Merge PR" git clone https://pagure.io/rpkg.git # docker image will contain ENV: PYTHONPATH=./rpkg -podman run --rm -v .:/src:Z quay.io/exd-guild-source-tools/fedpkg-test:latest tox -e py36,py39,py312,py313,flake8,bandit --workdir /tmp/tox ${TOX_POSARGS} +podman run --rm -v .:/src:Z quay.io/exd-guild-source-tools/fedpkg-test:latest tox -e py36,py39,py312,py313,py314,flake8,ruff --workdir /tmp/tox ${TOX_POSARGS} """ sh "cat job.sh" sh "ssh -o StrictHostKeyChecking=no root@$hostname mkdir $remote_dir" diff --git a/fedpkg/__main__.py b/fedpkg/__main__.py index 1a2c3f8..fdc9c01 100644 --- a/fedpkg/__main__.py +++ b/fedpkg/__main__.py @@ -44,7 +44,7 @@ def main(): # Make sure we have a sane config file if not os.path.exists(args.config) and \ - not other[-1] in ['--help', '-h', 'help']: + other[-1] not in ['--help', '-h', 'help']: sys.stderr.write('Invalid config file %s\n' % args.config) sys.exit(1) diff --git a/jenkins_test.dockerfile b/jenkins_test.dockerfile index 7970925..62c7371 100644 --- a/jenkins_test.dockerfile +++ b/jenkins_test.dockerfile @@ -1,4 +1,4 @@ -FROM fedora:41 +FROM fedora:42 LABEL \ name="fedpkg test" \ description="Run tests using tox with Python 3" \ @@ -16,11 +16,11 @@ RUN dnf -y update && dnf -y install \ openssl-devel \ make \ git \ - bandit + ruff RUN dnf clean all WORKDIR /src ENV PYTHONPATH "${PYTHONPATH}:./rpkg" -CMD ["tox", "-e", "py36,py39,py312,py313,py314,flake8,bandit"] +CMD ["tox", "-e", "py36,py39,py312,py313,py314,flake8,ruff"] diff --git a/pyproject.toml b/pyproject.toml index 3fc787f..e6af427 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -85,3 +85,36 @@ packages = [ "conf/etc/rpkg/fedpkg-stage.conf" = "etc/rpkg/fedpkg-stage.conf" "conf/etc/rpkg/fedpkg.conf" = "etc/rpkg/fedpkg.conf" +[tool.ruff] +line-length = 100 + +[tool.ruff.lint] +select = [ + # pycodestyle + "E", + # pycodestyle warnings + "W", + # Pyflakes + "F", + # pyupgrade + #"UP", + # flake8-bugbear + #"B", + # flake8-simplify + #"SIM", + # isort + #"I", + # flake8-bandit + "S", + # flake8-type-checking + #"TCH", + # flake8-comprehensions + #"C4", + # pep8-naming + #"N", + # flake8-annotations + #"ANN", + # flake8-pytest-style + #"PT", +] +ignore = ["S101", "S603", "S607"] diff --git a/tox.ini b/tox.ini index 3450087..982e7e8 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,6 @@ [tox] -envlist = py36,py39,py312,py313,flake8,doc,bandit +envlist = py36,py39,py312,py313,py314,flake8,doc,bandit,coverage,ruff +basepython = {env:TOXPYTHON:python3} [testenv] sitepackages=false @@ -8,9 +9,6 @@ basepython= py39: {env:TOXPYTHON:python3.9} py312: {env:TOXPYTHON:python3.12} py313: {env:TOXPYTHON:python3.13} - flake8: {env:TOXPYTHON:python3.6} - doc: {env:TOXPYTHON:python3} - bandit: {env:TOXPYTHON:python3} deps = -r{toxinidir}/requirements.txt @@ -46,3 +44,21 @@ skip_install = true deps = bandit commands = bandit -r -ll fedpkg/ test/ ignore_outcome = False + +[testenv:coverage] +deps = + {[testenv]deps} + pytest-cov +skip_install = True +commands = + python -m pytest --cov=fedpkg --cov-report=term --cov-report=html {posargs} + +[coverage:run] +source = fedpkg +omit = + +[testenv:ruff] +deps = ruff +skip_install = True +commands = + python -m ruff check fedpkg/ test/