Skip to content

Commit e6582d3

Browse files
committed
clear up remaining type checking issues
1 parent f7214f3 commit e6582d3

File tree

8 files changed

+56
-48
lines changed

8 files changed

+56
-48
lines changed

chipflow_lib/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def _ensure_chipflow_root():
4848

4949
if os.environ["CHIPFLOW_ROOT"] not in sys.path:
5050
sys.path.append(os.environ["CHIPFLOW_ROOT"])
51-
_ensure_chipflow_root.root = os.environ["CHIPFLOW_ROOT"]
52-
return _ensure_chipflow_root.root
51+
_ensure_chipflow_root.root = os.environ["CHIPFLOW_ROOT"] #type: ignore
52+
return _ensure_chipflow_root.root #type: ignore
5353

5454

5555
def _parse_config() -> 'Config':
@@ -84,4 +84,7 @@ def _parse_config_file(config_file) -> 'Config':
8484
error_str = "\n".join(error_messages)
8585
raise ChipFlowError(f"Validation error in chipflow.toml:\n{error_str}")
8686

87+
def _get_src_loc(src_loc_at=0):
88+
frame = sys._getframe(1 + src_loc_at)
89+
return (frame.f_code.co_filename, frame.f_lineno)
8790

chipflow_lib/pin_lock.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from pathlib import Path
66
from pprint import pformat
77

8-
from chipflow_lib import _parse_config, _ensure_chipflow_root
9-
from chipflow_lib.platforms import top_components, LockFile, PACKAGE_DEFINITIONS
8+
from . import _parse_config, _ensure_chipflow_root, ChipFlowError
9+
from .platforms import top_components, LockFile, PACKAGE_DEFINITIONS
1010

1111
# logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
1212
logger = logging.getLogger(__name__)
@@ -27,6 +27,9 @@ def lock_pins() -> None:
2727
logger.debug(f"Old Lock =\n{pformat(oldlock)}")
2828
logger.debug(f"Locking pins: {'using pins.lock' if lockfile.exists() else ''}")
2929

30+
if not config.chipflow.silicon:
31+
raise ChipFlowError("no [chipflow.silicon] section found in chipflow.toml")
32+
3033
# Get package definition from dict instead of Pydantic model
3134
package_name = config.chipflow.silicon.package
3235
package_def = PACKAGE_DEFINITIONS[package_name]

chipflow_lib/platforms/silicon.py

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# amaranth: UnusedElaboratable=no
2+
# type: ignore[reportAttributeAccessIssue]
23

34
# SPDX-License-Identifier: BSD-2-Clause
45
import logging
@@ -275,29 +276,20 @@ def instantiate_ports(self, m: Module):
275276
for name, port in v.items():
276277
self._ports[port.port_name] = SiliconPlatformPort(component, name, port)
277278

278-
for clock, name in self._config.chipflow.clocks.items():
279-
port_data = pinlock.package.clocks[name]
280-
port = SiliconPlatformPort(component, name, port_data, invert=True)
281-
self._ports[name] = port
282-
283-
if clock == 'default':
284-
clock = 'sync'
285-
setattr(m.domains, clock, ClockDomain(name=clock))
286-
clk_buffer = io.Buffer("i", port)
287-
setattr(m.submodules, "clk_buffer_" + clock, clk_buffer)
288-
m.d.comb += ClockSignal().eq(clk_buffer.i)
289-
290-
for reset, name in self._config.chipflow.resets.items():
291-
port_data = pinlock.package.resets[name]
292-
port = SiliconPlatformPort(component, name, port_data)
293-
self._ports[name] = port
279+
for clock in pinlock.port_map.get_clocks():
280+
setattr(m.domains, clock.port_name, ClockDomain(name=clock))
281+
clk_buffer = io.Buffer("i", self._ports[clock.port_name])
282+
setattr(m.submodules, "clk_buffer_" + clock.port_name, clk_buffer)
283+
m.d.comb += ClockSignal().eq(clk_buffer.i) #type: ignore[reportAttributeAccessIssue]
284+
285+
for reset in pinlock.port_map.get_clocks():
294286
rst_buffer = io.Buffer("i", port)
295-
setattr(m.submodules, reset, rst_buffer)
296-
setattr(m.submodules, reset + "_sync", FFSynchronizer(rst_buffer.i, ResetSignal()))
287+
setattr(m.submodules, reset.port_name, rst_buffer)
288+
setattr(m.submodules, reset.port_name + "_sync", FFSynchronizer(rst_buffer.i, ResetSignal())) #type: ignore[reportAttributeAccessIssue]
297289

