Skip to content

Commit 9b3e714

Browse files
committedAug 23, 2021
pylint_all: Use argparse for processing arguments
1 parent a39eb7a commit 9b3e714

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed
 

‎scripts/pylint_all.py

+27-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#! /usr/bin/env python3
22

33
"""
4-
Performs pylint on all python files in the project repo's {test,script,docs} directory recursively.
5-
6-
This script is meant to be run from the CI but can also be easily in local dev environment,
7-
where you can optionally pass `-d` as command line argument to let this script abort on first error.
4+
Runs pylint on all Python files in project directories known to contain Python scripts.
85
"""
96

7+
from argparse import ArgumentParser
108
from os import path, walk, system
11-
from sys import argv, exit as exitwith
9+
from sys import exit as exitwith
10+
from textwrap import dedent
1211

1312
PROJECT_ROOT = path.dirname(path.realpath(__file__))
1413
PYLINT_RCFILE = "{}/pylintrc".format(PROJECT_ROOT)
@@ -40,11 +39,29 @@ def pylint_all_filenames(dev_mode, rootdirs):
4039

4140
return len(failed), len(filenames)
4241

42+
43+
def parse_command_line():
44+
script_description = dedent("""
45+
Runs pylint on all Python files in project directories known to contain Python scripts.
46+
47+
This script is meant to be run from the CI but can also be easily used in the local dev
48+
environment.
49+
""")
50+
51+
parser = ArgumentParser(description=script_description)
52+
parser.add_argument(
53+
'-d', '--dev-mode',
54+
dest='dev_mode',
55+
default=False,
56+
action='store_true',
57+
help="Abort on first error."
58+
)
59+
return parser.parse_args()
60+
61+
4362
def main():
44-
""" Collects all python script root dirs and runs pylint on them. You can optionally
45-
pass `-d` as command line argument to let this script abort on first error. """
46-
dev_mode = len(argv) == 2 and argv[1] == "-d"
47-
failed_count, total_count = pylint_all_filenames(dev_mode, [
63+
options = parse_command_line()
64+
failed_count, total_count = pylint_all_filenames(options.dev_mode, [
4865
path.abspath(path.dirname(__file__) + "/../docs"),
4966
path.abspath(path.dirname(__file__) + "/../scripts"),
5067
path.abspath(path.dirname(__file__) + "/../test")])
@@ -53,5 +70,6 @@ def main():
5370
else:
5471
print("Successfully tested {} files.".format(total_count))
5572

73+
5674
if __name__ == "__main__":
5775
main()

0 commit comments

Comments
 (0)
Please sign in to comment.