@@ -636,14 +636,73 @@ def validate_contents(self, repo):
636
636
if len (examples_list ) < 1 :
637
637
errors .append (ERROR_MISSING_EXAMPLE_FILES )
638
638
else :
639
- lib_name = (repo ["name" ][repo ["name" ].rfind ("CircuitPython_" )
640
- + 14 :].lower ())
639
+ def __check_lib_name (repo_name , file_name ):
640
+ """ Nested function to test example file names.
641
+ Allows examples to either match the repo name,
642
+ or have underscores separating the repo name.
643
+ """
644
+ file_names = set ()
645
+ file_names .add (file_name )
646
+
647
+ name_split = file_name .split ("_" )
648
+ name_rebuilt = '' .join (
649
+ (part for part in name_split if ".py" not in part )
650
+ )
651
+
652
+ if name_rebuilt : # avoid adding things like 'simpletest.py' -> ''
653
+ file_names .add (name_rebuilt )
654
+
655
+ found = False
656
+
657
+ """ Option 1:
658
+ Strips underscores from repo name and example name, and makes comparison
659
+
660
+ repo_name_stripped = repo_name.replace("_", "")
661
+ match = name_rebuilt.startswith(repo_name_stripped)
662
+ print(
663
+ f"Checking {repo_name} against {file_name}\n "
664
+ f"\t Repo name stripped of '_': {repo_name_stripped}\n "
665
+ f"\t Rebuilt example name: {name_rebuilt}\n "
666
+ f"\t Match: {match}"
667
+ )
668
+ return match
669
+ """
670
+
671
+ """ Option 2:
672
+ Strips underscores from example file name only, adds to set with original
673
+ file name, and compares repo name to both example file name versions
674
+
675
+ #return any(
676
+ # name.startswith(repo_name) for name in file_names
677
+ #)
678
+
679
+ ## long form only for showing results; 'any' above is the preferred version
680
+ print(f"Checking {repo_name} against {file_name} versions:")
681
+ for name in file_names:
682
+ if name.startswith(repo_name):
683
+ found = True
684
+
685
+ print(
686
+ f"\t Example file name: {name}\t Match: {found}"
687
+ )
688
+
689
+ return found
690
+ ##
691
+ """
692
+
693
+ lib_name_start = repo ["name" ].rfind ("CircuitPython_" ) + 14
694
+ lib_name = repo ["name" ][lib_name_start :].lower ()
695
+
641
696
all_have_name = True
642
697
simpletest_exists = False
643
698
for example in examples_list :
644
- if (not example ["name" ].lower ().startswith (lib_name )
645
- and example ["name" ].endswith (".py" )):
646
- all_have_name = False
699
+ if example ["name" ].endswith (".py" ):
700
+ check_lib_name = __check_lib_name (
701
+ lib_name ,
702
+ example ["name" ].lower ()
703
+ )
704
+ if not check_lib_name :
705
+ all_have_name = False
647
706
if "simpletest" in example ["name" ].lower ():
648
707
simpletest_exists = True
649
708
if not all_have_name :
0 commit comments