298290
self.pinlock = pinlock
299291

300-
def request(self, name=None, **kwargs):
292+
def request(self, name, **kwargs):
301293
if "$" in name:
302294
raise NameError(f"Reserved character `$` used in pad name `{name}`")
303295
if name not in self._ports:
@@ -314,10 +306,10 @@ def get_io_buffer(self, buffer):
314306
raise TypeError(f"Unsupported buffer type {buffer!r}")
315307

316308
if buffer.direction is not io.Direction.Output:
317-
result.i = buffer.i
309+
result.i = buffer.i #type: ignore[reportAttributeAccessIssue]
318310
if buffer.direction is not io.Direction.Input:
319-
result.o = buffer.o
320-
result.oe = buffer.oe
311+
result.o = buffer.o #type: ignore[reportAttributeAccessIssue]
312+
result.oe = buffer.oe #type: ignore[reportAttributeAccessIssue]
321313

322314
return result
323315

@@ -394,13 +386,3 @@ def build(self, elaboratable, name="top"):
394386
"-o", output_rtlil.replace("\\", "/")
395387
])
396388
return output_rtlil
397-
398-
def default_clock(m, platform, clock, reset):
399-
# Clock generation
400-
m.domains.sync = ClockDomain()
401-
402-
clk = platform.request(clock)
403-
m.d.comb += ClockSignal().eq(clk.i)
404-
m.submodules.rst_sync = FFSynchronizer(
405-
~platform.request(reset).i,
406-
ResetSignal())

chipflow_lib/platforms/sim.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
from pathlib import Path
55

66
from amaranth import *
7-
from amaranth.back import rtlil
7+
from amaranth.back import rtlil # type: ignore[reportAttributeAccessIssue]
88

9+
from .. import _get_src_loc
910

1011
__all__ = ["SimPlatform"]
1112

@@ -49,7 +50,7 @@ def is_model_out(field_name):
4950
box += f' wire width {field_width} {"output" if is_model_out(field_name) else "input"} {i} \\{field_name}\n' # noqa: E501
5051
box += 'end\n\n'
5152
self.sim_boxes[inst_type] = box
52-
return Instance(inst_type, **conns)
53+
return Instance(inst_type, src_loc_at=_get_src_loc(), **conns)
5354

5455
def add_monitor(self, inst_type, iface):
5556
conns = dict(i_clk=ClockSignal(), a_keep=True)
@@ -67,7 +68,7 @@ def add_monitor(self, inst_type, iface):
6768
box += f' wire width {field_width} input {i + 1} \\{field_name}\n'
6869
box += 'end\n\n'
6970
self.sim_boxes[inst_type] = box
70-
return Instance(inst_type, **conns)
71+
return Instance(inst_type, src_loc_at=_get_src_loc(), **conns)
7172

7273
def build(self, e):
7374
Path(self.build_dir).mkdir(parents=True, exist_ok=True)

chipflow_lib/platforms/utils.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,18 +446,37 @@ def _add_port(self, component: str, interface: str, port_name: str, port: Port):
446446
self.ports[component][interface] = {}
447447
self.ports[component][interface][port_name] = port
448448

449-
def _add_ports(self, component: str, interface: str, ports: Dict[str, Port]):
449+
def _add_ports(self, component: str, interface: str, ports: Interface):
450450
"Internally used by a `PackageDef`"
451451
if component not in self.ports:
452452
self.ports[component] = {}
453453
self.ports[component][interface] = ports
454454

455-
def get_ports(self, component: str, interface: str) -> Dict[str, Port]:
455+
def get_ports(self, component: str, interface: str) -> Interface:
456+
456457
"List the ports allocated in this PortMap for the given `Component` and `Interface`"
457458
if component not in self.ports:
458459
raise KeyError(f"'{component}' not found in {self}")
459460
return self.ports[component][interface]
460461

