@@ -181,13 +181,15 @@ def validate_repo_state(self, repo):
181
181
errors .append (ERROR_MISSING_LICENSE )
182
182
if not repo ["permissions" ]["push" ]:
183
183
errors .append (ERROR_MISSING_LIBRARIANS )
184
- if not common_funcs .is_repo_in_bundle (full_repo ["clone_url" ], self .bundle_submodules ) and \
185
- not repo ["name" ] in BUNDLE_IGNORE_LIST : # Don't assume the bundle will
186
- # bundle itself and possibly
187
- # other repos.
188
- errors .append (ERROR_NOT_IN_BUNDLE )
189
- if "allow_squash_merge" not in full_repo or full_repo ["allow_squash_merge" ] or full_repo ["allow_rebase_merge" ]:
190
- errors .append (ERROR_ONLY_ALLOW_MERGES )
184
+ if (not common_funcs .is_repo_in_bundle (full_repo ["clone_url" ], self .bundle_submodules )
185
+ and not repo ["name" ] in BUNDLE_IGNORE_LIST ):
186
+ # Don't assume the bundle will bundle itself and possibly
187
+ # other repos.
188
+ errors .append (ERROR_NOT_IN_BUNDLE )
189
+ if ("allow_squash_merge" not in full_repo
190
+ or full_repo ["allow_squash_merge" ]
191
+ or full_repo ["allow_rebase_merge" ]):
192
+ errors .append (ERROR_ONLY_ALLOW_MERGES )
191
193
return errors
192
194
193
195
def validate_release_state (self , repo ):
@@ -204,7 +206,9 @@ def validate_release_state(self, repo):
204
206
if repo ["name" ] in BUNDLE_IGNORE_LIST :
205
207
return []
206
208
207
- repo_last_release = github .get ("/repos/" + repo ["full_name" ] + "/releases/latest" )
209
+ repo_last_release = github .get ("/repos/"
210
+ + repo ["full_name" ]
211
+ + "/releases/latest" )
208
212
if not repo_last_release .ok :
209
213
return [ERROR_GITHUB_NO_RELEASE ]
210
214
repo_release_json = repo_last_release .json ()
@@ -215,14 +219,27 @@ def validate_release_state(self, repo):
215
219
return [ERROR_GITHUB_NO_RELEASE ]
216
220
else :
217
221
# replace 'output_handler' with ERROR_OUTPUT_HANDLER
218
- self .output_file_data .append ("Error: retrieving latest release information failed on '{0}'. Information Received: {1}" .format (
219
- repo ["name" ], repo_release_json ["message" ]))
222
+ err_msg = [
223
+ "Error: retrieving latest release information failed on " ,
224
+ "'{}'. " format (repo ["name" ]),
225
+ "Information Received: " ,
226
+ "{}" .format (repo_release_json ["message" ])
227
+ ]
228
+ self .output_file_data .append ("" .join (err_msg ))
220
229
return [ERROR_OUTPUT_HANDLER ]
221
230
222
- compare_tags = github .get ("/repos/" + repo ["full_name" ] + "/compare/" + tag_name + "...master" )
231
+ compare_tags = github .get ("/repos/"
232
+ + repo ["full_name" ]
233
+ + "/compare/"
234
+ + tag_name
235
+ + "...master" )
223
236
if not compare_tags .ok :
224
237
# replace 'output_handler' with ERROR_OUTPUT_HANDLER
225
- self .output_file_data .append ("Error: failed to compare {0} 'master' to tag '{1}'" .format (repo ["name" ], tag_name ))
238
+ err_msg = [
239
+ "Error: failed to compare {} 'master' " .format (repo ["name" ]),
240
+ "to tag '{}'" .format (tag_name )
241
+ ]
242
+ self .output_file_data .append ("" .join (err_msg ))
226
243
return [ERROR_OUTPUT_HANDLER ]
227
244
compare_tags_json = compare_tags .json ()
228
245
if "status" in compare_tags_json :
@@ -239,22 +256,30 @@ def validate_release_state(self, repo):
239
256
# compare_tags_json["status"], compare_tags_json["ahead_by"],
240
257
# compare_tags_json["behind_by"], compare_tags_json["total_commits"], repo["full_name"]))
241
258
if date_diff .days > datetime .date .today ().max .day :
242
- return [(ERROR_GITHUB_COMMITS_SINCE_LAST_RELEASE_GTM , date_diff .days )]
259
+ return [(ERROR_GITHUB_COMMITS_SINCE_LAST_RELEASE_GTM ,
260
+ date_diff .days )]
243
261
elif date_diff .days <= datetime .date .today ().max .day :
244
262
if date_diff .days > 7 :
245
- return [(ERROR_GITHUB_COMMITS_SINCE_LAST_RELEASE_1M , date_diff .days )]
263
+ return [(ERROR_GITHUB_COMMITS_SINCE_LAST_RELEASE_1M ,
264
+ date_diff .days )]
246
265
else :
247
- return [(ERROR_GITHUB_COMMITS_SINCE_LAST_RELEASE_1W , date_diff .days )]
266
+ return [(ERROR_GITHUB_COMMITS_SINCE_LAST_RELEASE_1W ,
267
+ date_diff .days )]
248
268
elif "errors" in compare_tags_json :
249
269
# replace 'output_handler' with ERROR_OUTPUT_HANDLER
250
- self .output_file_data .append ("Error: comparing latest release to 'master' failed on '{0}'. Error Message: {1}" .format (
251
- repo ["name" ], compare_tags_json ["message" ]))
270
+ err_msg = [
271
+ "Error: comparing latest release to 'master' failed on " ,
272
+ "'{}'. " .format (repo ["name" ]),
273
+ "Error Message: {}" .format (compare_tags_json ["message" ])
274
+ ]
275
+ self .output_file_data .append ("" .join (err_msg ))
252
276
return [ERROR_OUTPUT_HANDLER ]
253
277
254
278
return []
255
279
256
280
def _validate_readme (self , repo , download_url ):
257
- # We use requests because file contents are hosted by githubusercontent.com, not the API domain.
281
+ # We use requests because file contents are hosted by
282
+ # githubusercontent.com, not the API domain.
258
283
contents = requests .get (download_url , timeout = 30 )
259
284
if not contents .ok :
260
285
return [ERROR_README_DOWNLOAD_FAILED ]
@@ -295,31 +320,40 @@ def _validate_py_for_u_modules(self, repo, download_url):
295
320
look for "import ___". If the "import u___" is
296
321
used with NO "import ____" generate an error.
297
322
"""
298
- # We use requests because file contents are hosted by githubusercontent.com, not the API domain.
323
+ # We use requests because file contents are hosted by
324
+ # githubusercontent.com, not the API domain.
299
325
contents = requests .get (download_url , timeout = 30 )
300
326
if not contents .ok :
301
327
return [ERROR_PYFILE_DOWNLOAD_FAILED ]
302
328
303
329
errors = []
304
330
305
331
lines = contents .text .split ("\n " )
306
- ustruct_lines = [l for l in lines if re .match (r"[\s]*import[\s][\s]*ustruct" , l )]
307
- struct_lines = [l for l in lines if re .match (r"[\s]*import[\s][\s]*struct" , l )]
332
+ ustruct_lines = ([l for l in lines
333
+ if re .match (r"[\s]*import[\s][\s]*ustruct" , l )])
334
+ struct_lines = ([l for l in lines
335
+ if re .match (r"[\s]*import[\s][\s]*struct" , l )])
308
336
if ustruct_lines and not struct_lines :
309
337
errors .append (ERROR_PYFILE_MISSING_STRUCT )
310
338
311
- ure_lines = [l for l in lines if re .match (r"[\s]*import[\s][\s]*ure" , l )]
312
- re_lines = [l for l in lines if re .match (r"[\s]*import[\s][\s]*re" , l )]
339
+ ure_lines = ([l for l in lines
340
+ if re .match (r"[\s]*import[\s][\s]*ure" , l )])
341
+ re_lines = ([l for l in lines
342
+ if re .match (r"[\s]*import[\s][\s]*re" , l )])
313
343
if ure_lines and not re_lines :
314
344
errors .append (ERROR_PYFILE_MISSING_RE )
315
345
316
- ujson_lines = [l for l in lines if re .match (r"[\s]*import[\s][\s]*ujson" , l )]
317
- json_lines = [l for l in lines if re .match (r"[\s]*import[\s][\s]*json" , l )]
346
+ ujson_lines = ([l for l in lines
347
+ if re .match (r"[\s]*import[\s][\s]*ujson" , l )])
348
+ json_lines = ([l for l in lines
349
+ if re .match (r"[\s]*import[\s][\s]*json" , l )])
318
350
if ujson_lines and not json_lines :
319
351
errors .append (ERROR_PYFILE_MISSING_JSON )
320
352
321
- uerrno_lines = [l for l in lines if re .match (r"[\s]*import[\s][\s]*uerrno" , l )]
322
- errno_lines = [l for l in lines if re .match (r"[\s]*import[\s][\s]*errno" , l )]
353
+ uerrno_lines = ([l for l in lines
354
+ if re .match (r"[\s]*import[\s][\s]*uerrno" , l )])
355
+ errno_lines = ([l for l in lines
356
+ if re .match (r"[\s]*import[\s][\s]*errno" , l )])
323
357
if uerrno_lines and not errno_lines :
324
358
errors .append (ERROR_PYFILE_MISSING_ERRNO )
325
359
@@ -336,7 +370,10 @@ def _validate_travis_yml(self, repo, travis_yml_file_info):
336
370
errors = []
337
371
338
372
lines = contents .text .split ("\n " )
339
- pypi_providers_lines = [l for l in lines if re .match (r"[\s]*-[\s]*provider:[\s]*pypi[\s]*" , l )]
373
+ pypi_providers_lines = (
374
+ [l for l in lines
375
+ if re .match (r"[\s]*-[\s]*provider:[\s]*pypi[\s]*" , l )]
376
+ )
340
377
341
378
if not pypi_providers_lines :
342
379
errors .append (ERROR_MISSING_PYPIPROVIDER )
@@ -381,7 +418,8 @@ def _validate_requirements_txt(self, repo, file_info):
381
418
382
419
errors = []
383
420
lines = contents .text .split ("\n " )
384
- blinka_lines = [l for l in lines if re .match (r"[\s]*Adafruit-Blinka[\s]*" , l )]
421
+ blinka_lines = ([l for l in lines
422
+ if re .match (r"[\s]*Adafruit-Blinka[\s]*" , l )])
385
423
386
424
if not blinka_lines and repo ["name" ] not in LIBRARIES_DONT_NEED_BLINKA :
387
425
errors .append (ERROR_MISSING_BLINKA )
@@ -409,7 +447,8 @@ def validate_contents(self, repo):
409
447
files = [x ["name" ] for x in content_list ]
410
448
411
449
# ignore new/in-work repos, which should have less than 8 files:
412
- # ___.py or folder, CoC, .travis.yml, .readthedocs.yml, docs/, examples/, README, LICENSE
450
+ # ___.py or folder, CoC, .travis.yml, .readthedocs.yml, docs/,
451
+ # examples/, README, LICENSE
413
452
if len (files ) < 8 :
414
453
BUNDLE_IGNORE_LIST .append (repo ["name" ])
415
454
if not self .validate_contents_quiet :
@@ -435,7 +474,8 @@ def validate_contents(self, repo):
435
474
if f ["name" ] == "README.rst" :
436
475
readme_info = f
437
476
break
438
- errors .extend (self ._validate_readme (repo , readme_info ["download_url" ]))
477
+ errors .extend (self ._validate_readme (repo ,
478
+ readme_info ["download_url" ]))
439
479
440
480
if ".travis.yml" in files :
441
481
file_info = content_list [files .index (".travis.yml" )]
@@ -471,19 +511,23 @@ def validate_contents(self, repo):
471
511
dirs = [x ["name" ] for x in content_list if x ["type" ] == "dir" ]
472
512
if "examples" in dirs :
473
513
# check for at least on .py file
474
- examples_list = github .get ("/repos/" + repo ["full_name" ] + "/contents/examples" )
514
+ examples_list = github .get ("/repos/"
515
+ + repo ["full_name" ]
516
+ + "/contents/examples" )
475
517
if not examples_list .ok :
476
518
errors .append (ERROR_UNABLE_PULL_REPO_EXAMPLES )
477
519
examples_list = examples_list .json ()
478
520
if len (examples_list ) < 1 :
479
521
errors .append (ERROR_MISSING_EXAMPLE_FILES )
480
522
else :
481
- lib_name = repo ["name" ][repo ["name" ].rfind ("CircuitPython_" ) + 14 :].lower ()
523
+ lib_name = (repo ["name" ][repo ["name" ].rfind ("CircuitPython_" )
524
+ + 14 :].lower ())
482
525
all_have_name = True
483
526
simpletest_exists = False
484
527
for example in examples_list :
485
- if not example ["name" ].lower ().startswith (lib_name ):
486
- all_have_name = False
528
+ if (not example ["name" ].lower ().startswith (lib_name )
529
+ and example ["name" ].endswith (".py" )):
530
+ all_have_name = False
487
531
if "simpletest" in example ["name" ].lower ():
488
532
simpletest_exists = True
489
533
if not all_have_name :
@@ -495,7 +539,8 @@ def validate_contents(self, repo):
495
539
496
540
# first location .py files whose names begin with "adafruit_"
497
541
re_str = re .compile ('adafruit\_[\w]*\.py' )
498
- pyfiles = [x ["download_url" ] for x in content_list if re_str .fullmatch (x ["name" ])]
542
+ pyfiles = ([x ["download_url" ] for x in content_list
543
+ if re_str .fullmatch (x ["name" ])])
499
544
for pyfile in pyfiles :
500
545
# adafruit_xxx.py file; check if for proper usage of u___ versions of modules
501
546
errors .extend (self ._validate_py_for_u_modules (repo , pyfile ))
@@ -505,14 +550,20 @@ def validate_contents(self, repo):
505
550
for adir in dirs :
506
551
if re_str .fullmatch (adir ):
507
552
# retrieve the files in that directory
508
- dir_file_list = github .get ("/repos/" + repo ["full_name" ] + "/contents/" + adir )
553
+ dir_file_list = github .get ("/repos/"
554
+ + repo ["full_name" ]
555
+ + "/contents/"
556
+ + adir )
509
557
if not dir_file_list .ok :
510
558
errors .append (ERROR_UNABLE_PULL_REPO_DIR )
511
559
dir_file_list = dir_file_list .json ()
512
560
# search for .py files in that directory
513
- dir_files = [x ["download_url" ] for x in dir_file_list if x ["type" ] == "file" and x ["name" ].endswith (".py" )]
561
+ dir_files = ([x ["download_url" ] for x in dir_file_list
562
+ if x ["type" ] == "file"
563
+ and x ["name" ].endswith (".py" )])
514
564
for dir_file in dir_files :
515
- # .py files in subdirectory adafruit_xxx; check if for proper usage of u___ versions of modules
565
+ # .py files in subdirectory adafruit_xxx
566
+ # check if for proper usage of u___ versions of modules
516
567
errors .extend (self ._validate_py_for_u_modules (repo , dir_file ))
517
568
518
569
return errors
0 commit comments