-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrun_pycodestyle.py
53 lines (42 loc) · 2.1 KB
/
run_pycodestyle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Copyright © 2020 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)."""
# Link to generated documentation for this script:
# <https://redhatinsights.github.io/insights-results-aggregator-utils/packages/run_pycodestyle.html>
from pathlib import Path
from sys import exit
import pycodestyle
def main() -> None:
"""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"))
# 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()