462+
def get_clocks(self) -> List[Port]:
463+
ret = []
464+
for n, c in self.ports.items():
465+
for cn, i in c.items():
466+
for ni, p in i.items():
467+
if p.type == "clock":
468+
ret.append(i)
469+
return ret
470+
471+
def get_resets(self) -> List[Port]:
472+
ret = []
473+
for n, c in self.ports.items():
474+
for cn, i in c.items():
475+
for ni, p in i.items():
476+
if p.type == "reset":
477+
ret.append(i)
478+
return ret
479+
461480

462481
class LockFile(pydantic.BaseModel):
463482
"""

chipflow_lib/steps/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ def build_cli_parser(self, parser):
3535

3636
def run_cli(self, args):
3737
"Called when this step's is used from `chipflow` command"
38-
self.build()
38+
...

chipflow_lib/steps/silicon.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ def __init__(self, config):
6969
def build_cli_parser(self, parser):
7070
action_argument = parser.add_subparsers(dest="action")
7171
action_argument.add_parser(
72-
"prepare", help=inspect.getdoc(self.prepare).splitlines()[0])
72+
"prepare", help=inspect.getdoc(self.prepare).splitlines()[0]) # type: ignore
7373
submit_subparser = action_argument.add_parser(
74-
"submit", help=inspect.getdoc(self.submit).splitlines()[0])
74+
"submit", help=inspect.getdoc(self.submit).splitlines()[0]) # type: ignore
7575
submit_subparser.add_argument(
7676
"--dry-run", help=argparse.SUPPRESS,
7777
default=False, action="store_true")
@@ -128,7 +128,7 @@ def submit(self, rtlil_path, args):
128128
fh = None
129129
submission_name = self.determine_submission_name()
130130
data = {
131-
"projectId": self.project_name,
131+
"projectId": self.config.project_name,
132132
"name": submission_name,
133133
}
134134

@@ -173,7 +173,7 @@ def network_err(e):
173173
fh.close()
174174
exit(1)
175175

176-
sp.info(f"> Submitting {submission_name} for project {self.project_name} to ChipFlow Cloud {self._chipflow_api_origin}")
176+
sp.info(f"> Submitting {submission_name} for project {self.config.project_name} to ChipFlow Cloud {self._chipflow_api_origin}")
177177
sp.start("Sending design to ChipFlow Cloud")
178178

179179
build_submit_url = f"{self._chipflow_api_origin}/build/submit"
@@ -216,7 +216,6 @@ def network_err(e):
216216

217217
if args.wait:
218218
exit_code = self._stream_logs(sp, network_err)
219-
sp.ok()
220219
if fh:
221220
fh.close()
222221
exit(exit_code)

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ typeCheckingMode = "standard"
4949
reportInvalidTypeForm = false
5050
reportMissingImports = false
5151
reportUnboundVariable = false
52+
reportWildcardImportFromLibrary = false
5253

5354
[tool.ruff]
5455
include = [
@@ -73,7 +74,7 @@ test.cmd = "pytest"
7374
test-cov.cmd = "pytest --cov=chipflow_lib --cov-report=term"
7475
test-cov-html.cmd = "pytest --cov=chipflow_lib --cov-report=html"
7576
test-docs.cmd = "sphinx-build -b doctest docs/ docs/_build"
76-
lint.composite = [ "ruff check", "pyrefly check chipflow_lib"]
77+
lint.composite = [ "ruff check", "pyright chipflow_lib"]
7778
docs.cmd = "sphinx-build docs/ docs/_build/ -W --keep-going"
7879
test-silicon.cmd = "pytest tests/test_silicon_platform.py tests/test_silicon_platform_additional.py tests/test_silicon_platform_amaranth.py tests/test_silicon_platform_build.py tests/test_silicon_platform_port.py --cov=chipflow_lib.platforms.silicon --cov-report=term"
7980
_check-project.call = "tools.check_project:main"

0 commit comments

Comments
 (0)