1
1
# The MIT License (MIT)
2
2
#
3
3
# Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
4
+ # 2019 Michael Schroeder
4
5
#
5
6
# Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
# of this software and associated documentation files (the "Software"), to deal
32
33
from adabot import github_requests as github
33
34
from adabot import travis_requests as travis
34
35
from adabot import pypi_requests as pypi
35
- from adabot .lib import circuitpython_library_validators
36
+ from adabot .lib import circuitpython_library_validators as cirpy_lib_vals
36
37
from adabot .lib .common_funcs import *
37
38
38
39
# Setup ArgumentParser
93
94
# Functions to run on repositories to validate their state. By convention these
94
95
# return a list of string errors for the specified repository (a dictionary
95
96
# of Github API repository object state).
96
- default_validators = [vals for vals in inspect .getmembers (circuitpython_library_validators .library_validator ) if vals [0 ].startswith ("validate" )]
97
+ default_validators = [
98
+ vals for vals in inspect .getmembers (cirpy_lib_vals .library_validator )
99
+ if vals [0 ].startswith ("validate" )
100
+ ]
97
101
98
102
99
103
def run_library_checks (validators , bundle_submodules , latest_pylint , kw_args ):
@@ -139,7 +143,9 @@ def run_library_checks(validators, bundle_submodules, latest_pylint, kw_args):
139
143
since = datetime .datetime .now () - datetime .timedelta (days = 7 )
140
144
repos_by_error = {}
141
145
142
- validator = circuitpython_library_validators .library_validator (validators , bundle_submodules , latest_pylint , ** kw_args )
146
+ validator = cirpy_lib_vals .library_validator (validators ,
147
+ bundle_submodules ,
148
+ latest_pylint , ** kw_args )
143
149
for repo in repos :
144
150
if len (validators ) != 0 :
145
151
errors = validator .run_repo_validation (repo )
@@ -152,7 +158,7 @@ def run_library_checks(validators, bundle_submodules, latest_pylint, kw_args):
152
158
for error in errors :
153
159
if not isinstance (error , tuple ):
154
160
# check for an error occurring in the valiator module
155
- if error == circuitpython_library_validators .ERROR_OUTPUT_HANDLER :
161
+ if error == cirpy_lib_vals .ERROR_OUTPUT_HANDLER :
156
162
#print(errors, "repo output handler error:", validator.output_file_data)
157
163
output_handler (", " .join (validator .output_file_data ))
158
164
validator .output_file_data .clear ()
@@ -162,15 +168,18 @@ def run_library_checks(validators, bundle_submodules, latest_pylint, kw_args):
162
168
else :
163
169
if error [0 ] not in repos_by_error :
164
170
repos_by_error [error [0 ]] = []
165
- repos_by_error [error [0 ]].append ("{0} ({1} days)" .format (repo ["html_url" ], error [1 ]))
171
+ repos_by_error [error [0 ]].append (
172
+ "{0} ({1} days)" .format (repo ["html_url" ], error [1 ])
173
+ )
166
174
insights = lib_insights
167
- if repo ["name" ] == "circuitpython" and repo ["owner" ]["login" ] == "adafruit" :
168
- insights = core_insights
175
+ if (repo ["name" ] == "circuitpython" and
176
+ repo ["owner" ]["login" ] == "adafruit" ):
177
+ insights = core_insights
169
178
errors = validator .gather_insights (repo , insights , since )
170
179
if errors :
171
180
print ("insights error" )
172
181
for error in errors :
173
- if error == circuitpython_library_validators .ERROR_OUTPUT_HANDLER :
182
+ if error == cirpy_lib_vals .ERROR_OUTPUT_HANDLER :
174
183
output_handler (", " .join (validator .output_file_data ))
175
184
validator .output_file_data .clear ()
176
185
@@ -194,7 +203,8 @@ def run_library_checks(validators, bundle_submodules, latest_pylint, kw_args):
194
203
ms_count = 0
195
204
for milestone in sorted (core_insights ["milestones" ].keys ()):
196
205
ms_count += core_insights ["milestones" ][milestone ]
197
- output_handler (" * {0}: {1} open issues" .format (milestone , core_insights ["milestones" ][milestone ]))
206
+ output_handler (" * {0}: {1} open issues" .format (milestone ,
207
+ core_insights ["milestones" ][milestone ]))
198
208
output_handler (" * {} issues not assigned a milestone" .format (len (core_insights ["open_issues" ]) - ms_count ))
199
209
output_handler ()
200
210
print_circuitpython_download_stats ()
@@ -212,12 +222,14 @@ def run_library_checks(validators, bundle_submodules, latest_pylint, kw_args):
212
222
if len (validators ) != 0 :
213
223
lib_repos = []
214
224
for repo in repos :
215
- if repo ["owner" ]["login" ] == "adafruit" and repo ["name" ].startswith ("Adafruit_CircuitPython" ):
216
- lib_repos .append (repo )
225
+ if (repo ["owner" ]["login" ] == "adafruit" and
226
+ repo ["name" ].startswith ("Adafruit_CircuitPython" )):
227
+ lib_repos .append (repo )
217
228
218
- output_handler ("{} out of {} repos need work." .format (need_work , len (lib_repos )))
229
+ output_handler ("{} out of {} repos need work." .format (need_work ,
230
+ len (lib_repos )))
219
231
220
- list_repos_for_errors = [circuitpython_library_validators .ERROR_NOT_IN_BUNDLE ]
232
+ list_repos_for_errors = [cirpy_lib_vals .ERROR_NOT_IN_BUNDLE ]
221
233
output_handler ()
222
234
for error in sorted (repos_by_error ):
223
235
if not repos_by_error [error ]:
@@ -252,6 +264,17 @@ def print_circuitpython_download_stats():
252
264
by_both = {}
253
265
total = {}
254
266
267
+ asset_re = re .compile (
268
+ r"""
269
+ circuitpython\- # end of the prefix
270
+ (?P<board>.+)\- # board name
271
+ (?P<lang>.+)\- # language
272
+ (\d\.\d\.\d.*) # version
273
+ \.(?=uf2|bin|hex) # file extension
274
+ """ ,
275
+ re .I | re .X
276
+ )
277
+
255
278
for release in releases :
256
279
if not found_unstable and not release ["draft" ] and release ["prerelease" ]:
257
280
found_unstable = True
@@ -266,11 +289,12 @@ def print_circuitpython_download_stats():
266
289
if not asset ["name" ].startswith ("adafruit-circuitpython" ):
267
290
continue
268
291
count = asset ["download_count" ]
269
- parts = asset ["name" ].split ("-" )
270
- board = parts [2 ]
271
- language = "en_US"
272
- if len (parts ) == 6 :
273
- language = parts [3 ]
292
+ info_re = asset_re .search (asset ["name" ])
293
+ if not info_re :
294
+ print ("Skipping stats for '{}'" .format (asset ["name" ]))
295
+ continue
296
+ board = info_re .group ("board" )
297
+ language = info_re .group ("lang" )
274
298
if language not in by_language :
275
299
by_language [language ] = {release ["tag_name" ]: 0 }
276
300
if release ["tag_name" ] not in by_language [language ]:
@@ -378,9 +402,10 @@ def print_issue_overview(*insights):
378
402
379
403
if __name__ == "__main__" :
380
404
validator_kwarg_list = {}
381
- startup_message = ["Running CircuitPython Library checks..." ,
382
- "Report Date: {}" .format (datetime .datetime .now ().strftime ("%d %B %Y, %I:%M%p" ))
383
- ]
405
+ startup_message = [
406
+ "Running CircuitPython Library checks..." ,
407
+ "Report Date: {}" .format (datetime .datetime .now ().strftime ("%d %B %Y, %I:%M%p" ))
408
+ ]
384
409
cmd_line_args = cmd_line_parser .parse_args ()
385
410
386
411
error_depth = cmd_line_args .error_depth
@@ -408,9 +433,14 @@ def print_issue_overview(*insights):
408
433
raise KeyError
409
434
#print('{}'.format(func_name))
410
435
if "contents" not in func_name :
411
- validators .append ([val [1 ] for val in default_validators if func_name in val [0 ]][0 ])
436
+ validators .append (
437
+ [val [1 ] for val in default_validators if func_name in val [0 ]][0 ]
438
+ )
412
439
else :
413
- validators .insert (0 , [val [1 ] for val in default_validators if func_name in val [0 ]][0 ])
440
+ validators .insert (
441
+ 0 ,
442
+ [val [1 ] for val in default_validators if func_name in val [0 ]][0 ]
443
+ )
414
444
validator_names .append (func_name )
415
445
except KeyError :
416
446
#print(default_validators)
@@ -426,14 +456,17 @@ def print_issue_overview(*insights):
426
456
427
457
if "validate_contents" not in validator_names :
428
458
validator_kwarg_list ["validate_contents_quiet" ] = True
429
- validators .insert (0 , [val [1 ] for val in default_validators if "validate_contents" in val [0 ]][0 ])
459
+ validators .insert (
460
+ 0 , [val [1 ] for val in default_validators if "validate_contents" in val [0 ]][0 ]
461
+ )
430
462
431
463
try :
432
464
for message in startup_message :
433
465
output_handler (message )
434
466
output_handler ()
435
467
#print(validators)
436
- run_library_checks (validators , bundle_submodules , latest_pylint , validator_kwarg_list )
468
+ run_library_checks (validators , bundle_submodules , latest_pylint ,
469
+ validator_kwarg_list )
437
470
except :
438
471
if output_filename is not None :
439
472
exc_type , exc_val , exc_tb = sys .exc_info ()
0 commit comments