-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #381 from tisnik/pr-check-for-python
PR check for Python sources
- Loading branch information
Showing
6 changed files
with
132 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.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 . | ||
|
||
shellcheck: ## Run shellcheck | ||
./shellcheck.sh | ||
|
||
help: ## Show this help screen | ||
@echo 'Usage: make <OPTIONS> ... <TARGETS>' | ||
@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 '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |