Skip to content

Commit

Permalink
Fix ruff issues
Browse files Browse the repository at this point in the history
Add to workflows
  • Loading branch information
oerc0122 committed Feb 3, 2025
1 parent 3a32499 commit 5982406
Show file tree
Hide file tree
Showing 52 changed files with 206 additions and 143 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/black.yml → .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Black
name: Lint

on:
push:
Expand All @@ -24,3 +24,12 @@ jobs:
with:
options: "--check --verbose"
src: "MDANSE_GUI/Src"

lint_check_ruff_gui:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/ruff-action@v3
with:
src: "./MDANSE_GUI/Src"
args: "check"
8 changes: 4 additions & 4 deletions MDANSE_GUI/Src/MDANSE_GUI/ElementsDatabaseEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def new_line_dialog(self):
ne_dialog = InputDialog(fields=dialog_variables)
ne_dialog.got_values.connect(self.add_new_line)
ne_dialog.show()
result = ne_dialog.exec()
_result = ne_dialog.exec()

@Slot()
def new_column_dialog(self):
Expand All @@ -173,7 +173,7 @@ def new_column_dialog(self):
ne_dialog = InputDialog(fields=dialog_variables)
ne_dialog.got_values.connect(self.add_new_column)
ne_dialog.show()
result = ne_dialog.exec()
_result = ne_dialog.exec()

@Slot(dict)
def add_new_line(self, input_variables: dict):
Expand All @@ -182,7 +182,7 @@ def add_new_line(self, input_variables: dict):
new_label = input_variables["atom_name"]
except KeyError:
return None
if not new_label in self.database.atoms:
if new_label not in self.database.atoms:
self.database.add_atom(new_label)
row = []
for key in self.all_column_names:
Expand All @@ -209,7 +209,7 @@ def add_new_column(self, input_variables: dict):
new_type = input_variables["property_type"]
except KeyError:
return None
if not new_label in self.database.atoms:
if new_label not in self.database.atoms:
self.database.add_property(new_label, new_type)
column = []
for key in self.all_row_names:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def valueFromDialog(self):
self.updateValue()
try:
type_guess = filetype(new_value[0])
except:
except Exception:
type_guess = "guess"
self._type_combo.setCurrentText(type_guess)

