This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
forked from orbingol/NURBS-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_pydocstyle.py
119 lines (99 loc) · 3.77 KB
/
code_pydocstyle.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import os
import random
from datetime import date, timedelta
from glob import glob
import pydocstyle
print(f"Pydocstyle version: {pydocstyle.__version__}")
file_list = filter(
lambda z: not z.endswith("__init__.py"),
[y for x in os.walk("./nurbs") for y in glob(os.path.join(x[0], "*.py"))],
)
UNWATCHED_ERRORS = [
# Do not watch these errors
"D100",
"D104",
"D105",
"D107",
"D200",
"D202",
"D203",
"D204",
"D206",
"D210",
"D212",
"D301",
"D302",
"D401",
"D402",
"D407",
"D408",
"D409",
"D412",
"D415",
"D418",
]
MAX_ERROR_BY_TYPE = {
# If the error code is not in this dict, then there is no tolerance on the error.
# http://www.pydocstyle.org/en/stable/error_codes.html
"D101": 53,
"D102": 11,
"D103": 2,
"D205": 39,
"D213": 484,
"D400": 92,
"D405": 5,
"D413": 65,
"D417": 2,
}
error_detected = False
error_over_ratchet_limit = False
EFFECTIVE_DATE = date(2023, 7, 27)
DAYS_TIME_EFFECT_LIMITING = 21
limit_time_effect = False
if os.environ.get("DRONE_BRANCH", "") in ["master", "testing"]:
limit_time_effect = True
print(f"Limiting time effect of 21 days as we are on {os.environ['DRONE_BRANCH']}")
if os.environ.get("DRONE_TARGET_BRANCH", "") in ["master", "testing"]:
limit_time_effect = True
print(f"Limiting time effect of 21 days as we are targetting {os.environ['DRONE_TARGET_BRANCH']}")
if limit_time_effect:
EFFECTIVE_DATE += timedelta(days=21)
today = date.today()
weekly_decrease = 5
time_decrease = int((today - EFFECTIVE_DATE).days / 7.0 * weekly_decrease)
ratchet_limit = 5 + int(DAYS_TIME_EFFECT_LIMITING / 7.0 * weekly_decrease)
code_to_errors = {}
for error in pydocstyle.check(file_list, ignore=UNWATCHED_ERRORS):
code_to_errors.setdefault(error.code, [])
code_to_errors[error.code].append(error)
code_to_number = {code: len(errors) for code, errors in code_to_errors.items()}
for error_code, number_errors in code_to_number.items():
if error_code not in UNWATCHED_ERRORS:
max_errors = max(MAX_ERROR_BY_TYPE.get(error_code, 0) - time_decrease, 0)
if number_errors > max_errors:
# The number of errors is above the maximum acceptable
error_detected = True
print(f"\nFix some {error_code} errors: {number_errors}/{max_errors}")
errors = code_to_errors[error_code]
errors_to_show = sorted(random.sample(errors, min(30, len(errors))), key=lambda m: (m.filename, m.line))
for error in errors_to_show:
print(f"{error.filename} line {error.line}: {error.message}")
elif max_errors - ratchet_limit <= number_errors < max_errors:
# The number of errors is below the maximum acceptable, but above the ratchet_limit:
# the user can reduce the maximum number of errors
print(
f"\nYou can adjust number of admissible errors (in code_pydocstyle.py) of {error_code} to {number_errors + time_decrease} (actual {max_errors + time_decrease})"
)
elif number_errors < max_errors - ratchet_limit:
# The number of errors is below the maximum acceptable, and below the ratchet_limit:
# the user must reduce the maximum number of errors
error_over_ratchet_limit = True
print(
f"\nYou MUST adjust number of admissible errors (in code_pydocstyle.py) of {error_code} to {number_errors + time_decrease} (actual {max_errors + time_decrease})"
)
if error_detected:
raise RuntimeError("Too many errors\nRun pydocstyle volmdlr to get the errors")
if error_over_ratchet_limit:
raise RuntimeError(
"Please lower the error limits in code_pydocstyle.py MAX_ERROR_BY_TYPE according to warnings above"
)