Skip to content

Commit

Permalink
chore: Cleanup and fix parsing errors in enrich.py and merge_docstubs.py
Browse files Browse the repository at this point in the history
Signed-off-by: Jos Verlinde <Jos.Verlinde@microsoft.com>
  • Loading branch information
Josverl committed Jan 1, 2025
1 parent 5986207 commit 09d7e47
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
12 changes: 8 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"cwd": "${workspaceFolder}",
"args": [
"-VV",
"list",
// "--board",
// "SEEED_WIO_TERMINAL",
// "PICO",
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions src/stubber/codemod/enrich.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand All @@ -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
Expand Down
12 changes: 8 additions & 4 deletions src/stubber/publish/merge_docstubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 09d7e47

Please sign in to comment.