Skip to content

Commit 5ae64ca

Browse files
committed
Fix version of ruff in use, fix issues found, and add a .gitattributes with python config
1 parent 2113009 commit 5ae64ca

17 files changed

+547
-530
lines changed

.gitattributes

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Basic .gitattributes for a python repo.
2+
3+
# Source files
4+
# ============
5+
*.py text diff=python eol=lf whitespace=trailing-space,space-before-tab,tab-in-indent,tabwidth=4
6+
7+
# Binary files
8+
# ============
9+
*.db binary
10+
*.p binary
11+
*.pkl binary
12+
*.pickle binary
13+
*.pyc binary export-ignore
14+
*.pyo binary export-ignore
15+
*.pyd binary
16+
17+
# Jupyter notebook
18+
*.ipynb text eol=lf
19+

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ __pycache__/
1818
.doit.db
1919

2020
docs/_build
21+
.cache
22+

chipflow_lib/config_models.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# SPDX-License-Identifier: BSD-2-Clause
2-
import enum
32
import re
4-
from typing import Dict, List, Optional, Union, Literal, Any
3+
from typing import Dict, Optional, Literal, Any
54

6-
from pydantic import BaseModel, Field, model_validator, ValidationInfo, field_validator
5+
from pydantic import BaseModel, model_validator, ValidationInfo, field_validator
76

87
from .platforms.utils import Process
98

@@ -19,7 +18,7 @@ def validate_loc_format(self):
1918
if not re.match(r"^[NSWE]?[0-9]+$", self.loc):
2019
raise ValueError(f"Invalid location format: {self.loc}, expected format: [NSWE]?[0-9]+")
2120
return self
22-
21+
2322
@classmethod
2423
def validate_pad_dict(cls, v: dict, info: ValidationInfo):
2524
"""Custom validation for pad dicts from TOML that may not have all fields."""
@@ -28,11 +27,11 @@ def validate_pad_dict(cls, v: dict, info: ValidationInfo):
2827
if 'loc' in v and 'type' not in v:
2928
if info.field_name == 'power':
3029
v['type'] = 'power'
31-
30+
3231
# Map legacy 'clk' type to 'clock' to match our enum
3332
if 'type' in v and v['type'] == 'clk':
3433
v['type'] = 'clock'
35-
34+
3635
return v
3736
return v
3837

@@ -44,7 +43,7 @@ class SiliconConfig(BaseModel):
4443
pads: Dict[str, PadConfig] = {}
4544
power: Dict[str, PadConfig] = {}
4645
debug: Optional[Dict[str, bool]] = None
47-
46+
4847
@field_validator('pads', 'power', mode='before')
4948
@classmethod
5049
def validate_pad_dicts(cls, v, info: ValidationInfo):

chipflow_lib/pin_lock.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from chipflow_lib import _parse_config, ChipFlowError
1010
from chipflow_lib.platforms import PACKAGE_DEFINITIONS, PIN_ANNOTATION_SCHEMA, top_interfaces
11-
from chipflow_lib.platforms.utils import LockFile, Package, PortMap, Port, Process
11+
from chipflow_lib.platforms.utils import LockFile, Package, PortMap, Port
1212
from chipflow_lib.config_models import Config
1313

