From 09d7e47fda1d39644a4ee075f5cd8c3f39f30f32 Mon Sep 17 00:00:00 2001 From: Jos Verlinde Date: Wed, 10 Jul 2024 23:26:02 +0200 Subject: [PATCH] chore: Cleanup and fix parsing errors in enrich.py and merge_docstubs.py Signed-off-by: Jos Verlinde --- .vscode/launch.json | 12 ++++++++---- src/stubber/codemod/enrich.py | 6 ++++++ src/stubber/publish/merge_docstubs.py | 12 ++++++++---- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 5d26e6a6..a5a1bb7c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,7 +13,6 @@ "cwd": "${workspaceFolder}", "args": [ "-VV", - "list", // "--board", // "SEEED_WIO_TERMINAL", // "PICO", @@ -41,9 +40,14 @@ "cwd": "${workspaceFolder}", "args": [ "-VV", - "get-mcu-stubs", - "--serial", - "/dev/ttyUSB0", + "merge", + "--version", + "preview", + "--port", + "esp8266", + // "get-mcu-stubs", + // "--serial", + // "/dev/ttyUSB0", // "get-frozen", // "--version", // "preview", diff --git a/src/stubber/codemod/enrich.py b/src/stubber/codemod/enrich.py index c644a24c..cc0c7b7d 100644 --- a/src/stubber/codemod/enrich.py +++ b/src/stubber/codemod/enrich.py @@ -6,6 +6,7 @@ from pathlib import Path from typing import Any, Dict, Optional +from libcst import ParserSyntaxError from libcst.codemod import CodemodContext, diff_code, exec_transform_with_prettyprint from libcst.tool import _default_config # type: ignore from mpflash.logger import log @@ -113,6 +114,7 @@ def enrich_folder( raise FileNotFoundError(f"Source {source_path} does not exist") if not docstub_path.exists(): raise FileNotFoundError(f"Docstub {docstub_path} does not exist") + log.debug(f"Enrich folder {source_path}.") count = 0 # list all the .py and .pyi files in the source folder if source_path.is_file(): @@ -138,6 +140,10 @@ def enrich_folder( # no docstub to enrich with if require_docstub: raise (FileNotFoundError(f"No doc-stub file found for {source_file}")) from e + except (Exception, ParserSyntaxError) as e: + log.error(f"Error parsing {source_file}") + log.exception(e) + continue # run black on the destination folder run_black(source_path) # DO NOT run Autoflake as this removes some relevant (unused) imports diff --git a/src/stubber/publish/merge_docstubs.py b/src/stubber/publish/merge_docstubs.py index fa9d7c56..a1416dfe 100644 --- a/src/stubber/publish/merge_docstubs.py +++ b/src/stubber/publish/merge_docstubs.py @@ -66,10 +66,14 @@ def merge_all_docstubs( log.info(f"skipping {merged_path.name}, no MCU stubs found in {board_path}") continue log.info(f"Merge {candidate['version']} docstubs with boardstubs to {merged_path.name}") - result = copy_and_merge_docstubs(board_path, merged_path, doc_path) - # Add methods from docstubs to the MCU stubs that do not exist in the MCU stubs - # Add the __call__ method to the machine.Pin and pyb.Pin class - add_machine_pin_call(merged_path, candidate["version"]) + try: + result = copy_and_merge_docstubs(board_path, merged_path, doc_path) + # Add methods from docstubs to the MCU stubs that do not exist in the MCU stubs + # Add the __call__ method to the machine.Pin and pyb.Pin class + add_machine_pin_call(merged_path, candidate["version"]) + except Exception as e: + log.error(f"Error parsing {candidate['version']} docstubs: {e}") + continue if result: merged += 1 log.info(f"merged {merged} of {len(candidates)} candidates")