Skip to content

Commit 26eb88d

Browse files
Merge pull request #1349 from jordancarlin/pre-commit
Enable pre-commit hooks
2 parents ade5b22 + 6bff128 commit 26eb88d

File tree

9 files changed

+104
-53
lines changed

9 files changed

+104
-53
lines changed

.github/workflows/lint.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@ on:
1818

1919
jobs:
2020
lint:
21-
name: Python ${{matrix.version}} lint
21+
name: Lint (Python ${{matrix.version}})
2222
strategy:
2323
matrix:
2424
version: [39, 312] # Test on oldest and newest verions used in wally-package-install.sh
2525
runs-on: ubuntu-latest
2626

2727
steps:
28-
- uses: actions/checkout@v4
28+
- name: Checkout code
29+
uses: actions/checkout@v4
30+
2931
- name: Set Python version
3032
run: sed -i '/^target-version/c\target-version = "py${{matrix.version}}"' .ruff.toml
31-
- name: Run ruff
32-
uses: astral-sh/ruff-action@v3
33+
34+
- name: Ensure pre-commit checks pass
35+
run: python3 -m pip install pre-commit && pre-commit run --all-files --show-diff-on-failure --color=always

.pre-commit-config.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# .pre-commit-config.yaml
2+
# jcarlin@hmc.edu 8 April 2025
3+
# Pre-commit hook configuration file for CVW
4+
5+
# SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
6+
7+
# See https://pre-commit.com for more information
8+
# See https://pre-commit.com/hooks.html for more hooks
9+
exclude: addins/
10+
minimum_pre_commit_version: "4.0.0"
11+
repos:
12+
# Standard pre-commit hooks
13+
- repo: https://github.com/pre-commit/pre-commit-hooks
14+
rev: v5.0.0
15+
hooks:
16+
- id: check-added-large-files
17+
- id: check-case-conflict
18+
- id: check-docstring-first
19+
# - id: check-executables-have-shebangs
20+
# - id: check-shebang-scripts-are-executable
21+
- id: check-symlinks
22+
exclude: bin/sim_bp # symlink to compiled executable
23+
- id: requirements-txt-fixer
24+
files: requirements.txt
25+
# - id: end-of-file-fixer
26+
# - id: trailing-whitespace
27+
# args: [--markdown-linebreak-ext=md]
28+
- id: check-merge-conflict
29+
args: ["--assume-in-merge"]
30+
exclude: \.adoc$ # sections titles Level 6 "=======" get flagged otherwise
31+
- id: check-json
32+
- id: check-toml
33+
- id: check-yaml
34+
35+
# Ruff python linter
36+
- repo: https://github.com/astral-sh/ruff-pre-commit
37+
rev: v0.11.4
38+
hooks:
39+
# Run the linter.
40+
- id: ruff
41+
args: [ --fix ]

.ruff.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Lint all .py files and extra python scripts without extensions
2-
include = ["*.py", "bin/wsim", "bin/regression-wally", "bin/iterelf", "sim/vcs/run_vcs"]
3-
exclude = ["addins/*", "tests/fp/quad/fpdatasetgen.py"]
2+
exclude = ["addins/*"]
43

54
# Target oldest version of Python used (Python 3.9 for Ubuntu 20.04 LTS)
65
target-version = "py39"

bin/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ adjustText>=1.2
22
lief>=0.14.1
33
Markdown>=3.6
44
matplotlib>=3.9.0
5+
pre-commit>=4.0.0
56
PyYAML>=5.2
67
riscof @ git+https://github.com/riscv/riscof.git
78
riscv-config>=3.18.3

fpga/generator/probe

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626

2727
import sys
2828

29+
2930
def usage():
30-
print("Usage: ./probes name width probenum")
31+
print("Usage: ./probes name width probenum")
3132

