Skip to content

Commit d2f128b

Browse files
authored
Merge pull request #83 from sommersoft/lib_report_prune_juice
Prune Issue Info From Report
2 parents 430d8ab + ef40f42 commit d2f128b

File tree

2 files changed

+103
-77
lines changed

2 files changed

+103
-77
lines changed

adabot/circuitpython_libraries.py

Lines changed: 102 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,45 @@
3636
from adabot.lib.common_funcs import *
3737

3838
# Setup ArgumentParser
39-
cmd_line_parser = argparse.ArgumentParser(description="Adabot utility for CircuitPython Libraries.",
40-
prog="Adabot CircuitPython Libraries Utility")
41-
cmd_line_parser.add_argument("-o", "--output_file", help="Output log to the filename provided.",
42-
metavar="<OUTPUT FILENAME>", dest="output_file")
43-
cmd_line_parser.add_argument("-p", "--print", help="Set the level of verbosity printed to the command prompt."
44-
" Zero is off; One is on (default).", type=int, default=1, dest="verbose", choices=[0,1])
45-
cmd_line_parser.add_argument("-e", "--error_depth", help="Set the threshold for outputting an error list. Default is 5.",
46-
dest="error_depth", type=int, default=5, metavar="n")
47-
cmd_line_parser.add_argument("-t", "--token", help="Prompt for a GitHub token to use for activating Travis.",
48-
dest="gh_token", action="store_true")
49-
cmd_line_parser.add_argument("-v", "--validator", help="Run only the validator(s) supplied in a string.", dest="validator",
50-
metavar='"validator1, validator2, ..."')
39+
cmd_line_parser = argparse.ArgumentParser(
40+
description="Adabot utility for CircuitPython Libraries.",
41+
prog="Adabot CircuitPython Libraries Utility"
42+
)
43+
cmd_line_parser.add_argument(
44+
"-o", "--output_file",
45+
help="Output log to the filename provided.",
46+
metavar="<OUTPUT FILENAME>",
47+
dest="output_file"
48+
)
49+
cmd_line_parser.add_argument(
50+
"-p", "--print",
51+
help="Set the level of verbosity printed to the command prompt."
52+
" Zero is off; One is on (default).",
53+
type=int,
54+
default=1,
55+
dest="verbose",
56+
choices=[0,1]
57+
)
58+
cmd_line_parser.add_argument(
59+
"-e", "--error_depth",
60+
help="Set the threshold for outputting an error list. Default is 5.",
61+
dest="error_depth",
62+
type=int,
63+
default=5,
64+
metavar="n"
65+
)
66+
cmd_line_parser.add_argument(
67+
"-t", "--token",
68+
help="Prompt for a GitHub token to use for activating Travis.",
69+
dest="gh_token",
70+
action="store_true"
71+
)
72+
cmd_line_parser.add_argument(
73+
"-v", "--validator",
74+
help="Run validators with 'all', or only the validator(s) supplied in a string.",
75+
dest="validator",
76+
metavar='all OR "validator1, validator2, ..."'
77+
)
5178

5279
# Define global state shared by the functions above:
5380
# Submodules inside the bundle (result of get_bundle_submodules)
@@ -114,27 +141,28 @@ def run_library_checks(validators, bundle_submodules, latest_pylint, kw_args):
114141

115142
validator = circuitpython_library_validators.library_validator(validators, bundle_submodules, latest_pylint, **kw_args)
116143
for repo in repos:
117-
errors = validator.run_repo_validation(repo)
118-
if errors:
119-
need_work += 1
120-
repo_needs_work.append(repo)
121-
# print(repo["full_name"])
122-
# print("\n".join(errors))
123-
# print()
124-
for error in errors:
125-
if not isinstance(error, tuple):
126-
# check for an error occurring in the valiator module
127-
if error == circuitpython_library_validators.ERROR_OUTPUT_HANDLER:
128-
#print(errors, "repo output handler error:", validator.output_file_data)
129-
output_handler(", ".join(validator.output_file_data))
130-
validator.output_file_data.clear()
131-
if error not in repos_by_error:
132-
repos_by_error[error] = []
133-
repos_by_error[error].append(repo["html_url"])
134-
else:
135-
if error[0] not in repos_by_error:
136-
repos_by_error[error[0]] = []
137-
repos_by_error[error[0]].append("{0} ({1} days)".format(repo["html_url"], error[1]))
144+
if len(validators) != 0:
145+
errors = validator.run_repo_validation(repo)
146+
if errors:
147+
need_work += 1
148+
repo_needs_work.append(repo)
149+
# print(repo["full_name"])
150+
# print("\n".join(errors))
151+
# print()
152+
for error in errors:
153+
if not isinstance(error, tuple):
154+
# check for an error occurring in the valiator module
155+
if error == circuitpython_library_validators.ERROR_OUTPUT_HANDLER:
156+
#print(errors, "repo output handler error:", validator.output_file_data)
157+
output_handler(", ".join(validator.output_file_data))
158+
validator.output_file_data.clear()
159+
if error not in repos_by_error:
160+
repos_by_error[error] = []
161+
repos_by_error[error].append(repo["html_url"])
162+
else:
163+
if error[0] not in repos_by_error:
164+
repos_by_error[error[0]] = []
165+
repos_by_error[error[0]].append("{0} ({1} days)".format(repo["html_url"], error[1]))
138166
insights = lib_insights
139167
if repo["name"] == "circuitpython" and repo["owner"]["login"] == "adafruit":
140168
insights = core_insights
@@ -179,27 +207,26 @@ def run_library_checks(validators, bundle_submodules, latest_pylint, kw_args):
179207
output_handler(" * {}".format(pr))
180208
print_issue_overview(lib_insights)
181209
output_handler("* {} open issues".format(len(lib_insights["open_issues"])))
182-
for issue in lib_insights["open_issues"]:
183-
output_handler(" * {}".format(issue))
210+
output_handler(" * https://circuitpython.org/libraries/contributing")
184211

