From 8cfd2a86c110e3ab580156d4914ee3257ee35692 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Oct 2025 23:22:09 -0700 Subject: [PATCH] Fix status checks: lint, format, typecheck, and tests (#8) * Initial plan * Initial assessment - identifying issues to fix Co-authored-by: arnavsacheti <36746504+arnavsacheti@users.noreply.github.com> * Fix type check and test issues to pass all status checks Co-authored-by: arnavsacheti <36746504+arnavsacheti@users.noreply.github.com> * Add coverage.xml to .gitignore and remove from tracking Co-authored-by: arnavsacheti <36746504+arnavsacheti@users.noreply.github.com> * Use more specific pattern for coverage.xml in .gitignore Co-authored-by: arnavsacheti <36746504+arnavsacheti@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: arnavsacheti <36746504+arnavsacheti@users.noreply.github.com> --- .gitignore | 1 + src/peakrdl_busdecoder/body/body.py | 4 +++- src/peakrdl_busdecoder/body/if_body.py | 3 ++- src/peakrdl_busdecoder/cpuif/apb3/apb3_cpuif.py | 1 + src/peakrdl_busdecoder/cpuif/apb4/apb4_cpuif.py | 1 + src/peakrdl_busdecoder/cpuif/axi4lite/axi4_lite_cpuif.py | 1 + .../cpuif/axi4lite/axi4_lite_cpuif_flat.py | 1 + src/peakrdl_busdecoder/decode_logic_gen.py | 7 +++++-- src/peakrdl_busdecoder/utils.py | 2 ++ tests/unit/test_unroll.py | 8 ++++---- 10 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index ac5e70c..2bfac04 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ **/*.pb **/.Xil **/.coverage.* +coverage.xml build/ dist/ diff --git a/src/peakrdl_busdecoder/body/body.py b/src/peakrdl_busdecoder/body/body.py index 203f325..9eff103 100644 --- a/src/peakrdl_busdecoder/body/body.py +++ b/src/peakrdl_busdecoder/body/body.py @@ -1,4 +1,6 @@ -from typing import Protocol, Self +from typing import Protocol + +from typing_extensions import Self class SupportsStr(Protocol): diff --git a/src/peakrdl_busdecoder/body/if_body.py b/src/peakrdl_busdecoder/body/if_body.py index 13d0f06..e7ccce0 100644 --- a/src/peakrdl_busdecoder/body/if_body.py +++ b/src/peakrdl_busdecoder/body/if_body.py @@ -2,7 +2,8 @@ from __future__ import annotations from textwrap import indent from types import EllipsisType -from typing import Self + +from typing_extensions import Self from .body import Body, SupportsStr diff --git a/src/peakrdl_busdecoder/cpuif/apb3/apb3_cpuif.py b/src/peakrdl_busdecoder/cpuif/apb3/apb3_cpuif.py index 92e6f84..db99c51 100644 --- a/src/peakrdl_busdecoder/cpuif/apb3/apb3_cpuif.py +++ b/src/peakrdl_busdecoder/cpuif/apb3/apb3_cpuif.py @@ -19,6 +19,7 @@ class APB3Cpuif(BaseCpuif): # Only add array dimensions if this should be treated as an array if self.check_is_array(child): + assert child.array_dimensions is not None return f"{base} {''.join(f'[{dim}]' for dim in child.array_dimensions)}" return base diff --git a/src/peakrdl_busdecoder/cpuif/apb4/apb4_cpuif.py b/src/peakrdl_busdecoder/cpuif/apb4/apb4_cpuif.py index 56de67e..a2ea70a 100644 --- a/src/peakrdl_busdecoder/cpuif/apb4/apb4_cpuif.py +++ b/src/peakrdl_busdecoder/cpuif/apb4/apb4_cpuif.py @@ -19,6 +19,7 @@ class APB4Cpuif(BaseCpuif): # Only add array dimensions if this should be treated as an array if self.check_is_array(child): + assert child.array_dimensions is not None return f"{base} {''.join(f'[{dim}]' for dim in child.array_dimensions)}" return base diff --git a/src/peakrdl_busdecoder/cpuif/axi4lite/axi4_lite_cpuif.py b/src/peakrdl_busdecoder/cpuif/axi4lite/axi4_lite_cpuif.py index e7c2c25..dead15c 100644 --- a/src/peakrdl_busdecoder/cpuif/axi4lite/axi4_lite_cpuif.py +++ b/src/peakrdl_busdecoder/cpuif/axi4lite/axi4_lite_cpuif.py @@ -19,6 +19,7 @@ class AXI4LiteCpuif(BaseCpuif): # Only add array dimensions if this should be treated as an array if self.check_is_array(child): + assert child.array_dimensions is not None return f"{base} {''.join(f'[{dim}]' for dim in child.array_dimensions)}" return base diff --git a/src/peakrdl_busdecoder/cpuif/axi4lite/axi4_lite_cpuif_flat.py b/src/peakrdl_busdecoder/cpuif/axi4lite/axi4_lite_cpuif_flat.py index 85e69f5..db22333 100644 --- a/src/peakrdl_busdecoder/cpuif/axi4lite/axi4_lite_cpuif_flat.py +++ b/src/peakrdl_busdecoder/cpuif/axi4lite/axi4_lite_cpuif_flat.py @@ -19,6 +19,7 @@ class AXI4LiteCpuifFlat(BaseCpuif): # Only add array dimensions if this should be treated as an array if self.check_is_array(child): + assert child.array_dimensions is not None return f"{base} {''.join(f'[{dim}]' for dim in child.array_dimensions)}" return base diff --git a/src/peakrdl_busdecoder/decode_logic_gen.py b/src/peakrdl_busdecoder/decode_logic_gen.py index d053426..bffda3c 100644 --- a/src/peakrdl_busdecoder/decode_logic_gen.py +++ b/src/peakrdl_busdecoder/decode_logic_gen.py @@ -1,5 +1,6 @@ from collections import deque from enum import Enum +from typing import cast from systemrdl.node import AddressableNode from systemrdl.walker import WalkerAction @@ -101,7 +102,8 @@ class DecodeLogicGenerator(BusDecoderListener): self._decode_stack.append(IfBody()) elif isinstance(self._decode_stack[-1], IfBody): # non-arrayed component with if-body - with self._decode_stack[-1].cm(condition) as b: + ifb = cast(IfBody, self._decode_stack[-1]) + with ifb.cm(condition) as b: b += f"{self._flavor.cpuif_select}.{get_indexed_path(self._ds.top_node, node)} = 1'b1;" else: raise RuntimeError("Invalid decode stack state") @@ -128,7 +130,8 @@ class DecodeLogicGenerator(BusDecoderListener): continue if isinstance(self._decode_stack[-1], IfBody): - with self._decode_stack[-1].cm(self._cond_stack.pop()) as parent_b: + ifb = cast(IfBody, self._decode_stack[-1]) + with ifb.cm(self._cond_stack.pop()) as parent_b: parent_b += b else: self._decode_stack[-1] += b diff --git a/src/peakrdl_busdecoder/utils.py b/src/peakrdl_busdecoder/utils.py index eebe174..7cf6b09 100644 --- a/src/peakrdl_busdecoder/utils.py +++ b/src/peakrdl_busdecoder/utils.py @@ -56,11 +56,13 @@ def ref_is_internal(top_node: AddrmapNode, ref: Node | PropertyReference) -> boo For the sake of this exporter, root signals are treated as internal. """ + current_node: Node | None if isinstance(ref, PropertyReference): current_node = ref.node else: current_node = ref + # pyrefly: ignore[bad-assignment] - false positive due to circular type checking while current_node is not None: if current_node == top_node: # reached top node without finding any external components diff --git a/tests/unit/test_unroll.py b/tests/unit/test_unroll.py index 4aa8e92..7f93c26 100644 --- a/tests/unit/test_unroll.py +++ b/tests/unit/test_unroll.py @@ -33,7 +33,7 @@ def test_unroll_disabled_creates_array_interface(sample_rdl): with TemporaryDirectory() as tmpdir: exporter = BusDecoderExporter() exporter.export( - sample_rdl.top, + sample_rdl, tmpdir, cpuif_cls=APB4Cpuif, cpuif_unroll=False, @@ -61,7 +61,7 @@ def test_unroll_enabled_creates_individual_interfaces(sample_rdl): with TemporaryDirectory() as tmpdir: exporter = BusDecoderExporter() exporter.export( - sample_rdl.top, + sample_rdl, tmpdir, cpuif_cls=APB4Cpuif, cpuif_unroll=True, @@ -95,7 +95,7 @@ def test_unroll_with_apb3(sample_rdl): with TemporaryDirectory() as tmpdir: exporter = BusDecoderExporter() exporter.export( - sample_rdl.top, + sample_rdl, tmpdir, cpuif_cls=APB3Cpuif, cpuif_unroll=True, @@ -138,7 +138,7 @@ def test_unroll_multidimensional_array(multidim_array_rdl): with TemporaryDirectory() as tmpdir: exporter = BusDecoderExporter() exporter.export( - multidim_array_rdl.top, + multidim_array_rdl, tmpdir, cpuif_cls=APB4Cpuif, cpuif_unroll=True,