From cec40bf14b015e7a75cab5d0409a24b941205a8f Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 14 Aug 2021 08:42:45 -0500 Subject: [PATCH 01/38] add down_triangle to CIRCUITPY and indent everything below --- create_requirement_images.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/create_requirement_images.py b/create_requirement_images.py index 08faf38..ef61b31 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -159,32 +159,32 @@ def make_line( def make_header(position, project_files): # Static files - make_line("CIRCUITPY", position) + make_line("CIRCUITPY", (position[0] + INDENT_SIZE, position[1]), triangle_icon=down_triangle) make_line( ".fseventsd", - (position[0] + INDENT_SIZE, position[1] + (LINE_SPACING * 1)), + (position[0] + INDENT_SIZE * 2, position[1] + (LINE_SPACING * 1)), hidden=True, triangle_icon=right_triangle, ) make_line( ".metadata_never_index", - (position[0] + INDENT_SIZE, position[1] + (LINE_SPACING * 2)), + (position[0] + INDENT_SIZE * 2, position[1] + (LINE_SPACING * 2)), icon=file_empty_hidden_icon, hidden=True, ) make_line( ".Trashes", - (position[0] + INDENT_SIZE, position[1] + (LINE_SPACING * 3)), + (position[0] + INDENT_SIZE * 2, position[1] + (LINE_SPACING * 3)), icon=file_empty_hidden_icon, hidden=True, ) make_line( "boot_out.txt", - (position[0] + INDENT_SIZE, position[1] + (LINE_SPACING * 4)), + (position[0] + INDENT_SIZE * 2, position[1] + (LINE_SPACING * 4)), ) make_line( "code.py", - (position[0] + INDENT_SIZE, position[1] + (LINE_SPACING * 5)), + (position[0] + INDENT_SIZE * 2, position[1] + (LINE_SPACING * 5)), icon=file_icon, ) @@ -206,7 +206,7 @@ def make_header(position, project_files): cur_file_icon = FILE_TYPE_ICON_MAP.get(cur_file_extension, file_empty_icon) make_line( file, - (position[0] + INDENT_SIZE, position[1] + (LINE_SPACING * (6 + i))), + (position[0] + INDENT_SIZE * 2, position[1] + (LINE_SPACING * (6 + i))), icon=cur_file_icon, ) rows_added += 1 @@ -215,7 +215,7 @@ def make_header(position, project_files): make_line( file, ( - position[0] + INDENT_SIZE, + position[0] + INDENT_SIZE * 2, position[1] + (LINE_SPACING * (6 + i + len(project_files_to_draw))), ), triangle_icon=right_triangle, @@ -225,7 +225,7 @@ def make_header(position, project_files): make_line( "lib", ( - position[0] + INDENT_SIZE, + position[0] + INDENT_SIZE * 2, position[1] + (LINE_SPACING * (5 + rows_added + 1)), ), triangle_icon=down_triangle, @@ -288,7 +288,7 @@ def make_libraries(libraries, position): triangle_icon = right_triangle make_line( lib_name, - (position[0] + INDENT_SIZE * 2, position[1] + (LINE_SPACING * i)), + (position[0] + INDENT_SIZE * 3, position[1] + (LINE_SPACING * i)), triangle_icon=triangle_icon, ) From 90ef2a697a8192ab5d99adfb05df18dd02effa86 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 14 Aug 2021 09:17:20 -0500 Subject: [PATCH 02/38] add midi files to list of filetypes that get drawn in the image. --- create_requirement_images.py | 3 ++- get_imports.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/create_requirement_images.py b/create_requirement_images.py index ef61b31..5b680f2 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -36,7 +36,7 @@ TEXT_COLOR = "#B0B0B0" HIDDEN_TEXT_COLOR = "#808080" -SHOWN_FILETYPES = ["py", "mpy", "bmp", "pcf", "bdf", "wav", "mp3", "json", "txt"] +SHOWN_FILETYPES = ["py", "mpy", "bmp", "pcf", "bdf", "wav", "mp3", "mid", "json", "txt"] f = open("latest_bundle_data.json", "r") bundle_data = json.load(f) @@ -70,6 +70,7 @@ def asset_path(asset_name): "bmp": file_image_icon, "wav": file_music_icon, "mp3": file_music_icon, + "mid": file_music_icon, "pcf": file_font_icon, "bdf": file_font_icon, "json": file_icon, diff --git a/get_imports.py b/get_imports.py index 3ea6cab..e191072 100644 --- a/get_imports.py +++ b/get_imports.py @@ -19,7 +19,7 @@ "LEARN_GUIDE_REPO", "../Adafruit_Learning_System_Guides/" ) -SHOWN_FILETYPES = ["py", "mpy", "bmp", "pcf", "bdf", "wav", "mp3", "json", "txt"] +SHOWN_FILETYPES = ["py", "mpy", "bmp", "pcf", "bdf", "wav", "mp3", "mid", "json", "txt"] SHOWN_FILETYPES_EXAMPLE = [s for s in SHOWN_FILETYPES if s != "py"] From cbeca741010bf0a8ccaf0fab300013d4cbe47917 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 15 Aug 2021 07:59:55 -0500 Subject: [PATCH 03/38] show subdirectories in screenshot --- create_requirement_images.py | 60 +++++++++++++++++++++++++++++------- get_imports.py | 34 +++++++++++++++++--- 2 files changed, 79 insertions(+), 15 deletions(-) diff --git a/create_requirement_images.py b/create_requirement_images.py index 5b680f2..c73e967 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -86,6 +86,7 @@ def generate_requirement_image( ): # pylint: disable=too-many-statements """Generate a single requirement image""" + def make_line( requirement_name, position=(0, 0), icon=None, hidden=False, triangle_icon=None ): # pylint: disable=too-many-branches @@ -192,14 +193,16 @@ def make_header(position, project_files): # dynamic files from project dir in learn guide repo rows_added = 0 project_files_to_draw = [] - project_folders_to_draw = [] + project_folders_to_draw = {} for cur_file in project_files: - if "." in cur_file[-5:]: - cur_extension = cur_file.split(".")[-1] - if cur_extension in SHOWN_FILETYPES: - project_files_to_draw.append(cur_file) - else: - project_folders_to_draw.append(cur_file) + if type(cur_file) == str: + if "." in cur_file[-5:]: + cur_extension = cur_file.split(".")[-1] + if cur_extension in SHOWN_FILETYPES: + project_files_to_draw.append(cur_file) + + elif type(cur_file) == tuple: + project_folders_to_draw[cur_file[0]] = cur_file[1] for i, file in enumerate(sorted(project_files_to_draw)): cur_file_extension = file.split(".")[-1] @@ -212,16 +215,41 @@ def make_header(position, project_files): ) rows_added += 1 - for i, file in enumerate(sorted(project_folders_to_draw)): + extra_rows = 0 + for i, file in enumerate(sorted(project_folders_to_draw.keys())): make_line( file, ( position[0] + INDENT_SIZE * 2, - position[1] + (LINE_SPACING * (6 + i + len(project_files_to_draw))), + position[1] + (LINE_SPACING * (6 + i + len(project_files_to_draw) + extra_rows)), ), - triangle_icon=right_triangle, + triangle_icon=down_triangle, ) rows_added += 1 + if file == "midi": + #print(project_folders_to_draw) + pass + extra_sub_file_space = 0 + for j, sub_file in enumerate(sorted(project_folders_to_draw[file])): + extra_rows += 1 + cur_file_extension = sub_file.split(".")[-1] + cur_file_icon = FILE_TYPE_ICON_MAP.get(cur_file_extension, folder_icon) + triangle_icon = None + if cur_file_icon == folder_icon: + triangle_icon = right_triangle + make_line( + sub_file, + ( + position[0] + INDENT_SIZE *3, + #position[1] + (LINE_SPACING * (6 + i + j + 1 + extra_sub_file_space + # + len(project_files_to_draw))), + position[1] + (LINE_SPACING * (6 + rows_added)), + ), + triangle_icon=triangle_icon, + icon=cur_file_icon + ) + rows_added += 1 + extra_sub_file_space = extra_rows make_line( "lib", @@ -281,6 +309,16 @@ def sort_libraries(libraries): package_list, file_list = get_dependencies(libraries) return sorted(package_list) + sorted(file_list) + def count_files(files_list): + _count = 0 + for _file in files_list: + if type(_file) == str: + _count += 1 + elif type(_file) == tuple: + _count += 1 + _count += len(_file[1]) + return _count + def make_libraries(libraries, position): for i, lib_name in enumerate(libraries): @@ -301,7 +339,7 @@ def make_libraries(libraries, position): if "main.py" in project_files: project_files.remove("main.py") - project_files_count = len(project_files) + project_files_count = count_files(project_files) image_height = ( PADDING * 2 diff --git a/get_imports.py b/get_imports.py index e191072..85c8d2b 100644 --- a/get_imports.py +++ b/get_imports.py @@ -111,15 +111,41 @@ def get_files_for_project(project_name): """Get the set of files for a learn project""" found_files = set() project_dir = "{}/{}/".format(LEARN_GUIDE_REPO, project_name) - for file in os.listdir(project_dir): + # root level + full_tree = os.walk(project_dir) + + root_level = next(full_tree) + if project_name == "NeoTrellis_M4_MIDI_Synth": + print(root_level) + + for file in root_level[2]: if "." in file: cur_extension = file.split(".")[-1] if cur_extension in SHOWN_FILETYPES: # print(file) found_files.add(file) - else: - # add dir - found_files.add(file) + + for _dir in root_level[1]: + if project_name == "NeoTrellis_M4_MIDI_Synth": + print(_dir) + # TODO: second item needs to be a tuple + dir_tuple = (_dir, tuple()) + for cur_tuple in os.walk(project_dir): + if project_name == "NeoTrellis_M4_MIDI_Synth": + print(cur_tuple) + #print("{} - {}".format(cur_tuple[0].split("/")[-1], _dir)) + #print(cur_tuple) + if cur_tuple[0].split("/")[-1] == _dir: + # TODO: can't use add or append to add to a tuple + # TODO: need to use + to make new tuple or * unpacking + # https://stackoverflow.com/questions/16730339/python-add-item-to-the-tuple + for _sub_dir in cur_tuple[1]: + dir_tuple = (dir_tuple[0], dir_tuple[1] + (_sub_dir,)) + for _sub_file in cur_tuple[2]: + dir_tuple = (dir_tuple[0], dir_tuple[1] + (_sub_file,)) + + # e.g. ("dir_name", ("file_1.txt", "file_2.txt")) + found_files.add(dir_tuple) return found_files From fee445140c4372aa3cc8749634395821ddae56d5 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 15 Aug 2021 08:26:07 -0500 Subject: [PATCH 04/38] cleanup debug prints --- create_requirement_images.py | 5 ----- get_imports.py | 15 +-------------- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/create_requirement_images.py b/create_requirement_images.py index c73e967..e449bd6 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -226,10 +226,6 @@ def make_header(position, project_files): triangle_icon=down_triangle, ) rows_added += 1 - if file == "midi": - #print(project_folders_to_draw) - pass - extra_sub_file_space = 0 for j, sub_file in enumerate(sorted(project_folders_to_draw[file])): extra_rows += 1 cur_file_extension = sub_file.split(".")[-1] @@ -249,7 +245,6 @@ def make_header(position, project_files): icon=cur_file_icon ) rows_added += 1 - extra_sub_file_space = extra_rows make_line( "lib", diff --git a/get_imports.py b/get_imports.py index 85c8d2b..b34417d 100644 --- a/get_imports.py +++ b/get_imports.py @@ -111,12 +111,9 @@ def get_files_for_project(project_name): """Get the set of files for a learn project""" found_files = set() project_dir = "{}/{}/".format(LEARN_GUIDE_REPO, project_name) - # root level - full_tree = os.walk(project_dir) + full_tree = os.walk(project_dir) root_level = next(full_tree) - if project_name == "NeoTrellis_M4_MIDI_Synth": - print(root_level) for file in root_level[2]: if "." in file: @@ -126,19 +123,9 @@ def get_files_for_project(project_name): found_files.add(file) for _dir in root_level[1]: - if project_name == "NeoTrellis_M4_MIDI_Synth": - print(_dir) - # TODO: second item needs to be a tuple dir_tuple = (_dir, tuple()) for cur_tuple in os.walk(project_dir): - if project_name == "NeoTrellis_M4_MIDI_Synth": - print(cur_tuple) - #print("{} - {}".format(cur_tuple[0].split("/")[-1], _dir)) - #print(cur_tuple) if cur_tuple[0].split("/")[-1] == _dir: - # TODO: can't use add or append to add to a tuple - # TODO: need to use + to make new tuple or * unpacking - # https://stackoverflow.com/questions/16730339/python-add-item-to-the-tuple for _sub_dir in cur_tuple[1]: dir_tuple = (dir_tuple[0], dir_tuple[1] + (_sub_dir,)) for _sub_file in cur_tuple[2]: From f2552ee535f2520713654b414e2e8a8776cc1121 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 15 Aug 2021 09:01:38 -0500 Subject: [PATCH 05/38] pre-commit fixes --- create_requirement_images.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/create_requirement_images.py b/create_requirement_images.py index e449bd6..085fb0c 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -86,7 +86,6 @@ def generate_requirement_image( ): # pylint: disable=too-many-statements """Generate a single requirement image""" - def make_line( requirement_name, position=(0, 0), icon=None, hidden=False, triangle_icon=None ): # pylint: disable=too-many-branches @@ -161,7 +160,11 @@ def make_line( def make_header(position, project_files): # Static files - make_line("CIRCUITPY", (position[0] + INDENT_SIZE, position[1]), triangle_icon=down_triangle) + make_line( + "CIRCUITPY", + (position[0] + INDENT_SIZE, position[1]), + triangle_icon=down_triangle, + ) make_line( ".fseventsd", (position[0] + INDENT_SIZE * 2, position[1] + (LINE_SPACING * 1)), @@ -195,13 +198,14 @@ def make_header(position, project_files): project_files_to_draw = [] project_folders_to_draw = {} for cur_file in project_files: - if type(cur_file) == str: + # string for individual file + if isinstance(cur_file, str): if "." in cur_file[-5:]: cur_extension = cur_file.split(".")[-1] if cur_extension in SHOWN_FILETYPES: project_files_to_draw.append(cur_file) - - elif type(cur_file) == tuple: + # tuple for directory + elif isinstance(cur_file, tuple): project_folders_to_draw[cur_file[0]] = cur_file[1] for i, file in enumerate(sorted(project_files_to_draw)): @@ -221,12 +225,15 @@ def make_header(position, project_files): file, ( position[0] + INDENT_SIZE * 2, - position[1] + (LINE_SPACING * (6 + i + len(project_files_to_draw) + extra_rows)), + position[1] + + ( + LINE_SPACING * (6 + i + len(project_files_to_draw) + extra_rows) + ), ), triangle_icon=down_triangle, ) rows_added += 1 - for j, sub_file in enumerate(sorted(project_folders_to_draw[file])): + for sub_file in sorted(project_folders_to_draw[file]): extra_rows += 1 cur_file_extension = sub_file.split(".")[-1] cur_file_icon = FILE_TYPE_ICON_MAP.get(cur_file_extension, folder_icon) @@ -236,13 +243,11 @@ def make_header(position, project_files): make_line( sub_file, ( - position[0] + INDENT_SIZE *3, - #position[1] + (LINE_SPACING * (6 + i + j + 1 + extra_sub_file_space - # + len(project_files_to_draw))), + position[0] + INDENT_SIZE * 3, position[1] + (LINE_SPACING * (6 + rows_added)), ), triangle_icon=triangle_icon, - icon=cur_file_icon + icon=cur_file_icon, ) rows_added += 1 @@ -307,9 +312,12 @@ def sort_libraries(libraries): def count_files(files_list): _count = 0 for _file in files_list: - if type(_file) == str: + # string for individual file + if isinstance(_file, str): _count += 1 - elif type(_file) == tuple: + + # tuple for directory + elif isinstance(_file, tuple): _count += 1 _count += len(_file[1]) return _count From d568d23f4cd298d00eb8c8a6a0b771906474935f Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 13 Nov 2021 11:28:48 -0600 Subject: [PATCH 06/38] fix image for library examples that contain directories. --- create_requirement_images.py | 1 + get_imports.py | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/create_requirement_images.py b/create_requirement_images.py index 085fb0c..44cc50a 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -74,6 +74,7 @@ def asset_path(asset_name): "pcf": file_font_icon, "bdf": file_font_icon, "json": file_icon, + "license": file_empty_icon, } # If this is not done, the images fail to load in the subprocesses. diff --git a/get_imports.py b/get_imports.py index b34417d..1b76d23 100644 --- a/get_imports.py +++ b/get_imports.py @@ -158,15 +158,30 @@ def get_files_for_example(example_path): """Get the set of files for a library example""" found_files = set(("code.py",)) example_dir = os.path.dirname(example_path) - for file in os.listdir(example_dir): + + full_tree = os.walk(example_dir) + root_level = next(full_tree) + + for file in root_level[2]: if "." in file: cur_extension = file.split(".")[-1] if cur_extension in SHOWN_FILETYPES_EXAMPLE: # print(file) found_files.add(file) - else: - # add dir - found_files.add(file) + + for _dir in root_level[1]: + dir_tuple = (_dir, tuple()) + for cur_tuple in os.walk(example_dir): + if cur_tuple[0].split("/")[-1] == _dir: + for _sub_dir in cur_tuple[1]: + dir_tuple = (dir_tuple[0], dir_tuple[1] + (_sub_dir,)) + for _sub_file in cur_tuple[2]: + dir_tuple = (dir_tuple[0], dir_tuple[1] + (_sub_file,)) + + # e.g. ("dir_name", ("file_1.txt", "file_2.txt")) + + if ".circuitpython.skip-screenshot" not in dir_tuple[1]: + found_files.add(dir_tuple) return found_files @@ -201,7 +216,7 @@ def get_learn_guide_cp_projects(): # Skip files in this folder, but handle sub-folders if ".circuitpython.skip-screenshot-here" in filenames: continue - # Do not reurse, but handle files in this folder + # Do not recurse, but handle files in this folder if ".circuitpython.skip-screenshot-sub" in filenames: del dirnames[:] From f3fb2f6cb950ed3cbdeec031afe407a3c05be8d6 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 13 Nov 2021 11:43:27 -0600 Subject: [PATCH 07/38] add .idea folder to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7515470..83b0f3a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ __pycache__ latest_bundle_data.json latest_bundle_tag.json generated_images +.idea From 407b798ea71481ffbd5b3d5a3a7cda7d18b25c08 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 13 Nov 2021 12:55:08 -0600 Subject: [PATCH 08/38] undo gitignore change --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 83b0f3a..7515470 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,3 @@ __pycache__ latest_bundle_data.json latest_bundle_tag.json generated_images -.idea From 7a8b4dc0217c3775f57c4cc212989fc1f96f34e4 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 13 Feb 2022 19:28:07 -0600 Subject: [PATCH 09/38] skip file for subdirectories in learn guides --- create_requirement_images.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/create_requirement_images.py b/create_requirement_images.py index 085fb0c..5211c74 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -206,7 +206,8 @@ def make_header(position, project_files): project_files_to_draw.append(cur_file) # tuple for directory elif isinstance(cur_file, tuple): - project_folders_to_draw[cur_file[0]] = cur_file[1] + if ".circuitpython.skip-screenshot" not in cur_file[1]: + project_folders_to_draw[cur_file[0]] = cur_file[1] for i, file in enumerate(sorted(project_files_to_draw)): cur_file_extension = file.split(".")[-1] @@ -318,8 +319,9 @@ def count_files(files_list): # tuple for directory elif isinstance(_file, tuple): - _count += 1 - _count += len(_file[1]) + if ".circuitpython.skip-screenshot" not in _file[1]: + _count += 1 + _count += len(_file[1]) return _count def make_libraries(libraries, position): From 6ca777b5f0bd9ac83792096f8ee4ba72b83925db Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 4 Nov 2022 17:17:10 -0500 Subject: [PATCH 10/38] adding support CSV file type in screenshots --- create_requirement_images.py | 7 +++++-- get_imports.py | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/create_requirement_images.py b/create_requirement_images.py index c52bcce..1b2cba8 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -14,6 +14,7 @@ import click from PIL import Image, ImageDraw, ImageFont +from get_imports import SHOWN_FILETYPES from get_imports import ( get_libs_for_project, @@ -36,8 +37,6 @@ TEXT_COLOR = "#B0B0B0" HIDDEN_TEXT_COLOR = "#808080" -SHOWN_FILETYPES = ["py", "mpy", "bmp", "pcf", "bdf", "wav", "mp3", "mid", "json", "txt"] - f = open("latest_bundle_data.json", "r") bundle_data = json.load(f) f.close() @@ -73,6 +72,7 @@ def asset_path(asset_name): "mid": file_music_icon, "pcf": file_font_icon, "bdf": file_font_icon, + "csv": file_empty_icon, "json": file_icon, "license": file_empty_icon, } @@ -203,6 +203,9 @@ def make_header(position, project_files): if isinstance(cur_file, str): if "." in cur_file[-5:]: cur_extension = cur_file.split(".")[-1] + if cur_extension == "csv": + print("Found CSV:") + print(cur_file) if cur_extension in SHOWN_FILETYPES: project_files_to_draw.append(cur_file) # tuple for directory diff --git a/get_imports.py b/get_imports.py index 1b76d23..d4b2ad8 100644 --- a/get_imports.py +++ b/get_imports.py @@ -12,6 +12,7 @@ import findimports import requests + BUNDLE_DATA = "latest_bundle_data.json" BUNDLE_TAG = "latest_bundle_tag.json" @@ -19,7 +20,19 @@ "LEARN_GUIDE_REPO", "../Adafruit_Learning_System_Guides/" ) -SHOWN_FILETYPES = ["py", "mpy", "bmp", "pcf", "bdf", "wav", "mp3", "mid", "json", "txt"] +SHOWN_FILETYPES = [ + "py", + "mpy", + "bmp", + "pcf", + "bdf", + "wav", + "mp3", + "mid", + "json", + "txt", + "csv", +] SHOWN_FILETYPES_EXAMPLE = [s for s in SHOWN_FILETYPES if s != "py"] From 16f8f30852931c08f0e77daae6484db98b9e3fc4 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 4 Nov 2022 17:38:34 -0500 Subject: [PATCH 11/38] try to use python3.10 --- .github/workflows/pre-commit.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 5c5782d..cded458 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -13,5 +13,8 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - name: Set up Python 3.x + uses: actions/setup-python@v4 + with: + python-version: "3.x" - uses: pre-commit/action@v2.0.2 From 7d06ed2725c1a1797acb051f1b7d71c085ee6c62 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 4 Nov 2022 17:41:10 -0500 Subject: [PATCH 12/38] try to use python3.10 for real this time --- .github/workflows/pre-commit.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index cded458..b004682 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -13,8 +13,8 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - name: Set up Python 3.x + - name: Set up Python 3.10 uses: actions/setup-python@v4 with: - python-version: "3.x" + python-version: "3.10" - uses: pre-commit/action@v2.0.2 From c7427da89d3f47a4996e0cc07c7159a93d893bfb Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 4 Nov 2022 17:49:33 -0500 Subject: [PATCH 13/38] remove prints try newer black version --- .pre-commit-config.yaml | 2 +- create_requirement_images.py | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8e87341..2e92c2a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ repos: - repo: https://github.com/python/black - rev: 20.8b1 + rev: 22.3.0 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool diff --git a/create_requirement_images.py b/create_requirement_images.py index 1b2cba8..ff8f5f1 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -203,9 +203,6 @@ def make_header(position, project_files): if isinstance(cur_file, str): if "." in cur_file[-5:]: cur_extension = cur_file.split(".")[-1] - if cur_extension == "csv": - print("Found CSV:") - print(cur_file) if cur_extension in SHOWN_FILETYPES: project_files_to_draw.append(cur_file) # tuple for directory From 3b577a3b4ddd997ba764ee05eaf6cd7d31b12f7f Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 17 May 2023 19:50:08 -0500 Subject: [PATCH 14/38] add settings.toml to the rendered screenshots if needed. fix bug with code file icon. --- create_requirement_images.py | 63 +++++++++++++++++++++++++++++------- settings_required.py | 37 +++++++++++++++++++++ 2 files changed, 88 insertions(+), 12 deletions(-) create mode 100644 settings_required.py diff --git a/create_requirement_images.py b/create_requirement_images.py index ff8f5f1..4ea5ee9 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -23,6 +23,7 @@ get_files_for_example, get_learn_guide_cp_projects, ) +from settings_required import settings_required os.makedirs("generated_images", exist_ok=True) @@ -66,6 +67,7 @@ def asset_path(asset_name): "py": file_icon, "mpy": file_icon, "txt": file_empty_icon, + "toml": file_icon, "bmp": file_image_icon, "wav": file_music_icon, "mp3": file_music_icon, @@ -78,15 +80,17 @@ def asset_path(asset_name): } # If this is not done, the images fail to load in the subprocesses. -for file_icon in FILE_TYPE_ICON_MAP.values(): - file_icon.load() +for _file_icon in FILE_TYPE_ICON_MAP.values(): + _file_icon.load() def generate_requirement_image( project_files, libs, image_name -): # pylint: disable=too-many-statements +): # pylint: disable=too-many-statements, too-many-locals """Generate a single requirement image""" + context = {"added_settings_toml": False} + def make_line( requirement_name, position=(0, 0), icon=None, hidden=False, triangle_icon=None ): # pylint: disable=too-many-branches @@ -159,7 +163,8 @@ def make_line( font=font, ) - def make_header(position, project_files): + def make_header(position, project_files, files_and_libs): + # pylint: disable=too-many-locals # Static files make_line( "CIRCUITPY", @@ -194,6 +199,21 @@ def make_header(position, project_files): icon=file_icon, ) + # TODO: Add settings.toml if it's needed + + if settings_required(files_and_libs): + make_line( + "settings.toml", + (position[0] + INDENT_SIZE * 2, position[1] + (LINE_SPACING * 6)), + icon=file_icon, + ) + context["added_settings_toml"] = True + + if project_files: + print(image_name) + print(project_files) + print("=============") + # dynamic files from project dir in learn guide repo rows_added = 0 project_files_to_draw = [] @@ -210,13 +230,18 @@ def make_header(position, project_files): if ".circuitpython.skip-screenshot" not in cur_file[1]: project_folders_to_draw[cur_file[0]] = cur_file[1] + begin_y_offset = 7 if context["added_settings_toml"] else 6 for i, file in enumerate(sorted(project_files_to_draw)): cur_file_extension = file.split(".")[-1] cur_file_icon = FILE_TYPE_ICON_MAP.get(cur_file_extension, file_empty_icon) + make_line( file, - (position[0] + INDENT_SIZE * 2, position[1] + (LINE_SPACING * (6 + i))), + ( + position[0] + INDENT_SIZE * 2, + position[1] + (LINE_SPACING * (begin_y_offset + i)), + ), icon=cur_file_icon, ) rows_added += 1 @@ -229,7 +254,8 @@ def make_header(position, project_files): position[0] + INDENT_SIZE * 2, position[1] + ( - LINE_SPACING * (6 + i + len(project_files_to_draw) + extra_rows) + LINE_SPACING + * (begin_y_offset + i + len(project_files_to_draw) + extra_rows) ), ), triangle_icon=down_triangle, @@ -246,7 +272,7 @@ def make_header(position, project_files): sub_file, ( position[0] + INDENT_SIZE * 3, - position[1] + (LINE_SPACING * (6 + rows_added)), + position[1] + (LINE_SPACING * (begin_y_offset + rows_added)), ), triangle_icon=triangle_icon, icon=cur_file_icon, @@ -257,7 +283,7 @@ def make_header(position, project_files): "lib", ( position[0] + INDENT_SIZE * 2, - position[1] + (LINE_SPACING * (5 + rows_added + 1)), + position[1] + (LINE_SPACING * ((begin_y_offset - 1) + rows_added + 1)), ), triangle_icon=down_triangle, ) @@ -333,11 +359,20 @@ def make_libraries(libraries, position): triangle_icon = right_triangle make_line( lib_name, - (position[0] + INDENT_SIZE * 3, position[1] + (LINE_SPACING * i)), + ( + position[0] + INDENT_SIZE * 3, + position[1] + + ( + LINE_SPACING + * (i + (1 if context["added_settings_toml"] else 0)) + ), + ), triangle_icon=triangle_icon, ) final_list_to_render = sort_libraries(libs) + if settings_required(final_list_to_render): + context["added_settings_toml"] = True if "code.py" in project_files: project_files.remove("code.py") @@ -352,16 +387,20 @@ def make_libraries(libraries, position): + 7 * LINE_SPACING + len(final_list_to_render) * LINE_SPACING + (project_files_count) * LINE_SPACING + + (1 if context["added_settings_toml"] else 0) * LINE_SPACING ) img = Image.new("RGB", (OUT_WIDTH, image_height), "#303030") draw = ImageDraw.Draw(img) make_background_highlights( - 7 + len(final_list_to_render) + project_files_count, + 7 + + len(final_list_to_render) + + project_files_count + + (1 if context["added_settings_toml"] else 0), offset=(PADDING, PADDING), ) - - make_header((PADDING, PADDING), project_files) + print(f"fltr: {final_list_to_render}") + make_header((PADDING, PADDING), project_files, final_list_to_render) make_libraries( final_list_to_render, (PADDING, PADDING + (LINE_SPACING * (7 + project_files_count))), diff --git a/settings_required.py b/settings_required.py new file mode 100644 index 0000000..e7184ee --- /dev/null +++ b/settings_required.py @@ -0,0 +1,37 @@ +# SPDX-FileCopyrightText: 2023 Tim C +# SPDX-License-Identifier: MIT + +""" +Utility function to check whether settings.toml file should be rendered for a project. +Based on whether it uses certain libraries or not. +""" + + +LIBRARIES_THAT_REQUIRE_SETTINGS = [ + "adafruit_requests.mpy", + "adafruit_esp32spi", + "adafruit_minimqtt", + "adafruit_portalbase", + "adafruit_azureiot", +] + + +def settings_required(files_and_libs): + """ + Returns True if the project needs ot have a settings.toml file + + :param files_and_libs list: a List of all files and libraries used in the project + """ + + if "settings.toml" in files_and_libs: + # settings.toml file is already in the files so we don't need to add it again + return False + + # if any of the libraries that require settings.toml are included in this project + if any( + libs_that_require_settings in files_and_libs + for libs_that_require_settings in LIBRARIES_THAT_REQUIRE_SETTINGS + ): + return True + + return False From ee7184f997fa328b9ae051a6b091c7d92bc1241b Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 6 Mar 2024 18:35:22 -0600 Subject: [PATCH 15/38] single guide screenshots. add /sd/ dir to screenshot --- README.md | 8 +++++++ create_requirement_images.py | 43 +++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 6015add..46a4ff4 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,11 @@ With that pointed at a learn guide repo you can run: python3 create_requirement_images.py ``` It will create images in the `generated_images` directory. + +### Generate Single Learn Guide Image + +```shell +python3 create_requirement_images.py --guide [Learn Guide Name] +# OR +python3 create_requirement_images.py -g [Learn Guide Name] +``` diff --git a/create_requirement_images.py b/create_requirement_images.py index 4ea5ee9..40d4980 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -370,6 +370,13 @@ def make_libraries(libraries, position): triangle_icon=triangle_icon, ) + def make_sd_dir(position): + make_line( + "sd", + position, + triangle_icon=right_triangle, + ) + final_list_to_render = sort_libraries(libs) if settings_required(final_list_to_render): context["added_settings_toml"] = True @@ -388,6 +395,7 @@ def make_libraries(libraries, position): + len(final_list_to_render) * LINE_SPACING + (project_files_count) * LINE_SPACING + (1 if context["added_settings_toml"] else 0) * LINE_SPACING + + 1 * LINE_SPACING # /sd/ dir ) img = Image.new("RGB", (OUT_WIDTH, image_height), "#303030") draw = ImageDraw.Draw(img) @@ -396,15 +404,23 @@ def make_libraries(libraries, position): 7 + len(final_list_to_render) + project_files_count - + (1 if context["added_settings_toml"] else 0), + + (1 if context["added_settings_toml"] else 0) + + 1, # for /sd/ dir offset=(PADDING, PADDING), ) print(f"fltr: {final_list_to_render}") make_header((PADDING, PADDING), project_files, final_list_to_render) - make_libraries( - final_list_to_render, - (PADDING, PADDING + (LINE_SPACING * (7 + project_files_count))), + _libraries_position = ( + PADDING, + PADDING + (LINE_SPACING * (7 + project_files_count)), ) + make_libraries(final_list_to_render, _libraries_position) + _sd_dir_position = ( + 76, + PADDING + + (LINE_SPACING * (7 + project_files_count + len(final_list_to_render))), + ) + make_sd_dir(_sd_dir_position) img.save("generated_images/{}.png".format(image_name)) @@ -440,13 +456,20 @@ def cli(ctx): @cli.command() -def learn(): +@click.option( + "-g", "--guide", help="Guide Name of a single Learn Guide to generate an image for." +) +def learn(guide=None): """Generate images for a learn-style repo""" - with Pool() as pool: - for _ in pool.imap( - generate_learn_requirement_image, get_learn_guide_cp_projects() - ): - pass + if guide is None: + with Pool() as pool: + for _ in pool.imap( + generate_learn_requirement_image, get_learn_guide_cp_projects() + ): + pass + else: + print(f"generating image for single guide: {guide}") + generate_learn_requirement_image(guide) @cli.command() From 5963729c38061a8cb50550db44a8922734ca8ff6 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 12 Sep 2024 11:49:53 -0500 Subject: [PATCH 16/38] fix for projects with only code.py --- README.md | 11 +++++++++-- create_requirement_images.py | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 46a4ff4..2afc08b 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,14 @@ It will create images in the `generated_images` directory. ### Generate Single Learn Guide Image ```shell -python3 create_requirement_images.py --guide [Learn Guide Name] +python3 create_requirement_images.py learn --guide [Learn Guide Name] # OR -python3 create_requirement_images.py -g [Learn Guide Name] +python3 create_requirement_images.py learn -g [Learn Guide Name] ``` + +### Help Command +The help command will list all possible commands and arguments. + +```shell +python3 create_requirement_images.py --help +``` \ No newline at end of file diff --git a/create_requirement_images.py b/create_requirement_images.py index 40d4980..fd4e127 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -415,6 +415,10 @@ def make_sd_dir(position): PADDING + (LINE_SPACING * (7 + project_files_count)), ) make_libraries(final_list_to_render, _libraries_position) + + if project_files_count == 0: + project_files_count = 1 + _sd_dir_position = ( 76, PADDING From a9678177311aeedaeb9e4a6812ddca767132f806 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 12 Sep 2024 11:59:41 -0500 Subject: [PATCH 17/38] use upload-artifacts v4 --- .github/workflows/build-images.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images.yml index 64022c0..cb67b70 100644 --- a/.github/workflows/build-images.yml +++ b/.github/workflows/build-images.yml @@ -16,7 +16,7 @@ jobs: - run: python3 -mpip install -r requirements.txt - run: git clone --depth=1 https://github.com/adafruit/Adafruit_Learning_System_Guides learn - run: env LEARN_GUIDE_REPO=learn/ python3 create_requirement_images.py - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 with: name: images path: generated_images From 53e0a1a7c0d87ee665d22a08480db71ee48aa5aa Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 12 Sep 2024 13:31:04 -0500 Subject: [PATCH 18/38] fix SD position logic to account for settings.toml. Fix update pre-commit hooks to newer versions and fix issues flagged by new versions. --- .gitignore | 12 ++++++++++++ .pre-commit-config.yaml | 4 ++-- README.md | 2 +- create_requirement_images.py | 13 +++++-------- get_imports.py | 8 ++++---- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 7515470..ad2a4eb 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,15 @@ __pycache__ latest_bundle_data.json latest_bundle_tag.json generated_images + +# Virtual environment-specific files +.env +.venv + +# MacOS-specific files +*.DS_Store + +# IDE-specific files +.idea +.vscode +*~ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2e92c2a..ddf2cd3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ repos: hooks: - id: black - repo: https://github.com/fsfe/reuse-tool - rev: v0.12.1 + rev: v1.1.2 hooks: - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks @@ -18,7 +18,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: pylint-2.7.1 + rev: v3.2.7 hooks: - id: pylint name: pylint (library code) diff --git a/README.md b/README.md index 2afc08b..80e616d 100644 --- a/README.md +++ b/README.md @@ -30,4 +30,4 @@ The help command will list all possible commands and arguments. ```shell python3 create_requirement_images.py --help -``` \ No newline at end of file +``` diff --git a/create_requirement_images.py b/create_requirement_images.py index fd4e127..15037a9 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -38,9 +38,8 @@ TEXT_COLOR = "#B0B0B0" HIDDEN_TEXT_COLOR = "#808080" -f = open("latest_bundle_data.json", "r") -bundle_data = json.load(f) -f.close() +with open("latest_bundle_data.json", "r", encoding="utf-8") as f: + bundle_data = json.load(f) def asset_path(asset_name): @@ -416,17 +415,15 @@ def make_sd_dir(position): ) make_libraries(final_list_to_render, _libraries_position) - if project_files_count == 0: - project_files_count = 1 - _sd_dir_position = ( 76, PADDING - + (LINE_SPACING * (7 + project_files_count + len(final_list_to_render))), + + (LINE_SPACING * (7 + project_files_count + len(final_list_to_render))) + + (1 if context["added_settings_toml"] else 0) * LINE_SPACING, ) make_sd_dir(_sd_dir_position) - img.save("generated_images/{}.png".format(image_name)) + img.save(f"generated_images/{image_name}.png") def generate_learn_requirement_image( # pylint: disable=invalid-name diff --git a/get_imports.py b/get_imports.py index d4b2ad8..ea6a03e 100644 --- a/get_imports.py +++ b/get_imports.py @@ -116,14 +116,14 @@ def ensure_latest_bundle(): ensure_latest_bundle() -with open("latest_bundle_data.json", "r") as f: +with open("latest_bundle_data.json", "r", encoding="utf-8") as f: bundle_data = json.load(f) def get_files_for_project(project_name): """Get the set of files for a learn project""" found_files = set() - project_dir = "{}/{}/".format(LEARN_GUIDE_REPO, project_name) + project_dir = f"{LEARN_GUIDE_REPO}/{project_name}/" full_tree = os.walk(project_dir) root_level = next(full_tree) @@ -153,11 +153,11 @@ def get_libs_for_project(project_name): """Get the set of libraries for a learn project""" found_libs = set() found_imports = [] - project_dir = "{}{}/".format(LEARN_GUIDE_REPO, project_name) + project_dir = f"{LEARN_GUIDE_REPO}{project_name}/" for file in os.listdir(project_dir): if file.endswith(".py"): - found_imports = findimports.find_imports("{}{}".format(project_dir, file)) + found_imports = findimports.find_imports(f"{project_dir}{file}") for cur_import in found_imports: cur_lib = cur_import.name.split(".")[0] From 84e484722d602a23eee60f363b9691630961ba6a Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Sep 2024 09:28:44 -0500 Subject: [PATCH 19/38] fix duplicate lib dirs --- create_requirement_images.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/create_requirement_images.py b/create_requirement_images.py index 40d4980..0a3f420 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -317,7 +317,17 @@ def get_dependencies(libraries): lib_name = libraries_to_check[0] del libraries_to_check[0] - lib_obj = bundle_data[lib_name] + try: + lib_obj = bundle_data[lib_name] + except KeyError: + # Library isn't in bundle, so we don't know about its + # dependencies. + if "." in lib_name: + file_list.add(lib_name) + else: + package_list.add(lib_name) + continue + for dep_name in lib_obj["dependencies"]: libraries_to_check.append(dep_name) dep_obj = bundle_data[dep_name] @@ -377,6 +387,29 @@ def make_sd_dir(position): triangle_icon=right_triangle, ) + def filter_custom_project_libs(project_file_set): + """ + Find and remove the custom project lib folder. + Returns a tuple with the contents of the custom project lib folder + which will in turn get included in the libraries list that the + tool uses to generate the "main" lib folder in the screenshot. + """ + _custom_libs = None + remove_files = [] + for file in project_file_set: + if not isinstance(file, tuple): + continue + if file[0] == "lib": + _custom_libs = file[1] + remove_files.append(file) + for file in remove_files: + project_file_set.remove(file) + return _custom_libs + + custom_libs = filter_custom_project_libs(project_files) + libs_list = list(libs) + libs_list.extend(custom_libs) + libs = set(libs_list) final_list_to_render = sort_libraries(libs) if settings_required(final_list_to_render): context["added_settings_toml"] = True From 027b248d31e52376d9e4c113f1fa56d09061853d Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Sep 2024 11:50:28 -0500 Subject: [PATCH 20/38] include community bundle libraries --- create_requirement_images.py | 21 ++++++++++-- get_imports.py | 65 ++++++++++++++++++++---------------- 2 files changed, 55 insertions(+), 31 deletions(-) diff --git a/create_requirement_images.py b/create_requirement_images.py index 40d4980..be40a75 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -42,6 +42,10 @@ bundle_data = json.load(f) f.close() +f = open("latest_community_bundle_data.json", "r") +community_bundle_data = json.load(f) +f.close() + def asset_path(asset_name): """Return the location of a file shipped with the screenshot maker""" @@ -317,10 +321,23 @@ def get_dependencies(libraries): lib_name = libraries_to_check[0] del libraries_to_check[0] - lib_obj = bundle_data[lib_name] + if lib_name in bundle_data: + lib_obj = bundle_data[lib_name] + bundle_used = bundle_data + elif lib_name in community_bundle_data: + lib_obj = community_bundle_data[lib_name] + bundle_used = community_bundle_data + else: + # handle lib that is not in any known bundle + if "." in lib_name: + file_list.add(lib_name) + else: + package_list.add(lib_name) + continue + for dep_name in lib_obj["dependencies"]: libraries_to_check.append(dep_name) - dep_obj = bundle_data[dep_name] + dep_obj = bundle_used[dep_name] if dep_obj["package"]: package_list.add(dep_name) else: diff --git a/get_imports.py b/get_imports.py index d4b2ad8..65bc21f 100644 --- a/get_imports.py +++ b/get_imports.py @@ -13,8 +13,14 @@ import requests -BUNDLE_DATA = "latest_bundle_data.json" -BUNDLE_TAG = "latest_bundle_tag.json" +ADAFRUIT_BUNDLE_DATA = "latest_bundle_data.json" +ADAFRUIT_BUNDLE_TAG = "latest_bundle_tag.json" + +COMMUNITY_BUNDLE_DATA = "latest_community_bundle_data.json" +COMMUNITY_BUNDLE_TAG = "latest_community_bundle_tag.json" + +ADAFRUIT_BUNDLE_S3_URL = "https://adafruit-circuit-python.s3.amazonaws.com/bundles/adafruit/adafruit-circuitpython-bundle-{tag}.json" +COMMUNITY_BUNDLE_S3_URL = "https://adafruit-circuit-python.s3.amazonaws.com/bundles/community/circuitpython-community-bundle-{tag}.json" LEARN_GUIDE_REPO = os.environ.get( "LEARN_GUIDE_REPO", "../Adafruit_Learning_System_Guides/" @@ -36,18 +42,15 @@ SHOWN_FILETYPES_EXAMPLE = [s for s in SHOWN_FILETYPES if s != "py"] -def get_bundle(tag): - """Download the given bundle's data to BUNDLE_DATA""" - url = f"https://adafruit-circuit-python.s3.amazonaws.com/bundles/adafruit/adafruit-circuitpython-bundle-{tag}.json" # pylint: disable=line-too-long - print(f"get bundle metadata from {url}") - r = requests.get(url) - with open(BUNDLE_DATA, "wb") as bundle_file: +def get_bundle(bundle_url, bundle_data_file): + """Download the Adafruit and Community bundles data""" + #url = f"https://adafruit-circuit-python.s3.amazonaws.com/bundles/adafruit/adafruit-circuitpython-bundle-{tag}.json" # pylint: disable=line-too-long + print(f"get bundle metadata from {bundle_url}") + r = requests.get(bundle_url) + with open(bundle_data_file, "wb") as bundle_file: bundle_file.write(r.content) -LATEST_BUNDLE_VERSION = "" - - def get_latest_release_from_url(url): """ Find the tag name of the latest release by using HTTP HEAD and decoding the redirect. @@ -65,44 +68,40 @@ def get_latest_release_from_url(url): return tag -def get_latest_tag(): +def get_latest_tag(repo_url): """ Find the value of the latest tag for the Adafruit CircuitPython library bundle. :return: The most recent tag value for the project. """ - global LATEST_BUNDLE_VERSION # pylint: disable=global-statement - if LATEST_BUNDLE_VERSION == "": - LATEST_BUNDLE_VERSION = get_latest_release_from_url( - "https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases/latest" - ) - return LATEST_BUNDLE_VERSION + + return get_latest_release_from_url(repo_url) -def ensure_latest_bundle(): +def ensure_latest_bundle(bundle_url, bundle_s3_url, bundle_tag_file, bundle_data_file): """ Ensure that there's a copy of the latest library bundle available so circup can check the metadata contained therein. """ print("Checking for library updates.") - tag = get_latest_tag() + tag = get_latest_tag(bundle_url) old_tag = "0" - if os.path.isfile(BUNDLE_TAG): - with open(BUNDLE_TAG, encoding="utf-8") as data: + if os.path.isfile(bundle_tag_file): + with open(bundle_tag_file, encoding="utf-8") as data: try: old_tag = json.load(data)["tag"] except json.decoder.JSONDecodeError as _: # Sometimes (why?) the JSON file becomes corrupt. In which case # log it and carry on as if setting up for first time. - print(f"Could not parse {BUNDLE_TAG:r}") + print(f"Could not parse {bundle_tag_file:r}") if tag > old_tag: print(f"New version available {tag}.") try: - get_bundle(tag) - with open(BUNDLE_TAG, "w", encoding="utf-8") as data: + get_bundle(bundle_s3_url.replace("{tag}", tag), bundle_data_file) + with open(bundle_tag_file, "w", encoding="utf-8") as data: json.dump({"tag": tag}, data) except requests.exceptions.HTTPError as _: - # See #20 for reason this this + # See #20 for reason this print( ( "There was a problem downloading the bundle. " @@ -114,11 +113,19 @@ def ensure_latest_bundle(): print(f"Current library bundle up to date {tag}") -ensure_latest_bundle() +ensure_latest_bundle("https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases/latest", + ADAFRUIT_BUNDLE_S3_URL, + ADAFRUIT_BUNDLE_TAG, ADAFRUIT_BUNDLE_DATA) +ensure_latest_bundle("https://github.com/adafruit/CircuitPython_Community_Bundle/releases/latest", + COMMUNITY_BUNDLE_S3_URL, + COMMUNITY_BUNDLE_TAG, COMMUNITY_BUNDLE_DATA) -with open("latest_bundle_data.json", "r") as f: +with open(ADAFRUIT_BUNDLE_DATA, "r") as f: bundle_data = json.load(f) +with open(COMMUNITY_BUNDLE_DATA, "r") as f: + community_bundle_data = json.load(f) + def get_files_for_project(project_name): """Get the set of files for a learn project""" @@ -161,7 +168,7 @@ def get_libs_for_project(project_name): for cur_import in found_imports: cur_lib = cur_import.name.split(".")[0] - if cur_lib in bundle_data: + if cur_lib in bundle_data or cur_lib in community_bundle_data: found_libs.add(cur_lib) return found_libs From 7be5d5292277dfd2bce74913791df10fbc37caa4 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Sep 2024 12:04:08 -0500 Subject: [PATCH 21/38] try newer OS in build-images task container --- .github/workflows/build-images.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images.yml index cb67b70..ed9e3d3 100644 --- a/.github/workflows/build-images.yml +++ b/.github/workflows/build-images.yml @@ -10,7 +10,7 @@ on: jobs: build-images: - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v2 - run: python3 -mpip install -r requirements.txt From 0c119c2cb00c407bcde1ed9087365e6f9cef0550 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Sep 2024 12:06:18 -0500 Subject: [PATCH 22/38] use venv --- .github/workflows/build-images.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images.yml index ed9e3d3..74fe44d 100644 --- a/.github/workflows/build-images.yml +++ b/.github/workflows/build-images.yml @@ -13,6 +13,8 @@ jobs: runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v2 + - run: python3 -m venv build_images_venv + - run: source build_images_venv/bin/activate - run: python3 -mpip install -r requirements.txt - run: git clone --depth=1 https://github.com/adafruit/Adafruit_Learning_System_Guides learn - run: env LEARN_GUIDE_REPO=learn/ python3 create_requirement_images.py From 5804ae99fd351debc6355b5a22a54cfeabc763c0 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Sep 2024 12:09:23 -0500 Subject: [PATCH 23/38] fix venv activate --- .github/workflows/build-images.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images.yml index 74fe44d..8e5b346 100644 --- a/.github/workflows/build-images.yml +++ b/.github/workflows/build-images.yml @@ -14,7 +14,10 @@ jobs: steps: - uses: actions/checkout@v2 - run: python3 -m venv build_images_venv - - run: source build_images_venv/bin/activate + - name: Activate virtualenv + run: | + . .build_images_venv/bin/activate + echo PATH=$PATH >> $GITHUB_ENV - run: python3 -mpip install -r requirements.txt - run: git clone --depth=1 https://github.com/adafruit/Adafruit_Learning_System_Guides learn - run: env LEARN_GUIDE_REPO=learn/ python3 create_requirement_images.py From 7854e8069ef575c640fd5ee7987c4a9550871957 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Sep 2024 12:10:07 -0500 Subject: [PATCH 24/38] fix venv path --- .github/workflows/build-images.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images.yml index 8e5b346..813f89c 100644 --- a/.github/workflows/build-images.yml +++ b/.github/workflows/build-images.yml @@ -16,7 +16,7 @@ jobs: - run: python3 -m venv build_images_venv - name: Activate virtualenv run: | - . .build_images_venv/bin/activate + . build_images_venv/bin/activate echo PATH=$PATH >> $GITHUB_ENV - run: python3 -mpip install -r requirements.txt - run: git clone --depth=1 https://github.com/adafruit/Adafruit_Learning_System_Guides learn From a356a51b287d5527504a221ad80e42aa4b51a881 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Sep 2024 12:12:24 -0500 Subject: [PATCH 25/38] add learn command to task --- .github/workflows/build-images.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images.yml index 813f89c..ebfb537 100644 --- a/.github/workflows/build-images.yml +++ b/.github/workflows/build-images.yml @@ -20,7 +20,7 @@ jobs: echo PATH=$PATH >> $GITHUB_ENV - run: python3 -mpip install -r requirements.txt - run: git clone --depth=1 https://github.com/adafruit/Adafruit_Learning_System_Guides learn - - run: env LEARN_GUIDE_REPO=learn/ python3 create_requirement_images.py + - run: env LEARN_GUIDE_REPO=learn/ python3 create_requirement_images.py learn - uses: actions/upload-artifact@v4 with: name: images From c365b948484d550b7bac4cb448e9c2aa23075679 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Sep 2024 12:16:25 -0500 Subject: [PATCH 26/38] revert unneeded subcommand. add new jsons to gitignore. return empty tuple instead of None if no custom libs --- .github/workflows/build-images.yml | 2 +- .gitignore | 2 ++ create_requirement_images.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images.yml index ebfb537..813f89c 100644 --- a/.github/workflows/build-images.yml +++ b/.github/workflows/build-images.yml @@ -20,7 +20,7 @@ jobs: echo PATH=$PATH >> $GITHUB_ENV - run: python3 -mpip install -r requirements.txt - run: git clone --depth=1 https://github.com/adafruit/Adafruit_Learning_System_Guides learn - - run: env LEARN_GUIDE_REPO=learn/ python3 create_requirement_images.py learn + - run: env LEARN_GUIDE_REPO=learn/ python3 create_requirement_images.py - uses: actions/upload-artifact@v4 with: name: images diff --git a/.gitignore b/.gitignore index ad2a4eb..c4c0d82 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ __pycache__ latest_bundle_data.json latest_bundle_tag.json +latest_community_bundle_data.json +latest_community_bundle_tag.json generated_images # Virtual environment-specific files diff --git a/create_requirement_images.py b/create_requirement_images.py index d9d32f7..021a3a4 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -393,7 +393,7 @@ def filter_custom_project_libs(project_file_set): which will in turn get included in the libraries list that the tool uses to generate the "main" lib folder in the screenshot. """ - _custom_libs = None + _custom_libs = tuple() remove_files = [] for file in project_file_set: if not isinstance(file, tuple): From a2b36ed1df542cc66e939ebc10e5a46627959c3f Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Sep 2024 12:26:06 -0500 Subject: [PATCH 27/38] use if/else instead of try/except --- create_requirement_images.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/create_requirement_images.py b/create_requirement_images.py index 021a3a4..b9b185a 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -316,9 +316,9 @@ def get_dependencies(libraries): lib_name = libraries_to_check[0] del libraries_to_check[0] - try: + if lib_name in bundle_data: lib_obj = bundle_data[lib_name] - except KeyError: + else: # Library isn't in bundle, so we don't know about its # dependencies. if "." in lib_name: From 662fa662c004022eb73218209bfcfae9c64848a2 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Sep 2024 12:36:27 -0500 Subject: [PATCH 28/38] resolve merge main conflicts. add new json files to gitignore. resolve pylint issues --- .gitignore | 2 ++ create_requirement_images.py | 5 ++--- get_imports.py | 25 +++++++++++++++---------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index ad2a4eb..c4c0d82 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ __pycache__ latest_bundle_data.json latest_bundle_tag.json +latest_community_bundle_data.json +latest_community_bundle_tag.json generated_images # Virtual environment-specific files diff --git a/create_requirement_images.py b/create_requirement_images.py index 38bbd04..0f646ae 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -41,9 +41,8 @@ with open("latest_bundle_data.json", "r", encoding="utf-8") as f: bundle_data = json.load(f) -f = open("latest_community_bundle_data.json", "r") -community_bundle_data = json.load(f) -f.close() +with open("latest_community_bundle_data.json", "r", encoding="utf-8") as f: + community_bundle_data = json.load(f) def asset_path(asset_name): diff --git a/get_imports.py b/get_imports.py index adb5b22..85f4ce0 100644 --- a/get_imports.py +++ b/get_imports.py @@ -19,8 +19,8 @@ COMMUNITY_BUNDLE_DATA = "latest_community_bundle_data.json" COMMUNITY_BUNDLE_TAG = "latest_community_bundle_tag.json" -ADAFRUIT_BUNDLE_S3_URL = "https://adafruit-circuit-python.s3.amazonaws.com/bundles/adafruit/adafruit-circuitpython-bundle-{tag}.json" -COMMUNITY_BUNDLE_S3_URL = "https://adafruit-circuit-python.s3.amazonaws.com/bundles/community/circuitpython-community-bundle-{tag}.json" +ADAFRUIT_BUNDLE_S3_URL = "https://adafruit-circuit-python.s3.amazonaws.com/bundles/adafruit/adafruit-circuitpython-bundle-{tag}.json" # pylint: disable=line-too-long +COMMUNITY_BUNDLE_S3_URL = "https://adafruit-circuit-python.s3.amazonaws.com/bundles/community/circuitpython-community-bundle-{tag}.json" # pylint: disable=line-too-long LEARN_GUIDE_REPO = os.environ.get( "LEARN_GUIDE_REPO", "../Adafruit_Learning_System_Guides/" @@ -44,7 +44,6 @@ def get_bundle(bundle_url, bundle_data_file): """Download the Adafruit and Community bundles data""" - #url = f"https://adafruit-circuit-python.s3.amazonaws.com/bundles/adafruit/adafruit-circuitpython-bundle-{tag}.json" # pylint: disable=line-too-long print(f"get bundle metadata from {bundle_url}") r = requests.get(bundle_url) with open(bundle_data_file, "wb") as bundle_file: @@ -113,17 +112,23 @@ def ensure_latest_bundle(bundle_url, bundle_s3_url, bundle_tag_file, bundle_data print(f"Current library bundle up to date {tag}") -ensure_latest_bundle("https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases/latest", - ADAFRUIT_BUNDLE_S3_URL, - ADAFRUIT_BUNDLE_TAG, ADAFRUIT_BUNDLE_DATA) -ensure_latest_bundle("https://github.com/adafruit/CircuitPython_Community_Bundle/releases/latest", - COMMUNITY_BUNDLE_S3_URL, - COMMUNITY_BUNDLE_TAG, COMMUNITY_BUNDLE_DATA) +ensure_latest_bundle( + "https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases/latest", + ADAFRUIT_BUNDLE_S3_URL, + ADAFRUIT_BUNDLE_TAG, + ADAFRUIT_BUNDLE_DATA, +) +ensure_latest_bundle( + "https://github.com/adafruit/CircuitPython_Community_Bundle/releases/latest", + COMMUNITY_BUNDLE_S3_URL, + COMMUNITY_BUNDLE_TAG, + COMMUNITY_BUNDLE_DATA, +) with open(ADAFRUIT_BUNDLE_DATA, "r", encoding="utf-8") as f: bundle_data = json.load(f) -with open(COMMUNITY_BUNDLE_DATA, "r") as f: +with open(COMMUNITY_BUNDLE_DATA, "r", encoding="utf-8") as f: community_bundle_data = json.load(f) From 8c99fccf2190beb8677857dcaf164adb2644dca0 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Sep 2024 16:40:56 -0500 Subject: [PATCH 29/38] Fold directories to hide contents if they have too many files --- create_requirement_images.py | 11 +++++++---- get_imports.py | 7 +++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/create_requirement_images.py b/create_requirement_images.py index 15037a9..0c9fe39 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -163,7 +163,7 @@ def make_line( ) def make_header(position, project_files, files_and_libs): - # pylint: disable=too-many-locals + # pylint: disable=too-many-locals, too-many-branches # Static files make_line( "CIRCUITPY", @@ -198,8 +198,7 @@ def make_header(position, project_files, files_and_libs): icon=file_icon, ) - # TODO: Add settings.toml if it's needed - + # Add settings.toml if it's needed if settings_required(files_and_libs): make_line( "settings.toml", @@ -247,6 +246,10 @@ def make_header(position, project_files, files_and_libs): extra_rows = 0 for i, file in enumerate(sorted(project_folders_to_draw.keys())): + if len(project_folders_to_draw[file]) > 0: + triangle_to_use = down_triangle + else: + triangle_to_use = right_triangle make_line( file, ( @@ -257,7 +260,7 @@ def make_header(position, project_files, files_and_libs): * (begin_y_offset + i + len(project_files_to_draw) + extra_rows) ), ), - triangle_icon=down_triangle, + triangle_icon=triangle_to_use, ) rows_added += 1 for sub_file in sorted(project_folders_to_draw[file]): diff --git a/get_imports.py b/get_imports.py index ea6a03e..46e9146 100644 --- a/get_imports.py +++ b/get_imports.py @@ -16,6 +16,8 @@ BUNDLE_DATA = "latest_bundle_data.json" BUNDLE_TAG = "latest_bundle_tag.json" +SUBDIRECTORY_FILECOUNT_LIMIT = 10 + LEARN_GUIDE_REPO = os.environ.get( "LEARN_GUIDE_REPO", "../Adafruit_Learning_System_Guides/" ) @@ -141,8 +143,9 @@ def get_files_for_project(project_name): if cur_tuple[0].split("/")[-1] == _dir: for _sub_dir in cur_tuple[1]: dir_tuple = (dir_tuple[0], dir_tuple[1] + (_sub_dir,)) - for _sub_file in cur_tuple[2]: - dir_tuple = (dir_tuple[0], dir_tuple[1] + (_sub_file,)) + if len(cur_tuple[2]) < SUBDIRECTORY_FILECOUNT_LIMIT: + for _sub_file in cur_tuple[2]: + dir_tuple = (dir_tuple[0], dir_tuple[1] + (_sub_file,)) # e.g. ("dir_name", ("file_1.txt", "file_2.txt")) found_files.add(dir_tuple) From 45d3387ae1d3d1937d209ea7ab3293efb5899e34 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 17 Dec 2024 10:30:51 -0600 Subject: [PATCH 30/38] PNG file icon. Find libraries one level deeper from wildcard import of file in learn project code --- create_requirement_images.py | 1 + get_imports.py | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/create_requirement_images.py b/create_requirement_images.py index 1f59017..2e495c3 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -71,6 +71,7 @@ def asset_path(asset_name): "txt": file_empty_icon, "toml": file_icon, "bmp": file_image_icon, + "png": file_image_icon, "wav": file_music_icon, "mp3": file_music_icon, "mid": file_music_icon, diff --git a/get_imports.py b/get_imports.py index 22d176c..812a49b 100644 --- a/get_imports.py +++ b/get_imports.py @@ -165,6 +165,7 @@ def get_files_for_project(project_name): def get_libs_for_project(project_name): + # pylint: disable=too-many-nested-blocks """Get the set of libraries for a learn project""" found_libs = set() found_imports = [] @@ -173,11 +174,23 @@ def get_libs_for_project(project_name): if file.endswith(".py"): found_imports = findimports.find_imports(f"{project_dir}{file}") - for cur_import in found_imports: cur_lib = cur_import.name.split(".")[0] if cur_lib in bundle_data or cur_lib in community_bundle_data: found_libs.add(cur_lib) + if cur_import.name.endswith(".*"): + filepath = os.path.join( + project_dir, "/".join(cur_import.name[:-2].split(".")) + ".py" + ) + if os.path.exists(filepath): + second_level_imports = findimports.find_imports(filepath) + for cur_second_level_import in second_level_imports: + cur_lib = cur_second_level_import.name.split(".")[0] + if ( + cur_lib in bundle_data + or cur_lib in community_bundle_data + ): + found_libs.add(cur_lib) return found_libs From 4f2c338fdc41f0d659276366673c136775628548 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 17 Dec 2024 10:59:59 -0600 Subject: [PATCH 31/38] os.path.join instead of string join --- get_imports.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/get_imports.py b/get_imports.py index 812a49b..3b3e62d 100644 --- a/get_imports.py +++ b/get_imports.py @@ -180,7 +180,8 @@ def get_libs_for_project(project_name): found_libs.add(cur_lib) if cur_import.name.endswith(".*"): filepath = os.path.join( - project_dir, "/".join(cur_import.name[:-2].split(".")) + ".py" + project_dir, + os.path.join(*cur_import.name[:-2].split(".")) + ".py", ) if os.path.exists(filepath): second_level_imports = findimports.find_imports(filepath) From 50776040224010ab6b67b5fc7eb371ce9a5db9c0 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 17 Dec 2024 11:02:51 -0600 Subject: [PATCH 32/38] wildcard import comment --- get_imports.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/get_imports.py b/get_imports.py index 3b3e62d..8858f52 100644 --- a/get_imports.py +++ b/get_imports.py @@ -178,6 +178,9 @@ def get_libs_for_project(project_name): cur_lib = cur_import.name.split(".")[0] if cur_lib in bundle_data or cur_lib in community_bundle_data: found_libs.add(cur_lib) + + # check if it's a wildcard import e.g. + # from module.submodule import * if cur_import.name.endswith(".*"): filepath = os.path.join( project_dir, From 0af6ff13a469d5944307258fe807ec2f696a8a0f Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 17 Dec 2024 11:22:45 -0600 Subject: [PATCH 33/38] wildcard import comment --- get_imports.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/get_imports.py b/get_imports.py index 8858f52..f4ef0ac 100644 --- a/get_imports.py +++ b/get_imports.py @@ -179,8 +179,7 @@ def get_libs_for_project(project_name): if cur_lib in bundle_data or cur_lib in community_bundle_data: found_libs.add(cur_lib) - # check if it's a wildcard import e.g. - # from module.submodule import * + # findimports returns import name in the form of ``foo.bar.*`` if cur_import.name.endswith(".*"): filepath = os.path.join( project_dir, From 6a95dd1c5499ba5ebab55c14c581af03c39ecf2d Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 17 Dec 2024 11:29:21 -0600 Subject: [PATCH 34/38] regular quotes --- get_imports.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get_imports.py b/get_imports.py index f4ef0ac..c8a3988 100644 --- a/get_imports.py +++ b/get_imports.py @@ -179,7 +179,7 @@ def get_libs_for_project(project_name): if cur_lib in bundle_data or cur_lib in community_bundle_data: found_libs.add(cur_lib) - # findimports returns import name in the form of ``foo.bar.*`` + # findimports returns import name in the form of "foo.bar.*" if cur_import.name.endswith(".*"): filepath = os.path.join( project_dir, From 17a7514daa9f642e476ea02a619e82e1fbb453df Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 19 Dec 2024 14:35:21 -0600 Subject: [PATCH 35/38] add connection_manager to settings.toml inclusions --- settings_required.py | 1 + 1 file changed, 1 insertion(+) diff --git a/settings_required.py b/settings_required.py index e7184ee..a27d3d3 100644 --- a/settings_required.py +++ b/settings_required.py @@ -13,6 +13,7 @@ "adafruit_minimqtt", "adafruit_portalbase", "adafruit_azureiot", + "adafruit_connection_manager", ] From 2f057dda25f7d5d78dda52d39fb8c767cba97782 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 21 Dec 2024 10:57:09 -0600 Subject: [PATCH 36/38] fix connection_manager with .mpy extension. add section to readme about generating single example image. --- README.md | 7 +++++++ settings_required.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 80e616d..dd644b5 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,13 @@ python3 create_requirement_images.py learn --guide [Learn Guide Name] python3 create_requirement_images.py learn -g [Learn Guide Name] ``` +### Generate Single Library Bundle Example Image +```shell +python3 create_requirement_images.py bundle [path to example].py +# e.g. +python3 create_requirement_images.py bundle Adafruit_CircuitPythonBundle/libraries/helpers/wiz/wiz_buttons_controller.py +``` + ### Help Command The help command will list all possible commands and arguments. diff --git a/settings_required.py b/settings_required.py index a27d3d3..287b8dc 100644 --- a/settings_required.py +++ b/settings_required.py @@ -13,7 +13,7 @@ "adafruit_minimqtt", "adafruit_portalbase", "adafruit_azureiot", - "adafruit_connection_manager", + "adafruit_connection_manager.mpy", ] From 257389f3e8796a0873de47ad861e26b24595b62f Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 14 Jan 2025 14:00:11 -0600 Subject: [PATCH 37/38] filter subdir files by shown type. omit directories if there are no shown file types inside of them. --- get_imports.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/get_imports.py b/get_imports.py index c8a3988..3442554 100644 --- a/get_imports.py +++ b/get_imports.py @@ -220,11 +220,15 @@ def get_files_for_example(example_path): for _sub_dir in cur_tuple[1]: dir_tuple = (dir_tuple[0], dir_tuple[1] + (_sub_dir,)) for _sub_file in cur_tuple[2]: - dir_tuple = (dir_tuple[0], dir_tuple[1] + (_sub_file,)) + if _sub_file.split(".")[-1] in SHOWN_FILETYPES_EXAMPLE: + dir_tuple = (dir_tuple[0], dir_tuple[1] + (_sub_file,)) # e.g. ("dir_name", ("file_1.txt", "file_2.txt")) - if ".circuitpython.skip-screenshot" not in dir_tuple[1]: + if ( + ".circuitpython.skip-screenshot" not in dir_tuple[1] + and len(dir_tuple[1]) > 0 + ): found_files.add(dir_tuple) return found_files From a6321c9529a5ddd1008c3568a30969c33241f63e Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 25 Feb 2025 19:55:27 -0600 Subject: [PATCH 38/38] update the list of shown filetypes. always show settings.toml --- create_requirement_images.py | 1 + get_imports.py | 12 ++++++++---- settings_required.py | 21 +++------------------ 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/create_requirement_images.py b/create_requirement_images.py index 2e495c3..e52fcf2 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -72,6 +72,7 @@ def asset_path(asset_name): "toml": file_icon, "bmp": file_image_icon, "png": file_image_icon, + "jpg": file_image_icon, "wav": file_music_icon, "mp3": file_music_icon, "mid": file_music_icon, diff --git a/get_imports.py b/get_imports.py index 3442554..e4de803 100644 --- a/get_imports.py +++ b/get_imports.py @@ -31,15 +31,19 @@ SHOWN_FILETYPES = [ "py", "mpy", + "txt", + "toml", "bmp", - "pcf", - "bdf", + "png", + "jpg", "wav", "mp3", "mid", - "json", - "txt", + "pcf", + "bdf", "csv", + "json", + "license", ] SHOWN_FILETYPES_EXAMPLE = [s for s in SHOWN_FILETYPES if s != "py"] diff --git a/settings_required.py b/settings_required.py index 287b8dc..b983f74 100644 --- a/settings_required.py +++ b/settings_required.py @@ -7,16 +7,6 @@ """ -LIBRARIES_THAT_REQUIRE_SETTINGS = [ - "adafruit_requests.mpy", - "adafruit_esp32spi", - "adafruit_minimqtt", - "adafruit_portalbase", - "adafruit_azureiot", - "adafruit_connection_manager.mpy", -] - - def settings_required(files_and_libs): """ Returns True if the project needs ot have a settings.toml file @@ -28,11 +18,6 @@ def settings_required(files_and_libs): # settings.toml file is already in the files so we don't need to add it again return False - # if any of the libraries that require settings.toml are included in this project - if any( - libs_that_require_settings in files_and_libs - for libs_that_require_settings in LIBRARIES_THAT_REQUIRE_SETTINGS - ): - return True - - return False + # always show settings.toml because it is created by default when + # circuitpython is loaded, and when storage.erase_filesystem() is called + return True