Skip to content

Commit c77e6d3

Browse files
committed
Fix new ruff lints
1 parent b323d5d commit c77e6d3

9 files changed

Lines changed: 26 additions & 23 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repos:
1818
- repo: https://github.com/astral-sh/ruff-pre-commit
1919
rev: v0.15.4
2020
hooks:
21-
- id: ruff
21+
- id: ruff-check
2222
args: [--output-format=full, --fix]
2323
- id: ruff-format
2424

aiidalab_ispg/app/spectrum.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
* Daniel Hollas <daniel.hollas@bristol.ac.uk>
55
"""
66

7+
import base64
8+
import csv
79
from enum import Enum, unique
10+
from tempfile import SpooledTemporaryFile
811

912
import bokeh.plotting as plt
1013
import ipywidgets as ipw
@@ -332,7 +335,7 @@ def __init__(self, **kwargs):
332335

333336
def _download_spectrum(self, btn):
334337
"""Download spectrum lines as CSV file"""
335-
from IPython.display import Javascript, display
338+
from IPython.display import Javascript, display # noqa: PLC0415
336339

337340
filename = "spectrum.tsv"
338341
if self.smiles:
@@ -354,10 +357,6 @@ def _download_spectrum(self, btn):
354357
display(js)
355358

356359
def _prepare_tsv(self):
357-
import base64
358-
import csv
359-
from tempfile import SpooledTemporaryFile
360-
361360
column_names = [
362361
f"Energy / ({self.energy_unit_selector.value.value})",
363362
f"Cross section / {self.intensity_unit}, "

aiidalab_ispg/app/spectrum_analysis.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
from .utils import BokehFigureContext
2323
from .widgets import HeaderWarning
2424

25+
try:
26+
# For numpy 1.x
27+
from numpy import trapz as trapezoid
28+
except ImportError:
29+
# for numpy >=2.4
30+
from numpy import trapezoid
31+
2532

2633
@unique
2734
class ActinicFlux(Enum):
@@ -310,7 +317,7 @@ def _update_j_plot(self, flux_type: ActinicFlux, quantumY: float):
310317
)
311318
# Integrate the differential j plot to get the total rate.
312319
# Use trapezoid rule.
313-
j_total = np.trapz(j_diff, x=wavelengths)
320+
j_total = trapezoid(j_diff, x=wavelengths)
314321
self.total_rate.value = f"<b>{np.format_float_scientific(j_total, 3)}</b>"
315322

316323
# Plot slightly smoothed j_diff to make it less rugged.

aiidalab_ispg/app/steps.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import traitlets
1212

1313
from aiida.engine import ProcessState
14+
from aiida.engine.processes.control import kill_processes
1415
from aiida.orm import StructureData, TrajectoryData, WorkChainNode, load_node
1516
from aiidalab_widgets_base import (
1617
AiidaNodeViewWidget,
@@ -273,8 +274,6 @@ def _on_click_kill_button(self, _=None):
273274
274275
First kill the process, then update the kill button layout.
275276
"""
276-
from aiida.engine.processes.control import kill_processes
277-
278277
self.kill_button.disabled = True
279278

280279
workchain = [load_node(self.process_uuid)]

aiidalab_ispg/app/widgets.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import io
1010
import re
1111
from pathlib import Path
12+
from tempfile import NamedTemporaryFile
1213
from typing import Optional
1314

1415
import ase
@@ -302,8 +303,6 @@ def _update_structure_viewer(self, change):
302303
# TODO: Maybe we want to have a separate button for this?
303304
def _prepare_payload(self, file_format=None):
304305
"""Prepare binary information."""
305-
from tempfile import NamedTemporaryFile
306-
307306
file_format = file_format if file_format else self.file_format.value
308307
tmp = NamedTemporaryFile()
309308

aiidalab_ispg/wigner/wigner.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import copy
1010
import math
1111
import random
12+
import sys
13+
from pathlib import Path
1214

1315
# some constants
1416
CM_TO_HARTREE = (
@@ -124,9 +126,8 @@ def _convert_orca_normal_modes(self, modes, masses):
124126
norm += modes[imode]["move"][j][xyz] ** 2 * mass / U_TO_AMU
125127
norm = math.sqrt(norm)
126128
if norm == 0.0 and freq >= self.low_freq_thr:
127-
raise ValueError(
128-
"Displacement vector of mode %i is null vector!" % (imode + 1)
129-
)
129+
msg = f"Displacement vector of mode {imode + 1} is null vector!"
130+
raise ValueError(msg)
130131

131132
converted_mode = copy.deepcopy(modes[imode])
132133
for j, mass in enumerate(masses):
@@ -150,7 +151,7 @@ def wigner(Q, P):
150151

151152
# Below are functions for CLI standalone use
152153
def parse_cmd():
153-
import argparse
154+
import argparse # noqa: PLC0415
154155

155156
desc = "Program for harmonic Wigner sampling"
156157
prog = "harmonwig"
@@ -199,16 +200,12 @@ def parse_cmd():
199200

200201

201202
def error(msg: str):
202-
import sys
203-
204203
print(f"ERROR: {msg}")
205204
sys.exit(1)
206205

207206

208207
def read_qm_output(fname: str, fmt: str = "auto") -> dict:
209-
from pathlib import Path
210-
211-
from cclib.io import ccread
208+
from cclib.io import ccread # noqa: PLC0415
212209

213210
path = Path(fname)
214211
try:

notebooks/workflow_workspace.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@
161161
"metadata": {},
162162
"outputs": [],
163163
"source": [
164-
"# from aiida.plugins import load_code\n",
164+
"from aiida.plugins import load_code\n",
165+
"\n",
165166
"Dict = DataFactory(\"core.dict\")\n",
166167
"old_workchain = load_node(pk=223)\n",
167168
"builder.structure = old_workchain.inputs.structure.get_structure(index=0)\n",

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ line-length = 88
1212
# TODO: Enable ruff for notebooks
1313
src = ["aiidalab_ispg", "tests"]
1414
target-version = "py39"
15+
extend-exclude = ["notebooks/workflow_workspace.ipynb"]
1516

1617
[tool.ruff.lint]
1718
# Enable pyflakes and pyf-builtins, pyflakes, f=bugbear

tests/app/conftest.py

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

77
import pytest
88
import requests
9+
import requests.exceptions
910
import selenium.webdriver.support.expected_conditions as EC
10-
from requests.exceptions import ConnectionError
1111
from selenium.webdriver.common.by import By
1212
from selenium.webdriver.support.wait import WebDriverWait
1313

@@ -17,7 +17,7 @@ def is_responsive(url):
1717
response = requests.get(url, timeout=200)
1818
if response.status_code == 200:
1919
return True
20-
except ConnectionError:
20+
except requests.exceptions.ConnectionError:
2121
return False
2222

2323

0 commit comments

Comments
 (0)