3233
def header():
33-
return """create_debug_core u_ila_0 ila
34+
return """create_debug_core u_ila_0 ila
3435
3536
set_property C_DATA_DEPTH 16384 [get_debug_cores u_ila_0]
3637
set_property C_TRIGIN_EN false [get_debug_cores u_ila_0]
@@ -49,49 +50,47 @@ endgroup
4950
connect_debug_port u_ila_0/clk [get_nets [list xlnx_ddr4_c0/inst/u_ddr4_infrastructure/addn_ui_clkout1 ]]"""
5051

5152
def convertLine(x):
52-
temp = x.split()
53-
temp[1] = int(temp[1])
54-
return tuple(temp)
53+
temp = x.split()
54+
temp[1] = int(temp[1])
55+
return tuple(temp)
5556

5657
def probeBits( probe ):
57-
str = ''
58+
string = ''
5859

59-
if (probe[1] > 1):
60-
for i in range(probe[1]):
61-
if i != (probe[1]-1):
62-
str = str + f"{{{probe[0]}[{i}]}} "
63-
else:
64-
str = str + f"{{{probe[0]}[{i}]}} "
60+
if (probe[1] > 1):
61+
for i in range(probe[1]):
62+
if i != (probe[1]-1):
63+
string = string + f"{{{probe[0]}[{i}]}} "
64+
else:
65+
string = string + f"{{{probe[0]}[{i}]}} "
6566

66-
else:
67-
str = f'{{{probe[0]}}}'
67+
else:
68+
string = f'{{{probe[0]}}}'
6869

69-
return str
70+
return string
7071

7172
def printProbe( probe, i ):
72-
bits = probeBits(probe)
73+
bits = probeBits(probe)
7374

74-
return (
75-
f'create_debug_port u_ila_0 probe\n'
76-
f'set_property port_width {probe[1]} [get_debug_ports u_ila_0/probe{i}]\n'
77-
f'set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe{i}]\n'
78-
f'connect_debug_port u_ila_0/probe{i} [get_nets [list {bits}]]\n\n'
79-
)
75+
return (
76+
f'create_debug_port u_ila_0 probe\n'
77+
f'set_property port_width {probe[1]} [get_debug_ports u_ila_0/probe{i}]\n'
78+
f'set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe{i}]\n'
79+
f'connect_debug_port u_ila_0/probe{i} [get_nets [list {bits}]]\n\n'
80+
)
8081

8182
def main(args):
82-
if (len(args) != 3):
83-
usage()
83+
if (len(args) != 3):
84+
usage()
8485

85-
name = args[0]
86-
width = int(args[1])
87-
probeNum = int(args[2])
86+
name = args[0]
87+
width = int(args[1])
88+
probeNum = int(args[2])
8889

8990

90-
probe = (name, width)
91+
probe = (name, width)
9192

92-
print(printProbe(probe, probeNum))
93+
print(printProbe(probe, probeNum))
9394

9495
if __name__ == '__main__':
95-
main(sys.argv[1:])
96-
97-
96+
main(sys.argv[1:])

fpga/probe

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import sys
2929

30+
3031
def usage():
3132
print("Usage: ./probes name width probenum")
3233
exit(1)
@@ -37,19 +38,19 @@ def convertLine(x):
3738
return tuple(temp)
3839

3940
def probeBits( probe ):
40-
str = ''
41+
string = ''
4142

4243
if (probe[1] > 1):
4344
for i in range(probe[1]):
4445
if i != (probe[1]-1):
45-
str = str + f"{{{probe[0]}[{i}]}} "
46+
string = string + f"{{{probe[0]}[{i}]}} "
4647
else:
47-
str = str + f"{{{probe[0]}[{i}]}} "
48+
string = string + f"{{{probe[0]}[{i}]}} "
4849

4950
else:
50-
str = f'{{{probe[0]}}}'
51+
string = f'{{{probe[0]}}}'
5152

52-
return str
53+
return string
5354

5455
def printProbe( probe, i ):
5556
bits = probeBits(probe)

fpga/proberange

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import sys
2929

30+
3031
def usage():
3132
print("Usage: ./probes list_of_probes outfile")
3233

@@ -56,19 +57,19 @@ def convertLine(x):
5657
return tuple(temp)
5758

5859
def probeBits( probe ):
59-
str = ''
60+
string = ''
6061

6162
if (probe[1] > 1):
6263
for i in range(probe[1]):
6364
if i != (probe[1]-1):
64-
str = str + f"{{{probe[0]}[{i}]}} "
65+
string = string + f"{{{probe[0]}[{i}]}} "
6566
else:
66-
str = str + f"{{{probe[0]}[{i}]}} "
67+
string = string + f"{{{probe[0]}[{i}]}} "
6768

6869
else:
69-
str = f'{{{probe[0]}}}'
70+
string = f'{{{probe[0]}}}'
7071

71-
return str
72+
return string
7273

7374
def printProbe( probe,):
7475
bits = probeBits(probe)

fpga/probes

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import sys
2929

30+
3031
def usage():
3132
print("Usage: ./probes list_of_probes outfile")
3233

@@ -55,19 +56,19 @@ def convertLine(x):
5556
return tuple(temp)
5657

5758
def probeBits( probe ):
58-
str = ''
59+
string = ''
5960

6061
if (probe[1] > 1):
6162
for i in range(probe[1]):
6263
if i != (probe[1]-1):
63-
str = str + f"{{{probe[0]}[{i}]}} "
64+
string = string + f"{{{probe[0]}[{i}]}} "
6465
else:
65-
str = str + f"{{{probe[0]}[{i}]}} "
66+
string = string + f"{{{probe[0]}[{i}]}} "
6667

6768
else:
68-
str = f'{{{probe[0]}}}'
69+
string = f'{{{probe[0]}}}'
6970

70-
return str
71+
return string
7172

7273
def printProbe( probe, i ):
7374
bits = probeBits(probe)

setup.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@ else
5151
exit 1
5252
fi
5353

54+
if [ ! -e "${WALLY}/.git/hooks/pre-commit" ]; then
55+
echo "Installing pre-commit hooks"
56+
pre-commit install
57+
fi
58+
5459
echo "setup done"

0 commit comments

Comments
 (0)