58
58
ERROR_PYFILE_MISSING_STRUCT = ".py file contains reference to import ustruct" \
59
59
" without reference to import struct. See issue " \
60
60
"https://github.com/adafruit/circuitpython/issues/782"
61
+ ERROR_PYFILE_MISSING_RE = ".py file contains reference to import ure" \
62
+ " without reference to import re. See issue " \
63
+ "https://github.com/adafruit/circuitpython/issues/1582"
64
+ ERROR_PYFILE_MISSING_JSON = ".py file contains reference to import ujson" \
65
+ " without reference to import json. See issue " \
66
+ "https://github.com/adafruit/circuitpython/issues/1582"
67
+ ERROR_PYFILE_MISSING_ERRNO = ".py file contains reference to import uerrno" \
68
+ " without reference to import errno. See issue " \
69
+ "https://github.com/adafruit/circuitpython/issues/1582"
61
70
ERROR_MISMATCHED_READTHEDOCS = "Mismatched readthedocs.yml"
62
71
ERROR_MISSING_EXAMPLE_FILES = "Missing .py files in examples folder"
63
72
ERROR_MISSING_EXAMPLE_FOLDER = "Missing examples folder"
@@ -421,10 +430,10 @@ def validate_readme(repo, download_url):
421
430
422
431
return errors
423
432
424
- def validate_py_for_ustruct (repo , download_url ):
425
- """ For a .py file, look for usage of "import ustruct " and
426
- look for "import struct ". If the "import ustruct " is
427
- used with NO "import struct " generate an error.
433
+ def validate_py_for_u_modules (repo , download_url ):
434
+ """ For a .py file, look for usage of "import u___ " and
435
+ look for "import ___ ". If the "import u___ " is
436
+ used with NO "import ____ " generate an error.
428
437
"""
429
438
# We use requests because file contents are hosted by githubusercontent.com, not the API domain.
430
439
contents = requests .get (download_url , timeout = 30 )
@@ -439,6 +448,21 @@ def validate_py_for_ustruct(repo, download_url):
439
448
if ustruct_lines and not struct_lines :
440
449
errors .append (ERROR_PYFILE_MISSING_STRUCT )
441
450
451
+ ure_lines = [l for l in lines if re .match (r"[\s]*import[\s][\s]*ure" , l )]
452
+ re_lines = [l for l in lines if re .match (r"[\s]*import[\s][\s]*re" , l )]
453
+ if ure_lines and not re_lines :
454
+ errors .append (ERROR_PYFILE_MISSING_RE )
455
+
456
+ ujson_lines = [l for l in lines if re .match (r"[\s]*import[\s][\s]*ujson" , l )]
457
+ json_lines = [l for l in lines if re .match (r"[\s]*import[\s][\s]*json" , l )]
458
+ if ujson_lines and not json_lines :
459
+ errors .append (ERROR_PYFILE_MISSING_JSON )
460
+
461
+ uerrno_lines = [l for l in lines if re .match (r"[\s]*import[\s][\s]*uerrno" , l )]
462
+ errno_lines = [l for l in lines if re .match (r"[\s]*import[\s][\s]*errno" , l )]
463
+ if uerrno_lines and not errno_lines :
464
+ errors .append (ERROR_PYFILE_MISSING_ERRNO )
465
+
442
466
return errors
443
467
444
468
def validate_travis_yml (repo , travis_yml_file_info ):
@@ -611,8 +635,8 @@ def validate_contents(repo):
611
635
re_str = re .compile ('adafruit\_[\w]*\.py' )
612
636
pyfiles = [x ["download_url" ] for x in content_list if re_str .fullmatch (x ["name" ])]
613
637
for pyfile in pyfiles :
614
- # adafruit_xxx.py file; check if for proper usage of ustruct
615
- errors .extend (validate_py_for_ustruct (repo , pyfile ))
638
+ # adafruit_xxx.py file; check if for proper usage of u___ versions of modules
639
+ errors .extend (validate_py_for_u_modules (repo , pyfile ))
616
640
617
641
# now location any directories whose names begin with "adafruit_"
618
642
re_str = re .compile ('adafruit\_[\w]*' )
@@ -626,8 +650,8 @@ def validate_contents(repo):
626
650
# search for .py files in that directory
627
651
dir_files = [x ["download_url" ] for x in dir_file_list if x ["type" ] == "file" and x ["name" ].endswith (".py" )]
628
652
for dir_file in dir_files :
629
- # .py files in subdirectory adafruit_xxx; check if for proper usage of ustruct
630
- errors .extend (validate_py_for_ustruct (repo , dir_file ))
653
+ # .py files in subdirectory adafruit_xxx; check if for proper usage of u___ versions of modules
654
+ errors .extend (validate_py_for_u_modules (repo , dir_file ))
631
655
632
656
return errors
633
657
0 commit comments