From 7e54803edea0b24f0892129e4a66d39dd44da5b3 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 17 Oct 2025 18:25:41 -1000 Subject: [PATCH] update test --- esphome/analyze_memory/cli.py | 19 +++---- script/ci_memory_impact_comment.py | 82 ++++++++++++++++++------------ script/ci_memory_impact_extract.py | 30 +++++------ 3 files changed, 75 insertions(+), 56 deletions(-) diff --git a/esphome/analyze_memory/cli.py b/esphome/analyze_memory/cli.py index a2366430dd..5713eac94c 100644 --- a/esphome/analyze_memory/cli.py +++ b/esphome/analyze_memory/cli.py @@ -371,15 +371,16 @@ def main(): idedata = None for idedata_path in idedata_candidates: - if idedata_path.exists(): - try: - with open(idedata_path, encoding="utf-8") as f: - raw_data = json.load(f) - idedata = IDEData(raw_data) - print(f"Loaded idedata from: {idedata_path}", file=sys.stderr) - break - except (json.JSONDecodeError, OSError) as e: - print(f"Warning: Failed to load idedata: {e}", file=sys.stderr) + if not idedata_path.exists(): + continue + try: + with open(idedata_path, encoding="utf-8") as f: + raw_data = json.load(f) + idedata = IDEData(raw_data) + print(f"Loaded idedata from: {idedata_path}", file=sys.stderr) + break + except (json.JSONDecodeError, OSError) as e: + print(f"Warning: Failed to load idedata: {e}", file=sys.stderr) if not idedata: print( diff --git a/script/ci_memory_impact_comment.py b/script/ci_memory_impact_comment.py index 5a399639f5..4e3fbb9086 100755 --- a/script/ci_memory_impact_comment.py +++ b/script/ci_memory_impact_comment.py @@ -409,6 +409,54 @@ def find_existing_comment(pr_number: str) -> str | None: return None +def update_existing_comment(comment_id: str, comment_body: str) -> None: + """Update an existing comment. + + Args: + comment_id: Comment ID to update + comment_body: New comment body text + + Raises: + subprocess.CalledProcessError: If gh command fails + """ + print(f"DEBUG: Updating existing comment {comment_id}", file=sys.stderr) + result = subprocess.run( + [ + "gh", + "api", + f"/repos/{{owner}}/{{repo}}/issues/comments/{comment_id}", + "-X", + "PATCH", + "-f", + f"body={comment_body}", + ], + check=True, + capture_output=True, + text=True, + ) + print(f"DEBUG: Update response: {result.stdout}", file=sys.stderr) + + +def create_new_comment(pr_number: str, comment_body: str) -> None: + """Create a new PR comment. + + Args: + pr_number: PR number + comment_body: Comment body text + + Raises: + subprocess.CalledProcessError: If gh command fails + """ + print(f"DEBUG: Posting new comment on PR #{pr_number}", file=sys.stderr) + result = subprocess.run( + ["gh", "pr", "comment", pr_number, "--body", comment_body], + check=True, + capture_output=True, + text=True, + ) + print(f"DEBUG: Post response: {result.stdout}", file=sys.stderr) + + def post_or_update_comment(pr_number: str, comment_body: str) -> None: """Post a new comment or update existing one. @@ -423,39 +471,9 @@ def post_or_update_comment(pr_number: str, comment_body: str) -> None: existing_comment_id = find_existing_comment(pr_number) if existing_comment_id and existing_comment_id != "None": - # Update existing comment - print( - f"DEBUG: Updating existing comment {existing_comment_id}", - file=sys.stderr, - ) - result = subprocess.run( - [ - "gh", - "api", - f"/repos/{{owner}}/{{repo}}/issues/comments/{existing_comment_id}", - "-X", - "PATCH", - "-f", - f"body={comment_body}", - ], - check=True, - capture_output=True, - text=True, - ) - print(f"DEBUG: Update response: {result.stdout}", file=sys.stderr) + update_existing_comment(existing_comment_id, comment_body) else: - # Post new comment - print( - f"DEBUG: Posting new comment (existing_comment_id={existing_comment_id})", - file=sys.stderr, - ) - result = subprocess.run( - ["gh", "pr", "comment", pr_number, "--body", comment_body], - check=True, - capture_output=True, - text=True, - ) - print(f"DEBUG: Post response: {result.stdout}", file=sys.stderr) + create_new_comment(pr_number, comment_body) print("Comment posted/updated successfully", file=sys.stderr) diff --git a/script/ci_memory_impact_extract.py b/script/ci_memory_impact_extract.py index 17ac788ae3..77d59417e3 100755 --- a/script/ci_memory_impact_extract.py +++ b/script/ci_memory_impact_extract.py @@ -25,6 +25,8 @@ import sys sys.path.insert(0, str(Path(__file__).parent.parent)) # pylint: disable=wrong-import-position +from esphome.analyze_memory import MemoryAnalyzer +from esphome.platformio_api import IDEData from script.ci_helpers import write_github_output # Regex patterns for extracting memory usage from PlatformIO output @@ -85,9 +87,6 @@ def run_detailed_analysis(build_dir: str) -> dict | None: Returns: Dictionary with analysis results or None if analysis fails """ - from esphome.analyze_memory import MemoryAnalyzer - from esphome.platformio_api import IDEData - build_path = Path(build_dir) if not build_path.exists(): print(f"Build directory not found: {build_dir}", file=sys.stderr) @@ -120,18 +119,19 @@ def run_detailed_analysis(build_dir: str) -> dict | None: idedata = None for idedata_path in idedata_candidates: - if idedata_path.exists(): - try: - with open(idedata_path, encoding="utf-8") as f: - raw_data = json.load(f) - idedata = IDEData(raw_data) - print(f"Loaded idedata from: {idedata_path}", file=sys.stderr) - break - except (json.JSONDecodeError, OSError) as e: - print( - f"Warning: Failed to load idedata from {idedata_path}: {e}", - file=sys.stderr, - ) + if not idedata_path.exists(): + continue + try: + with open(idedata_path, encoding="utf-8") as f: + raw_data = json.load(f) + idedata = IDEData(raw_data) + print(f"Loaded idedata from: {idedata_path}", file=sys.stderr) + break + except (json.JSONDecodeError, OSError) as e: + print( + f"Warning: Failed to load idedata from {idedata_path}: {e}", + file=sys.stderr, + ) analyzer = MemoryAnalyzer(elf_path, idedata=idedata) components = analyzer.analyze()