From ba689af2293b838ce3f9b78a485461e732ffa786 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Fri, 8 Dec 2023 12:05:55 +0100 Subject: [PATCH 1/7] PR check for Python sources --- .github/workflows/pr_approval.yaml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/pr_approval.yaml diff --git a/.github/workflows/pr_approval.yaml b/.github/workflows/pr_approval.yaml new file mode 100644 index 0000000..9ed8893 --- /dev/null +++ b/.github/workflows/pr_approval.yaml @@ -0,0 +1,30 @@ +name: Pytest + +on: + - push + - pull_request + +jobs: + pytest: + runs-on: ubuntu-20.04 + strategy: + matrix: + python-version: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - run: pip install --upgrade setuptools + - run: pip install --upgrade wheel + - run: pip install pycodestyle + - run: pip install pydocstyle + - name: Style checks + run: make style + - name: Docstrings checks + run: make doc-check From 8f298866e1c3b3c8e704acc8b2d440f21f2a240e Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Fri, 8 Dec 2023 12:07:28 +0100 Subject: [PATCH 2/7] Get rid of TravisCI --- .travis.yml | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index bce1ae2..0000000 --- a/.travis.yml +++ /dev/null @@ -1,20 +0,0 @@ -dist: jammy -language: python -python: - - "3.7" - - "3.8" - - "3.9" - - "3.10-dev" - - "3.11-dev" - # - "nightly" # nightly build -addons: - apt: - packages: - - libsnappy-dev -# Pycodestyle part -# needed to work correctly with Python 3 shebang -env: SKIP_INTERPRETER=true -install: - - pip install pycodestyle -script: - - pycodestyle **/*.py From 7aad2769f2e6189ec712e5a6d9e6c890f218c3cd Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Fri, 8 Dec 2023 12:08:20 +0100 Subject: [PATCH 3/7] Makefile --- Makefile | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c221bc4 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +.PHONY: style code-style + +style: code-style docs-style shellcheck ## Perform all style checks + +code-style: ## Check code style for all Python sources from this repository + python3 tools/run_pycodestyle.py + +ruff: ## Run Ruff linter + ruff . + +docs-style: ## Check documentation strings in all Python sources from this repository + pydocstyle . + +help: ## Show this help screen + @echo 'Usage: make ... ' + @echo '' + @echo 'Available targets are:' + @echo '' + @grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \ + awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-35s\033[0m %s\n", $$1, $$2}' + @echo '' From a49fe45bddc435d7ab74f0145add7e8bd63c9e4a Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Fri, 8 Dec 2023 12:09:14 +0100 Subject: [PATCH 4/7] Code style checker --- tools/run_pycodestyle.py | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tools/run_pycodestyle.py diff --git a/tools/run_pycodestyle.py b/tools/run_pycodestyle.py new file mode 100644 index 0000000..317ccbc --- /dev/null +++ b/tools/run_pycodestyle.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 + +# Copyright © 2020, 2021, 2022 Pavel Tisnovsky +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Simple checker of all Python sources in the given directory (usually repository).""" + +from pathlib import Path +from sys import exit +import pycodestyle + + +def main(): + """Run pydocstyle checker against all Python sources in the given directory.""" + # Find all files in current directory and subdirectories with '*.py' extension. + # Files are found recursivelly in all subdirectories as well. + files = list(Path(".").rglob("*.py")) + files = [f for f in files if not str(f).startswith("venv/")] + print("Files to check:") + print("\n".join(str(f) for f in files)) + print("\nChecks:") + + # Setup the module to check style of Python sources. We (usually) already + # have global configuration file 'setup.cfg' that can be used. Also verbose + # mode would be useful for our purposes, so we set `quiet` to `False` to + # enable verbose output. + style = pycodestyle.StyleGuide(quiet=False, config_file="setup.cfg") + + # Check the style for all Python sources found in current directory and all + # subdirectories too. All detected issues are displayed in the meantime. + result = style.check_files(files) + + # Print number of errors found at the end of check. + print("Total errors:", result.total_errors) + + # If any error is found, return with exit code check to non-zero value. + if result.total_errors > 0: + exit(1) + # Default exit code is 0 == success + + +# If this script is started from command line, run the `main` function which +# represents entry point to the processing. +if __name__ == "__main__": + main() From 529a2e12a745c247daddcf521fc60561a5be9031 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Fri, 8 Dec 2023 12:16:58 +0100 Subject: [PATCH 5/7] Updated pydocstyle setup --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 027bc1a..4bc1eb0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,7 +2,7 @@ max-line-length = 100 [pydocstyle] -ignore = D301, D212, D203 +ignore = D301, D211, D212, D213, D203 [metadata] name = aggregator-utils From 9f4607565c2a37b26d02a31bc306c503ff9796c1 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Fri, 8 Dec 2023 12:18:02 +0100 Subject: [PATCH 6/7] Added shellcheck --- Makefile | 3 +++ shellcheck.sh | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100755 shellcheck.sh diff --git a/Makefile b/Makefile index c221bc4..0aaaac3 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,9 @@ ruff: ## Run Ruff linter docs-style: ## Check documentation strings in all Python sources from this repository pydocstyle . +shellcheck: ## Run shellcheck + ./shellcheck.sh + help: ## Show this help screen @echo 'Usage: make ... ' @echo '' diff --git a/shellcheck.sh b/shellcheck.sh new file mode 100755 index 0000000..a146b64 --- /dev/null +++ b/shellcheck.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# Copyright 2020 Red Hat, Inc +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if ! command -v shellcheck > /dev/null 2>&1; then + scversion="stable" # or "v0.4.7", or "latest" + wget -qO- "https://github.com/koalaman/shellcheck/releases/download/${scversion?}/shellcheck-${scversion?}.linux.x86_64.tar.xz" | tar -xJv + shellcheck-stable/shellcheck --version + shellcheck-stable/shellcheck --exclude=SC2230 -- *.sh +else + shellcheck --exclude=SC2230 -- *.sh +fi From 674b94d8e0fa307eb9cc1d2c18c1ef2ce067a032 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Fri, 8 Dec 2023 12:20:29 +0100 Subject: [PATCH 7/7] Removed unused task --- .github/workflows/pr_approval.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/pr_approval.yaml b/.github/workflows/pr_approval.yaml index 9ed8893..544f796 100644 --- a/.github/workflows/pr_approval.yaml +++ b/.github/workflows/pr_approval.yaml @@ -26,5 +26,3 @@ jobs: - run: pip install pydocstyle - name: Style checks run: make style - - name: Docstrings checks - run: make doc-check