Skip to content

Commit 7917e78

Browse files
Update ruff, typos and codespell config and fix errors (#313)
* [pre-commit] pre-commit autoupdate * push typos and ruff version * fix RUF043 errors * fix B905 and RUF059 errors * fix codespell pre-commit config --------- Co-authored-by: Patrick Schuenke <patrick.schuenke@nvision-imaging.com>
1 parent 2a56d42 commit 7917e78

16 files changed

+33
-38
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,26 @@ repos:
1616
- id: mixed-line-ending
1717

1818
- repo: https://github.com/astral-sh/ruff-pre-commit
19-
rev: v0.12.11
19+
rev: v0.14.0
2020
hooks:
2121
- id: ruff # linter
2222
args: [--fix]
2323
- id: ruff-format # formatter
2424

2525
- repo: https://github.com/crate-ci/typos
26-
rev: v1.35.6
26+
rev: v1.38.1
2727
hooks:
2828
- id: typos
29+
args: [] # empty, to remove write-changes from the default arguments.
2930
exclude: ^examples/|paper.md
3031

3132
- repo: https://github.com/codespell-project/codespell
3233
# Configuration for codespell is in pyproject.toml
3334
rev: v2.4.1
3435
hooks:
3536
- id: codespell
36-
additional_dependencies:
37-
- tomli; python_version<'3.11'
37+
additional_dependencies:
38+
- tomli; python_version<'3.11'
3839

3940
ci:
4041
autofix_commit_msg: |

pyproject.toml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,7 @@ test = [
3636
"pytest-cov<6.1",
3737
"pytest-xdist",
3838
]
39-
docs = [
40-
"sphinx",
41-
"jinja2",
42-
"furo",
43-
"recommonmark",
44-
]
39+
docs = ["sphinx", "jinja2", "furo", "recommonmark"]
4540

4641
[project.urls]
4742
Homepage = "https://github.com/imr-framework/pypulseq"
@@ -128,7 +123,6 @@ skip-magic-trailing-comma = false
128123

129124
[tool.typos.default]
130125
locale = "en-us"
131-
exclude = ["examples/**"]
132126

133127
# PyTest section
134128
[tool.pytest.ini_options]

src/pypulseq/SAR/SAR_calc.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,13 @@ def calc_SAR(file: Union[str, Path, Sequence]) -> None:
280280
SARhg_lim, tsec = _SAR_interp(SAR_hg, t)
281281
(
282282
SAR_wbg_tensec,
283-
SAR_wbg_sixmin,
283+
_SAR_wbg_sixmin,
284284
SAR_hg_tensec,
285-
SAR_hg_sixmin,
286-
SAR_wbg_sixmin_peak,
287-
SAR_hg_sixmin_peak,
288-
SAR_wbg_tensec_peak,
289-
SAR_hg_tensec_peak,
285+
_SAR_hg_sixmin,
286+
_SAR_wbg_sixmin_peak,
287+
_SAR_hg_sixmin_peak,
288+
_SAR_wbg_tensec_peak,
289+
_SAR_hg_tensec_peak,
290290
) = _SAR_lims_check(SARwbg_lim, SARhg_lim, tsec)
291291

292292
# Plot 10 sec average SAR

src/pypulseq/Sequence/block.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def get_block(self, block_index: int) -> SimpleNamespace:
297297
block = SimpleNamespace()
298298
attrs = ['block_duration', 'rf', 'gx', 'gy', 'gz', 'adc', 'label']
299299
values = [None] * len(attrs)
300-
for att, val in zip(attrs, values):
300+
for att, val in zip(attrs, values, strict=False):
301301
setattr(block, att, val)
302302
event_ind = self.block_events[block_index]
303303

src/pypulseq/Sequence/calc_grad_spectrum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def calculate_gradient_spectrum(
156156
plt.axvline(res['frequency'] - res['bandwidth'] / 2, color='k', linestyle='--')
157157
plt.axvline(res['frequency'] + res['bandwidth'] / 2, color='k', linestyle='--')
158158
else:
159-
for s, c in zip(spectrograms, ['X', 'Y', 'Z']):
159+
for s, c in zip(spectrograms, ['X', 'Y', 'Z'], strict=False):
160160
plt.figure()
161161
plt.title(f'Spectrum {c}')
162162
plt.xlabel('Time (s)')

src/pypulseq/Sequence/ext_test_report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def ext_test_report(self) -> str:
2828
# Calculate TE, TR
2929
duration, num_blocks, event_count = self.duration()
3030

31-
k_traj_adc, k_traj, t_excitation, t_refocusing, t_adc = self.calculate_kspace()
31+
k_traj_adc, _, t_excitation, _, t_adc = self.calculate_kspace()
3232
t_excitation = np.asarray(t_excitation)
3333

3434
k_abs_adc = np.sqrt(np.sum(np.square(k_traj_adc), axis=0))

src/pypulseq/Sequence/sequence.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ def plot(
10011001
_t = [t_factor * t] * len(lbl_vals)
10021002
# Plot each label individually to retrieve each corresponding Line2D object
10031003
p = itertools.chain.from_iterable(
1004-
[sp11.plot(__t, _lbl_vals, '.') for __t, _lbl_vals in zip(_t, lbl_vals)]
1004+
[sp11.plot(__t, _lbl_vals, '.') for __t, _lbl_vals in zip(_t, lbl_vals, strict=False)]
10051005
)
10061006
if len(label_legend_to_plot) != 0:
10071007
sp11.legend(list(p), label_legend_to_plot, loc='upper left')
@@ -1596,7 +1596,7 @@ def waveforms(self, append_RF: bool = False, time_range: Union[List[float], None
15961596
# element of the next shape.
15971597
shape_pieces[j] = [shape_pieces[j][0]] + [
15981598
cur if prev[0, -1] + eps < cur[0, 0] else cur[:, 1:]
1599-
for prev, cur in zip(shape_pieces[j][:-1], shape_pieces[j][1:])
1599+
for prev, cur in zip(shape_pieces[j][:-1], shape_pieces[j][1:], strict=False)
16001600
]
16011601

16021602
wave_data.append(np.concatenate(shape_pieces[j], axis=1))
@@ -1820,7 +1820,7 @@ def write(
18201820
# Check whether all gradients in the last block are ramped down properly
18211821
last_block_id = next(reversed(self.block_events))
18221822
last_block = self.get_block(last_block_id)
1823-
for channel, event in zip(('x', 'y', 'z'), (last_block.gx, last_block.gy, last_block.gz)):
1823+
for channel, event in zip(('x', 'y', 'z'), (last_block.gx, last_block.gy, last_block.gz), strict=False):
18241824
if (
18251825
event is not None
18261826
and event.type == 'grad'

src/pypulseq/event_lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def round_data(data: Tuple[float], digits: Tuple[int]) -> Tuple[float]:
280280
"""
281281
return tuple(
282282
round(d, dig - math.ceil(math.log10(abs(d) + 1e-12)) if dig > 0 else -dig)
283-
for d, dig in zip(data, digits)
283+
for d, dig in zip(data, digits, strict=False)
284284
)
285285

286286
def round_data_numpy(data: np.ndarray, digits: int) -> np.ndarray:

src/pypulseq/make_sigpy_pulse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def sigpy_n_seq(
121121
)
122122

123123
if pulse_cfg.pulse_type == 'slr':
124-
[signal, t, pulse] = make_slr(
124+
[signal, t, _] = make_slr(
125125
flip_angle=flip_angle,
126126
time_bw_product=time_bw_product,
127127
duration=duration,
@@ -130,7 +130,7 @@ def sigpy_n_seq(
130130
disp=plot,
131131
)
132132
if pulse_cfg.pulse_type == 'sms':
133-
[signal, t, pulse] = make_sms(
133+
[signal, t, _] = make_sms(
134134
flip_angle=flip_angle,
135135
time_bw_product=time_bw_product,
136136
duration=duration,

src/pypulseq/utils/safe_pns_prediction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def safe_example():
405405
# safe_hw_verify(hw)
406406

407407
# Predict PNS levels
408-
pns, res = safe_gwf_to_pns(gwf, rf, dt, hw, 1)
408+
pns, _ = safe_gwf_to_pns(gwf, rf, dt, hw, 1)
409409

410410
# Plot some results
411411
safe_plot(pns, dt)

0 commit comments

Comments
 (0)