Skip to content

Commit 389c03a

Browse files
committed
draft: allow underscores in example filenames; two options included and will need to be finalized; won't run as is
1 parent ddcf3f0 commit 389c03a

File tree

1 file changed

+64
-5
lines changed

1 file changed

+64
-5
lines changed

adabot/lib/circuitpython_library_validators.py

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -636,14 +636,73 @@ def validate_contents(self, repo):
636636
if len(examples_list) < 1:
637637
errors.append(ERROR_MISSING_EXAMPLE_FILES)
638638
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"\tRepo name stripped of '_': {repo_name_stripped}\n"
665+
f"\tRebuilt example name: {name_rebuilt}\n"
666+
f"\tMatch: {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"\tExample file name: {name}\tMatch: {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+
641696
all_have_name = True
642697
simpletest_exists = False
643698
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
647706
if "simpletest" in example["name"].lower():
648707
simpletest_exists = True
649708
if not all_have_name:

0 commit comments

Comments
 (0)