Expand Down
2 changes: 1 addition & 1 deletion MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/BackupWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class BackupWidget(WidgetBase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
source_object = kwargs.get("source_object", None)
_source_object = kwargs.get("source_object", None)
self._field = QLineEdit(str(self._configurator.default))
self._field.setPlaceholderText(str(self._configurator.default))
self._layout.addWidget(self._field)
Expand Down
2 changes: 1 addition & 1 deletion MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/DummyWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class DummyWidget(WidgetBase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
source_object = kwargs.get("source_object", None)
_source_object = kwargs.get("source_object", None)
self._layout.addWidget(QLabel("content is missing here", self._base))
self._configurator = {"value": "Oops!"}
self.default_labels()
Expand Down
4 changes: 2 additions & 2 deletions MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/FramesWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, *args, **kwargs):
if trajectory_configurator is not None:
try:
self._last_frame = trajectory_configurator["length"]
except:
except Exception:
self._last_frame = -1
else:
self._last_frame = -1
Expand Down Expand Up @@ -93,7 +93,7 @@ def get_widget_value(self):
strval = field.text()
try:
val = int(strval)
except:
except Exception:
val = int(self._default_values[n])
result.append(val)
return result
2 changes: 1 addition & 1 deletion MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/InputFileWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def valueFromDialog(self):
self._parent._default_path = str(
PurePath(os.path.split(new_value[0])[0])
)
except:
except Exception:
LOG.error(
f"session.set_path failed for {self._job_name}, {os.path.split(new_value[0])[0]}"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
class InterpolationOrderWidget(WidgetBase):
def __init__(self, *args, **kwargs):
super().__init__(*args, layout_type="QHBoxLayout", **kwargs)
source_object = kwargs.get("source_object", None)
_source_object = kwargs.get("source_object", None)

self._field = QSpinBox(self._base)
self._field.setMaximum(5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def valueFromDialog(self):
paths_group = self._settings.group("paths")
try:
self.default_path = paths_group.get(self._job_name)
except:
except Exception:
LOG.warning(f"session.get_path failed for {self._job_name}")
new_value = self._file_dialog(
self.parent(),
Expand All @@ -57,7 +57,7 @@ def valueFromDialog(self):
paths_group.set(
self._job_name, str(PurePath(os.path.split(new_value[0][0])[0]))
)
except:
except Exception:
LOG.error(
f"session.set_path failed for {self._job_name}, {os.path.split(new_value[0][0])[0]}"
)
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, *args, **kwargs):
guess_name = str(
PurePath(os.path.join(self.default_path, jobname + "_result1"))
)
except:
except Exception:
guess_name = str(PurePath(default_value[0]))
LOG.error("It was not possible to get the job name from the parent")
while os.path.exists(guess_name + ".mda"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, *args, **kwargs):
try:
parent = kwargs.get("parent", None)
guess_name = str(PurePath(os.path.join(self.default_path, "POSCAR")))
except:
except Exception:
guess_name = str(PurePath(default_value[0]))
LOG.error("It was not possible to get the job name from the parent")
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self, *args, **kwargs):
guess_name = str(
PurePath(os.path.join(self.default_path, jobname + "_trajectory1"))
)
except:
except Exception:
guess_name = str(PurePath(default_value[0]))
LOG.error("It was not possible to get the job name from the parent")
while os.path.exists(guess_name + ".mdt"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def update_charge_textbox(self) -> None:
"""
map = self.mapper.get_full_setting()

text = [f"Partial charge mapping:\n"]
text = ["Partial charge mapping:\n"]
atoms = self.selector.system.atom_list
for idx, charge in map.items():
text.append(f"{idx} ({atoms[idx]}) -> {charge}\n")
Expand Down
2 changes: 1 addition & 1 deletion MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/ProjectionWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class ProjectionWidget(WidgetBase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
source_object = kwargs.get("source_object", None)
_source_object = kwargs.get("source_object", None)
bgroup = QButtonGroup(self._base)
for id, blabel in enumerate(["None", "Axial", "Planar"]):
rbutton = QRadioButton(blabel, parent=self._base)
Expand Down
2 changes: 1 addition & 1 deletion MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/RangeWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def get_widget_value(self):
strval = field.text()
try:
val = self._num_type(strval)
except:
except Exception:
val = self._num_type(self._default_values[n])
result.append(val)
return result
2 changes: 1 addition & 1 deletion MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/UnitCellWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def get_widget_value(self):
for key, value in self._array_fields.items():
try:
array[key[0]][key[1]] = float(value.text())
except:
except Exception:
LOG.error(
f"Could not set value ({key[0]}, {key[1]}) to {value.text()}"
)
Expand Down
2 changes: 1 addition & 1 deletion MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/VectorWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ def get_widget_value(self):
"""Collect the results from the input widgets and return the value."""
try:
vector = [float(x.text()) for x in self._vector_fields]
except:
except Exception:
vector = [0, 0, 0]
return vector
2 changes: 1 addition & 1 deletion MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/WidgetBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def updateValue(self):
self.configure_using_default()
try:
self._configurator.configure(current_value)
except:
except Exception:
self.mark_error(
"COULD NOT SET THIS VALUE - you may need to change the values in other widgets"
)
Expand Down
4 changes: 2 additions & 2 deletions MDANSE_GUI/Src/MDANSE_GUI/MolecularViewer/Contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def parseInformation(self, unique=True):
atom_ids = self._reader.atom_ids
grouped_by_type = {}
name_by_type = {}
colour_by_type = {}
radius_by_type = {}
_colour_by_type = {}
_radius_by_type = {}
unique_types = np.unique(atom_types)
for type in unique_types:
crit = np.where(atom_types == type)
Expand Down
2 changes: 1 addition & 1 deletion MDANSE_GUI/Src/MDANSE_GUI/MolecularViewer/Controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
class ViewerControls(QWidget):
def __init__(self, *args, **kwargs):
super(QWidget, self).__init__(*args, **kwargs)
layout = QGridLayout(self)
_layout = QGridLayout(self)
self._viewer = None
self._buttons = {}
self._delegates = {}
Expand Down
7 changes: 4 additions & 3 deletions MDANSE_GUI/Src/MDANSE_GUI/MolecularViewer/MolecularViewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

from typing import List

import numpy as np
Expand Down Expand Up @@ -199,9 +200,9 @@ def _draw_isosurface(self, index):

LOG.info("Computing isosurface ...")

initial_coords = self._reader.read_frame(0)
_initial_coords = self._reader.read_frame(0)
coords, lower_bounds, upper_bounds = self._reader.read_atom_trajectory(index)
spacing, self._atomic_trace_histogram = histogram_3d(
spacing, self._atomic_trace_histogram = histogram_3d( # noqa
coords, lower_bounds, upper_bounds, 100, 100, 100
)

Expand Down Expand Up @@ -548,7 +549,7 @@ def on_open_atomic_trace_settings_dialog(self):
hist_max = self._atomic_trace_histogram.max()
hist_mean = self._atomic_trace_histogram.mean()

dlg = AtomicTraceSettingsDialog(hist_min, hist_max, hist_mean, self)
dlg = AtomicTraceSettingsDialog(hist_min, hist_max, hist_mean, self) # noqa

dlg.rendering_type_changed.connect(self.on_change_atomic_trace_rendering_type)
dlg.opacity_changed.connect(self.on_change_atomic_trace_opacity)
Expand Down
4 changes: 2 additions & 2 deletions MDANSE_GUI/Src/MDANSE_GUI/Session/LocalSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def save(self, fname: str = None):
try:
with open(fname, "w") as target:
target.write(output)
except:
except Exception:
return
else:
self._filename = fname
Expand All @@ -122,7 +122,7 @@ def load(self, fname: str = None):
try:
with open(fname, "r") as source:
all_items_text = source.readline()
except:
except Exception:
LOG.warning(f"Failed to read session settings from {fname}")
else:
all_items = json_decoder.decode(all_items_text)
Expand Down
2 changes: 1 addition & 1 deletion MDANSE_GUI/Src/MDANSE_GUI/Session/StructuredSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def save_new_value(self, item_index: QModelIndex):
group.set(item_key, new_value)
elif column_number == 2:
group.set_comment(item_key, new_value)
except:
except Exception:
LOG.warning(
f"Could not store {new_value} in group[{group_key}]->[{item_key}]"
)
Expand Down
6 changes: 3 additions & 3 deletions MDANSE_GUI/Src/MDANSE_GUI/Subprocess/JobStatusProcess.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ def terminate_the_process(self):
LOG.info(f"JobCommunicator PID: {os.getpid()} started 'terminate_the_process")
try:
self._process.terminate()
except:
except Exception:
return
else:
try:
self._process.close()
except:
except Exception:
return


Expand Down Expand Up @@ -91,7 +91,7 @@ def start_status(self):
LOG.info(f"JobStatusProcess PID: {os.getpid()} started 'start_status")
try:
temp = int(self._nSteps)
except:
except Exception:
self._pipe.send(("STARTED", None))
else:
self._pipe.send(("STARTED", temp))
Expand Down
2 changes: 1 addition & 1 deletion MDANSE_GUI/Src/MDANSE_GUI/TabbedWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def version_information(self):
version = ""
version += f"MDANSE version: {metadata.version('MDANSE')}\n"
version += f"MDANSE_GUI version: {metadata.version('MDANSE_GUI')}\n"
popup = QMessageBox.about(self, "MDANSE Version Information", version)
_popup = QMessageBox.about(self, "MDANSE Version Information", version)

def setupToolbar(self):
self._toolBar = QToolBar("Main MDANSE toolbar", self)
Expand Down
2 changes: 1 addition & 1 deletion MDANSE_GUI/Src/MDANSE_GUI/Tabs/GeneralTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def conversion_factor(self, input_unit: str) -> Tuple[float, str]:
conversion_factor = measure(1.0, input_unit, equivalent=True).toval(
target_unit
)
except:
except Exception:
target_unit = self._settings.default_value("units", property)
conversion_factor = measure(1.0, input_unit, equivalent=True).toval(
target_unit
Expand Down
4 changes: 2 additions & 2 deletions MDANSE_GUI/Src/MDANSE_GUI/Tabs/LoggingTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def change_log_level(self, new_level: str):
return
try:
self._extra_handler.setLevel(new_level)
except:
except Exception:
LOG.error(f"Could not set GuiLogHandler to log level {new_level}")
else:
self._visualiser.append_text(
Expand All @@ -88,7 +88,7 @@ def change_log_level(self, new_level: str):
def add_handler(self, new_handler):
try:
current_level = self._loglevel_combo.currentText()
except:
except Exception:
current_level = "INFO"
self._extra_handler = new_handler
self._extra_handler.add_visualiser(self._visualiser)
Expand Down
6 changes: 3 additions & 3 deletions MDANSE_GUI/Src/MDANSE_GUI/Tabs/Models/JobHolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def run(self):
while self._keep_running:
try:
status_update = self._pipe_end.recv()
except:
except Exception:
self.fail()
else:
self._job_comm.status_update(status_update)
Expand Down Expand Up @@ -329,7 +329,7 @@ def startProcess(self, job_vars: list, load_afterwards=False):
else:
try:
int(job_vars[1]["output_files"][1])
except:
except Exception:
item_th.for_loading.connect(self.results_for_loading)
else:
item_th.for_loading.connect(self.trajectory_for_loading)
Expand All @@ -341,7 +341,7 @@ def startProcess(self, job_vars: list, load_afterwards=False):
watcher_thread.start()
try:
task_name = str(job_vars[0])
except:
except Exception:
task_name = str("This should have been a job name")
name_item = QStandardItem(task_name)
name_item.setData(entry_number, role=Qt.ItemDataRole.UserRole)
Expand Down
2 changes: 1 addition & 1 deletion MDANSE_GUI/Src/MDANSE_GUI/Tabs/Models/JobTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def parentsFromCategories(self, category_tuple):
"""
parent = self.invisibleRootItem()
for cat_string in category_tuple:
if not cat_string in self._categories.keys():
if cat_string not in self._categories:
current_node = QStandardItem(cat_string)
parent.appendRow(current_node)
parent = current_node
Expand Down
2 changes: 1 addition & 1 deletion MDANSE_GUI/Src/MDANSE_GUI/Tabs/Models/PlotDataModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def populate(self, file):
child.setData(key, role=Qt.ItemDataRole.UserRole)
try:
file[key][:]
except:
except Exception:
child._item_type = "group"
self.appendRow(child)

Expand Down
Loading

0 comments on commit 5982406

Please sign in to comment.