Skip to content

Commit b327068

Browse files
wsipaktmichalak
authored andcommitted
resolve linter errors
Signed-off-by: Wojciech Sipak <[email protected]>
1 parent 8b23ebd commit b327068

13 files changed

+626
-236
lines changed

xls/modules/zstd/cocotb/channel.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ class XLSChannel(Bus):
3737
_optional_signals = XLS_CHANNEL_OPTIONAL_SIGNALS
3838

3939
def __init__(self, entity, name, clk, *, start_now=False, **kwargs: Any):
40-
super().__init__(entity, name, self._signals, self._optional_signals, **kwargs)
40+
super().__init__(
41+
entity, name, self._signals, self._optional_signals, **kwargs
42+
)
4143
self.clk = clk
4244
if start_now:
4345
self.start_recv_loop()
@@ -58,17 +60,30 @@ class XLSChannelDriver(BusDriver):
5860
_signals = XLS_CHANNEL_SIGNALS
5961
_optional_signals = XLS_CHANNEL_OPTIONAL_SIGNALS
6062

61-
def __init__(self, entity: SimHandleBase, name: str, clock: SimHandleBase, **kwargs: Any):
63+
def __init__(
64+
self,
65+
entity: SimHandleBase,
66+
name: str,
67+
clock: SimHandleBase,
68+
**kwargs: Any
69+
):
6270
BusDriver.__init__(self, entity, name, clock, **kwargs)
6371

6472
self.bus.data.setimmediatevalue(0)
6573
self.bus.vld.setimmediatevalue(0)
6674

67-
async def _driver_send(self, transaction: Transaction, sync: bool = True, **kwargs: Any) -> None:
75+
async def _driver_send(
76+
self,
77+
transaction: Transaction,
78+
sync: bool = True,
79+
**kwargs: Any
80+
) -> None:
6881
if sync:
6982
await RisingEdge(self.clock)
7083

71-
data_to_send = (transaction if isinstance(transaction, Sequence) else [transaction])
84+
data_to_send = (
85+
transaction if isinstance(transaction, Sequence) else [transaction]
86+
)
7287

