11# The MIT License (MIT)
22#
33# Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
4+ # 2019 Michael Schroeder
45#
56# Permission is hereby granted, free of charge, to any person obtaining a copy
67# of this software and associated documentation files (the "Software"), to deal
3233from adabot import github_requests as github
3334from adabot import travis_requests as travis
3435from 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
3637from adabot .lib .common_funcs import *
3738
3839# Setup ArgumentParser
9394# Functions to run on repositories to validate their state. By convention these
9495# return a list of string errors for the specified repository (a dictionary
9596# 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+ ]
97101
98102
99103def 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):
139143 since = datetime .datetime .now () - datetime .timedelta (days = 7 )
140144 repos_by_error = {}
141145
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 )
143149 for repo in repos :
144150 if len (validators ) != 0 :
145151 errors = validator .run_repo_validation (repo )
@@ -152,7 +158,7 @@ def run_library_checks(validators, bundle_submodules, latest_pylint, kw_args):
152158 for error in errors :
153159 if not isinstance (error , tuple ):
154160 # 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 :
156162 #print(errors, "repo output handler error:", validator.output_file_data)
157163 output_handler (", " .join (validator .output_file_data ))
158164 validator .output_file_data .clear ()
@@ -162,15 +168,18 @@ def run_library_checks(validators, bundle_submodules, latest_pylint, kw_args):
162168 else :
163169 if error [0 ] not in repos_by_error :
164170 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+ )
166174 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
169178 errors = validator .gather_insights (repo , insights , since )
170179 if errors :
171180 print ("insights error" )
172181 for error in errors :
173- if error == circuitpython_library_validators .ERROR_OUTPUT_HANDLER :
182+ if error == cirpy_lib_vals .ERROR_OUTPUT_HANDLER :
174183 output_handler (", " .join (validator .output_file_data ))
175184 validator .output_file_data .clear ()
176185
@@ -194,7 +203,8 @@ def run_library_checks(validators, bundle_submodules, latest_pylint, kw_args):
194203 ms_count = 0
195204 for milestone in sorted (core_insights ["milestones" ].keys ()):
196205 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 ]))
198208 output_handler (" * {} issues not assigned a milestone" .format (len (core_insights ["open_issues" ]) - ms_count ))
199209 output_handler ()
200210 print_circuitpython_download_stats ()
@@ -212,12 +222,14 @@ def run_library_checks(validators, bundle_submodules, latest_pylint, kw_args):
212222 if len (validators ) != 0 :
213223 lib_repos = []
214224 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 )
217228
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 )))
219231
220- list_repos_for_errors = [circuitpython_library_validators .ERROR_NOT_IN_BUNDLE ]
232+ list_repos_for_errors = [cirpy_lib_vals .ERROR_NOT_IN_BUNDLE ]
221233 output_handler ()
222234 for error in sorted (repos_by_error ):
223235 if not repos_by_error [error ]:
@@ -252,6 +264,17 @@ def print_circuitpython_download_stats():
252264 by_both = {}
253265 total = {}
254266
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+
255278 for release in releases :
256279 if not found_unstable and not release ["draft" ] and release ["prerelease" ]:
257280 found_unstable = True
@@ -266,11 +289,12 @@ def print_circuitpython_download_stats():
266289 if not asset ["name" ].startswith ("adafruit-circuitpython" ):
267290 continue
268291 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" )
274298 if language not in by_language :
275299 by_language [language ] = {release ["tag_name" ]: 0 }
276300 if release ["tag_name" ] not in by_language [language ]:
@@ -378,9 +402,10 @@ def print_issue_overview(*insights):
378402
379403if __name__ == "__main__" :
380404 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+ ]
384409 cmd_line_args = cmd_line_parser .parse_args ()
385410
386411 error_depth = cmd_line_args .error_depth
@@ -408,9 +433,14 @@ def print_issue_overview(*insights):
408433 raise KeyError
409434 #print('{}'.format(func_name))
410435 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+ )
412439 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+ )
414444 validator_names .append (func_name )
415445 except KeyError :
416446 #print(default_validators)
@@ -426,14 +456,17 @@ def print_issue_overview(*insights):
426456
427457 if "validate_contents" not in validator_names :
428458 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+ )
430462
431463 try :
432464 for message in startup_message :
433465 output_handler (message )
434466 output_handler ()
435467 #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 )
437470 except :
438471 if output_filename is not None :
439472 exc_type , exc_val , exc_tb = sys .exc_info ()
0 commit comments