185-
lib_repos = []
186-
for repo in repos:
187-
if repo["owner"]["login"] == "adafruit" and repo["name"].startswith("Adafruit_CircuitPython"):
188-
lib_repos.append(repo)
212+
if len(validators) != 0:
213+
lib_repos = []
214+
for repo in repos:
215+
if repo["owner"]["login"] == "adafruit" and repo["name"].startswith("Adafruit_CircuitPython"):
216+
lib_repos.append(repo)
189217

190-
# print("- [ ] [{0}](https://github.com/{1})".format(repo["name"], repo["full_name"]))
191-
output_handler("{} out of {} repos need work.".format(need_work, len(lib_repos)))
218+
output_handler("{} out of {} repos need work.".format(need_work, len(lib_repos)))
192219

193-
list_repos_for_errors = [circuitpython_library_validators.ERROR_NOT_IN_BUNDLE]
194-
output_handler()
195-
for error in sorted(repos_by_error):
196-
if not repos_by_error[error]:
197-
continue
220+
list_repos_for_errors = [circuitpython_library_validators.ERROR_NOT_IN_BUNDLE]
198221
output_handler()
199-
error_count = len(repos_by_error[error])
200-
output_handler("{} - {}".format(error, error_count))
201-
if error_count <= error_depth or error in list_repos_for_errors:
202-
output_handler("\n".join([" * " + x for x in repos_by_error[error]]))
222+
for error in sorted(repos_by_error):
223+
if not repos_by_error[error]:
224+
continue
225+
output_handler()
226+
error_count = len(repos_by_error[error])
227+
output_handler("{} - {}".format(error, error_count))
228+
if error_count <= error_depth or error in list_repos_for_errors:
229+
output_handler("\n".join([" * " + x for x in repos_by_error[error]]))
203230

204231
def output_handler(message="", quiet=False):
205232
"""Handles message output to prompt/file for print_*() functions."""
@@ -369,38 +396,37 @@ def print_issue_overview(*insights):
369396
output_filename = cmd_line_args.output_file
370397
startup_message.append(" - Report output will be saved to: {}".format(output_filename))
371398

372-
validators = [val_funcs[1] for val_funcs in default_validators]
399+
validators = []
373400
if cmd_line_args.validator:
374-
validators = []
375-
validator_names = []
376-
for func in cmd_line_args.validator.split(","):
377-
func_name = func.strip()
378-
try:
379-
if not func_name.startswith("validate"):
380-
#raise KeyError
381-
print('{}'.format(func_name))
382-
if "contents" not in func_name:
383-
validators.append([val[1] for val in default_validators if func_name in val[0]][0])
384-
else:
385-
validators.insert(0, [val[1] for val in default_validators if func_name in val[0]][0])
386-
validator_names.append(func_name)
387-
except KeyError:
388-
#print(", ".join([vals for vals in sys.modules[__name__].__dict__["circuitpython_library_validators"]]))
389-
#print(sys.modules[__name__].__dict__["circuitpython_library_validators"].__dict__["library_validator"].__dict__)
390-
print(default_validators)
391-
output_handler("Error: '{0}' is not an available validator.\n" \
392-
"Available validators are: {1}".format(func.strip(),
393-
", ".join([val[0] for val in default_validators])))
394-
sys.exit()
395-
396-
startup_message.append(" - Only these selected validators will run: {}".format(", ".join(validator_names)))
401+
if cmd_line_args.validator != "all":
402+
validators = []
403+
for func in cmd_line_args.validator.split(","):
404+
func_name = func.strip()
405+
try:
406+
if not func_name.startswith("validate"):
407+
raise KeyError
408+
#print('{}'.format(func_name))
409+
if "contents" not in func_name:
410+
validators.append([val[1] for val in default_validators if func_name in val[0]][0])
411+
else:
412+
validators.insert(0, [val[1] for val in default_validators if func_name in val[0]][0])
413+
validator_names.append(func_name)
414+
except KeyError:
415+
#print(default_validators)
416+
output_handler("Error: '{0}' is not an available validator.\n" \
417+
"Available validators are: {1}".format(func.strip(),
418+
", ".join([val[0] for val in default_validators])))
419+
sys.exit()
420+
else:
421+
validators = [val_funcs[1] for val_funcs in default_validators]
422+
validator_names = [val_names[0] for val_names in default_validators]
423+
424+
startup_message.append(" - These validators will run: {}".format(", ".join(validator_names)))
397425

398426
if "validate_contents" not in validators:
399427
validator_kwarg_list["validate_contents_quiet"] = True
400428
validators.insert(0, [val[1] for val in default_validators if "validate_contents" in val[0]][0])
401429

402-
#validator_kwarg_list["validators"] = validators
403-
404430
try:
405431
for message in startup_message:
406432
output_handler(message)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ idna==2.6
44
redis==2.10.6
55
requests==2.20.0
66
sh==1.12.14
7-
urllib3>=1.24
7+
urllib3==1.24

0 commit comments

Comments
 (0)