Skip to content

Commit 2a2b59c

Browse files
authored
Merge pull request #3 from jepler/subfolders
Handle projects that have sub-directories
2 parents 9ce3876 + 812fa53 commit 2a2b59c

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ SPDX-License-Identifier: MIT
66

77
This folder contains scripts that can be run to create requirement screenshots for all of the learn guide projects
88

9-
To use the scripts you must set `LEARN_GUIDE_REPO` inside of `get_imports.py` to point to the location of learn guide repo.
9+
To use the scripts you must set the environment `LEARN_GUIDE_REPO` to point to the location of learn guide repo. It must end with a trailing slash.
1010

11-
default value is `"../../Adafruit_Learning_System_Guides/"`
12-
13-
One directory above the root of this repo.
11+
The default value is `"../Adafruit_Learning_System_Guides/"`, one directory above the root of this repo.
1412

1513
With that pointed at a learn guide repo you can run:
1614

1715
```
18-
python create_requirement_images.py
16+
python3 create_requirement_images.py
1917
```
2018
It will create images in the `generated_images` directory.

create_requirement_images.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,9 @@ 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(
329+
"generated_images/{}.png".format(learn_guide_project.replace("/", "_"))
330+
)
329331
except SyntaxError as exc:
330332
print(exc)
331333
traceback.print_exc()

get_imports.py

Lines changed: 24 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,28 @@ 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+
# Skip files in this folder, but handle sub-folders
155+
if ".circuitpython.skip-here" in filenames:
156+
continue
157+
# Do not reurse, but handle files in this folder
158+
if ".circuitpython.skip-sub" in filenames:
159+
del dirnames[:]
160+
161+
if any(f for f in filenames if f.endswith(".py")):
162+
yield os.path.relpath(dirpath, LEARN_GUIDE_REPO)
163+
164+
165+
if __name__ == "__main__":
166+
for p in get_learn_guide_cp_projects():
167+
print("PROJECT", p)

0 commit comments

Comments
 (0)