Skip to content

Commit bc5a791

Browse files
committed
Handle projects that have sub-directories
.. as requested in the comments on adafruit/Adafruit_Learning_System_Guides#1533
1 parent 9ce3876 commit bc5a791

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

create_requirement_images.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def make_libraries(libraries, position):
325325
(PADDING, PADDING + (LINE_SPACING * (7 + project_files_count))),
326326
)
327327

328-
img.save("generated_images/{}.png".format(learn_guide_project))
328+
img.save("generated_images/{}.png".format(learn_guide_project.replace("/", "_")))
329329
except SyntaxError as exc:
330330
print(exc)
331331
traceback.print_exc()

get_imports.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
BUNDLE_TAG = "latest_bundle_tag.json"
1717

1818
LEARN_GUIDE_REPO = os.environ.get(
19-
"LEARN_GUIDE_REPO", "../../Adafruit_Learning_System_Guides/"
19+
"LEARN_GUIDE_REPO", "../Adafruit_Learning_System_Guides/"
2020
)
2121

2222
SHOWN_FILETYPES = ["py", "mpy", "bmp", "pcf", "bdf", "wav", "mp3", "json", "txt"]
@@ -140,28 +140,27 @@ def get_libs_for_project(project_name):
140140
return found_libs
141141

142142

143-
def get_learn_guide_projects():
144-
"""Get the list of all folders in the learn guide"""
145-
return os.listdir(LEARN_GUIDE_REPO)
146-
147-
148143
def get_learn_guide_cp_projects():
149144
"""Get the list of all circuitpython projects, according to some heuristics"""
150-
cp_projects = []
151-
152-
def has_py_file(location):
153-
dir_files = os.listdir(location)
154-
for file in dir_files:
155-
if file.endswith(".py"):
156-
return ".circuitpython.skip" not in dir_files
157-
return False
158-
159-
all_projects = get_learn_guide_projects()
160-
for project in all_projects:
161-
project_dir = "{}/{}/".format(LEARN_GUIDE_REPO, project)
162-
try:
163-
if has_py_file(project_dir):
164-
cp_projects.append(project)
165-
except NotADirectoryError:
166-
pass
167-
return cp_projects
145+
for dirpath, dirnames, filenames in os.walk(LEARN_GUIDE_REPO):
146+
# The top-level needs special treatment
147+
if dirpath == LEARN_GUIDE_REPO:
148+
dirnames.remove('.git')
149+
continue
150+
# Skip this folder and all subfolders
151+
if '.circuitpython.skip' in filenames:
152+
del dirnames[:]
153+
continue
154+
# Do not reurse, but handle files in this folder
155+
elif '.circuitpython.skip-sub' in filenames:
156+
del dirnames[:]
157+
# Skip files in this folder, but handle sub-folders
158+
elif '.circuitpython.skip-here' in filenames:
159+
continue
160+
161+
if any(f for f in filenames if f.endswith(".py")):
162+
yield os.path.relpath(dirpath, LEARN_GUIDE_REPO)
163+
164+
if __name__ == '__main__':
165+
for p in get_learn_guide_cp_projects():
166+
print("PROJECT", p)

0 commit comments

Comments
 (0)