-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathci_lint_runner.py
39 lines (31 loc) · 1.06 KB
/
ci_lint_runner.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
# Copyright The PFDL Contributors
#
# Licensed under the MIT License.
# For details on the licensing terms, see the LICENSE file.
# SPDX-License-Identifier: MIT
"""A simple script for running pylint programmatically inside the CI."""
# standard libraries
import sys
import subprocess
folder_path = sys.argv[1]
threshold = float(sys.argv[2])
args = "--rcfile=.pylintrc"
cmd = "pylint " + folder_path + " " + args
text = ""
try:
out = subprocess.run(
cmd, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
text = out.stdout.decode("utf-8")
except subprocess.CalledProcessError as err:
text = err.output.decode("utf-8")
search_str = "Your code has been rated at "
text = text[text.index(search_str) + len(search_str) : len(text)]
lint_score = float(text[0 : text.index("/")])
if lint_score < threshold:
message = f"Pylint check failed | Score: {lint_score} | Threshold: {threshold}"
print(message)
sys.exit(1)
message = f"Pylint check passed | Score: {lint_score} | Threshold: {threshold}"
print(message)
sys.exit(0)