1414
# logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
@@ -79,11 +79,10 @@ def allocate_pins(name: str, member: Dict[str, Any], pins: List[str], port_name:
7979
def lock_pins() -> None:
8080
# Get the config as dict for backward compatibility with top_interfaces
8181
config_dict = _parse_config()
82-
82+
8383
# Parse with Pydantic for type checking and strong typing
84-
from chipflow_lib.config_models import Config
8584
config_model = Config.model_validate(config_dict)
86-
85+
8786
used_pins = set()
8887
oldlock = None
8988

chipflow_lib/platforms/silicon.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from amaranth.lib import wiring, io
1313
from amaranth.lib.cdc import FFSynchronizer
14-
from amaranth.lib.wiring import Component, In, PureInterface, flipped, connect
14+
from amaranth.lib.wiring import Component, In, PureInterface
1515

1616
from amaranth.back import rtlil
1717
from amaranth.hdl import Fragment
@@ -74,12 +74,12 @@ def __init__(self,
7474
self._invert = invert
7575
self._options = port.options
7676
self._pins = port.pins
77-
77+
7878
# Initialize signal attributes to None
7979
self._i = None
8080
self._o = None
8181
self._oe = None
82-
82+
8383
# Create signals based on direction
8484
if self._direction in (io.Direction.Input, io.Direction.Bidir):
8585
self._i = Signal(port.width, name=f"{component}_{name}__i")

chipflow_lib/steps/silicon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def submit(self, rtlil_path, *, dry_run=False):
149149
logger.debug(f"padname={padname}, port={port}, loc={port.pins[0]}, "
150150
f"dir={port.direction}, width={width}")
151151
pads[padname] = {'loc': port.pins[0], 'type': port.direction.value}
152-
152+
153153
# Use the Pydantic models to access configuration data
154154
silicon_model = self.config_model.chipflow.silicon
155155
config = {

pdm.lock

Lines changed: 147 additions & 129 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,15 @@ reportMissingImports = false
4848
reportUnboundVariable = false
4949

5050
[tool.ruff]
51-
include = ["pyproject.toml", "**/*.py", "chipflow.toml"]
51+
include = [
52+
"chipflow_lib/**/*.py",
53+
"tests/**.py",
54+
"chipflow.toml",
55+
"pyproject.toml"
56+
]
5257

5358
[tool.ruff.lint]
59+
select = ["E4", "E7", "E9", "F", "W291", "W293"]
5460
ignore = ['F403', 'F405']
5561

5662
[tool.pdm.version]
@@ -68,8 +74,7 @@ test-silicon.cmd = "pytest tests/test_silicon_platform.py tests/test_silicon_pla
6874

6975
[dependency-groups]
7076
lint = [
71-
"ruff",
72-
"pytest-cov",
77+
"ruff>=0.9.2",
7378
]
7479
test = [
7580
"pytest>=7.2.0",

tests/fixtures/mock_top.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ def elaborate(self, platform):
4343
m = Module()
4444
for inpin, outpin in zip(self.test1.members, self.test2.members):
4545
m.d.comb += inpin.eq(outpin)
46-
46+
4747
return m

tests/test_buffers.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import unittest
55
from unittest import mock
66

7-
from amaranth import Module, Signal
7+
from amaranth import Module
88
from amaranth.lib import io
99

1010
# We'll need to mock SiliconPlatformPort instead of using the real one
@@ -14,49 +14,49 @@ class TestBuffers(unittest.TestCase):
1414
def test_io_buffer_mocked(self, mock_ffbuffer, mock_iobuffer):
1515
"""Test that IOBuffer can be imported and mocked"""
1616
from chipflow_lib.platforms.silicon import IOBuffer
17-
17+
1818
# Verify that the mock is working
1919
self.assertEqual(IOBuffer, mock_iobuffer)
20-
20+
2121
# Create a mock port
2222
port = mock.Mock()
2323
port.invert = False
24-
24+
2525
# Create a mock for the IOBuffer elaborate method
2626
module = Module()
2727
mock_iobuffer.return_value.elaborate.return_value = module
28-
28+
2929
# Create an IOBuffer instance
3030
buffer = IOBuffer(io.Direction.Input, port)
31-
31+
3232
# Elaborate the buffer
3333
result = buffer.elaborate(None)
34-
34+
3535
# Verify the result
3636
self.assertEqual(result, module)
3737
mock_iobuffer.return_value.elaborate.assert_called_once()
3838

3939
def test_ff_buffer_mocked(self, mock_ffbuffer, mock_iobuffer):
4040
"""Test that FFBuffer can be imported and mocked"""
4141
from chipflow_lib.platforms.silicon import FFBuffer
42-
42+
4343
# Verify that the mock is working
4444
self.assertEqual(FFBuffer, mock_ffbuffer)
45-
45+
4646
# Create a mock port
4747
port = mock.Mock()
4848
port.invert = False
49-
49+
5050
# Create a mock for the FFBuffer elaborate method
5151
module = Module()
5252
mock_ffbuffer.return_value.elaborate.return_value = module
53-
53+
5454
# Create an FFBuffer instance
5555
buffer = FFBuffer(io.Direction.Input, port, i_domain="sync", o_domain="sync")
56-
56+
5757
# Elaborate the buffer
5858
result = buffer.elaborate(None)
59-
59+
6060
# Verify the result
6161
self.assertEqual(result, module)
6262
mock_ffbuffer.return_value.elaborate.assert_called_once()

0 commit comments

Comments
 (0)