7388
for word in data_to_send:
7489
self.bus.vld.value = 1
@@ -83,11 +98,18 @@ async def _driver_send(self, transaction: Transaction, sync: bool = True, **kwar
8398

8499

85100
class XLSChannelMonitor(BusMonitor):
86-
"""Monitors and decodes transactions on an XLS channel."""
101+
"""Monitors and decodes transactions on an XLS channel."""
87102
_signals = XLS_CHANNEL_SIGNALS
88103
_optional_signals = XLS_CHANNEL_OPTIONAL_SIGNALS
89104

90-
def __init__(self, entity: SimHandleBase, name: str, clock: SimHandleBase, struct: Type[XLSStruct], **kwargs: Any):
105+
def __init__(
106+
self,
107+
entity: SimHandleBase,
108+
name: str,
109+
clock: SimHandleBase,
110+
struct: Type[XLSStruct],
111+
**kwargs: Any
112+
):
91113
BusMonitor.__init__(self, entity, name, clock, **kwargs)
92114
self.struct = struct
93115

xls/modules/zstd/cocotb/data_generator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import zstandard
2323

2424
class BlockType(enum.Enum):
25+
"""Enum encoding of ZSTD block types."""
26+
2527
RAW = 0
2628
RLE = 1
2729
COMPRESSED = 2
@@ -38,7 +40,9 @@ def from_string(s):
3840
raise ValueError(str(e)) from e
3941

4042
def CallDecodecorpus(args):
41-
decodecorpus = pathlib.Path(runfiles.get_path("decodecorpus", repository = "zstd"))
43+
decodecorpus = pathlib.Path(
44+
runfiles.get_path("decodecorpus", repository = "zstd")
45+
)
4246
cmd = args
4347
cmd.insert(0, str(decodecorpus))
4448
cmd_concat = " ".join(cmd)

xls/modules/zstd/cocotb/memory.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
# limitations under the License.
1414

1515
"""
16-
Extensions of the cocotb AXI RAM models that initialize
17-
memory contents from a binary file.
16+
Extensions of the cocotb AXI RAM models to memory contents from a binary file.
1817
"""
1918

2019
import os

xls/modules/zstd/cocotb/scoreboard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _current_cycle(self):
6060
def _req_callback(self, transaction: XLSStruct):
6161
self.pending_req.put(LatencyQueueItem(transaction, self._current_cycle()))
6262

63-
def _resp_callback(self, _transaction: XLSStruct):
63+
def _resp_callback(self, unused_transaction: XLSStruct):
6464
latency_item = self.pending_req.get()
6565
self.results.append(self._current_cycle() - latency_item.timestamp)
6666

xls/modules/zstd/cocotb/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@
2626

2727

2828
def setup_com_iverilog():
29-
iverilog_path = pathlib.Path(runfiles.get_path("iverilog", repository = "com_icarus_iverilog"))
30-
vvp_path = pathlib.Path(runfiles.get_path("vvp", repository = "com_icarus_iverilog"))
29+
iverilog_path = pathlib.Path(
30+
runfiles.get_path("iverilog", repository = "com_icarus_iverilog")
31+
)
32+
vvp_path = pathlib.Path(
33+
runfiles.get_path("vvp", repository = "com_icarus_iverilog")
34+
)
3135
os.environ["PATH"] += os.pathsep + str(iverilog_path.parent)
3236
os.environ["PATH"] += os.pathsep + str(vvp_path.parent)
3337
build_dir = pathlib.Path(os.environ['BUILD_WORKING_DIRECTORY'], "sim_build")

xls/modules/zstd/cocotb/xlsstruct.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717
"""
1818

1919
import random
20-
from dataclasses import asdict
21-
from dataclasses import astuple
22-
from dataclasses import dataclass
23-
from dataclasses import fields
20+
import dataclasses
2421

2522
from cocotb.binary import BinaryValue
2623

@@ -42,21 +39,23 @@ class MyStruct(XLSStruct):
4239
Returns:
4340
type: The dataclass-decorated class with repr disabled.
4441
"""
45-
return dataclass(cls, repr=False)
42+
return dataclasses.dataclass(cls, repr=False)
4643

47-
@dataclass
44+
@dataclasses.dataclass
4845
class XLSStruct:
49-
"""
50-
Represents XLS struct on the Python side, allowing serialization/deserialization
51-
to/from common formats and usage with XLS{Driver, Monitor}.
46+
"""Represents XLS struct on the Python side.
47+
48+
Allows serialization/deserialization to/from common formats and usage with
49+
XLS{Driver, Monitor}.
5250
53-
The intended way to use this class is to inherit from it, specify the fields with
54-
<field>: <width> [= <default value>] syntax and decorate the inheriting class with
55-
@XLSDataclass. Objects of this class can be instantiated and used like usual
56-
dataclass objects, with a few extra methods and properties available. They can also
57-
be passed as arguments to XLSChannelDriver.send and will be serialized to expected
58-
bit vector. Class can be passed to XLSChannelMonitor ``struct`` constructor argument
59-
to automatically deserialize all transfers to the provided struct.
51+
The intended way to use this class is to inherit from it, specify the fields
52+
with <field>: <width> [= <default value>] syntax and decorate the inheriting
53+
class with @XLSDataclass. Objects of this class can be instantiated and used
54+
like usual dataclass objects, with a few extra methods and properties
55+
available. They can also be passed as arguments to XLSChannelDriver.send and
56+
will be serialized to expected bit vector. Class can be passed to
57+
XLSChannelMonitor ``struct`` constructor argument to automatically
58+
deserialize all transfers to the provided struct.
6059
6160
Example:
6261
@@ -88,7 +87,7 @@ def _masks(cls):
8887
returns [2'b11, 3'b111, 4'b1111].
8988
"""
9089
masks = []
91-
for field in fields(cls):
90+
for field in dataclasses.fields(cls):
9291
width = field.type
9392
masks += [(1 << width) - 1]
9493
return masks
@@ -101,7 +100,7 @@ def _positions(cls):
101100
returns [20, 18, 15, 11, 6, 0]
102101
"""
103102
positions = []
104-
for i, field in enumerate(fields(cls)):
103+
for i, field in enumerate(dataclasses.fields(cls)):
105104
width = field.type
106105
if i == 0:
107106
positions += [cls.total_width - width]
@@ -113,17 +112,18 @@ def _positions(cls):
113112
@property
114113
def total_width(cls):
115114
"""Returns total bit width of the struct."""
116-
return sum(field.type for field in fields(cls))
115+
return sum(field.type for field in dataclasses.fields(cls))
117116

118117
@property
119118
def value(self):
120119
"""Returns struct's value as a Python integer."""
121120
value = 0
122121
masks = self._masks()
123122
positions = self._positions()
124-
for field_val, mask, pos in zip(astuple(self), masks, positions):
123+
for field_val, mask, pos in zip(
124+
dataclasses.astuple(self), masks, positions):
125125
if field_val > mask:
126-
raise TruncationError(f"Signal value is wider than its bit width")
126+
raise TruncationError("Signal value is wider than its bit width")
127127
value |= (field_val & mask) << pos
128128
return value
129129

@@ -151,15 +151,15 @@ def from_int(cls, value):
151151
instance = {}
152152
masks = cls._masks()
153153
positions = cls._positions()
154-
for field, mask, pos in zip(fields(cls), masks, positions):
154+
for field, mask, pos in zip(dataclasses.fields(cls), masks, positions):
155155
instance[field.name] = (value >> pos) & mask
156156
return cls(**instance)
157157

158158
@classmethod
159159
def randomize(cls):
160160
"""Returns an instance of the struct with all fields' values randomized."""
161161
instance = {}
162-
for field in fields(cls):
162+
for field in dataclasses.fields(cls):
163163
instance[field.name] = random.randrange(0, 2**field.type)
164164
return cls(**instance)
165165

@@ -168,5 +168,7 @@ def __str__(self):
168168

169169
def __repr__(self):
170170
classname = self.__class__.__name__
171-
class_fields = [f"{name}={hex(value)}" for name, value in asdict(self).items()]
171+
class_fields = [
172+
f"{name}={hex(value)}" for name, value in dataclasses.asdict(self).items()
173+
]
172174
return f"{classname}({', '.join(class_fields)})"

0 commit comments

Comments
 (0)