From 5963729c38061a8cb50550db44a8922734ca8ff6 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 12 Sep 2024 11:49:53 -0500 Subject: [PATCH 1/3] 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 2/3] 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 3/3] 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]