Skip to content

Commit

Permalink
Fix ruff issues (ISISNeutronMuon#653)
Browse files Browse the repository at this point in the history
Add to workflows
  • Loading branch information
oerc0122 committed Feb 10, 2025
1 parent 3f1535c commit f466bc1
Show file tree
Hide file tree
Showing 83 changed files with 236 additions and 224 deletions.
19 changes: 14 additions & 5 deletions .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 @@ -16,11 +16,20 @@ jobs:
options: "--check --verbose"
src: "MDANSE/Src"

lint-mdanse-gui:
lint_check_ruff_gui:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
- uses: astral-sh/ruff-action@v3
with:
options: "--check --verbose"
src: "MDANSE_GUI/Src"
src: "./MDANSE_GUI/Src"
args: "format --check"

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
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ def left_widgets(self) -> list[QWidget]:
self.combo_boxes = []

for k, v in self.settings.items():

if isinstance(v, bool):
check_layout = QHBoxLayout()
checkbox = QCheckBox()
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@


class CorrelationFramesWidget(FramesWidget):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@


class DerivativeOrderWidget(WidgetBase):

def __init__(self, *args, **kwargs):
super().__init__(*args, layout_type="QHBoxLayout", **kwargs)
self._field = QSpinBox(self._base)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@


class DistHistCutoffWidget(RangeWidget):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@


class HDFTrajectoryWidget(WidgetBase):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
source_object = kwargs.get("source_object", None)
Expand Down
3 changes: 1 addition & 2 deletions MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/InputFileWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@


class InputFileWidget(WidgetBase):

def __init__(self, *args, file_dialog=QFileDialog.getOpenFileName, **kwargs):
super().__init__(*args, **kwargs)
configurator = kwargs.get("configurator", None)
Expand Down Expand Up @@ -103,7 +102,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 @@ -23,7 +23,6 @@
class MDAnalysisCoordinateFileWidget(
MultiInputFileWidget, MDAnalysisTopologyFileWidget
):

def __init__(self, *args, file_dialog=QFileDialog.getOpenFileNames, **kwargs):
super().__init__(
*args,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@


class MDAnalysisMDTrajTimeStepWidget(FloatWidget):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@


class MDAnalysisTopologyFileWidget(InputFileWidget):

def __init__(self, *args, format_options=sorted(mda._PARSERS.keys()), **kwargs):
self.format_options = ["AUTO"] + list(format_options)
super().__init__(*args, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@


class MDTrajTopologyFileWidget(InputFileWidget):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@


class MultiInputFileWidget(InputFileWidget):

def __init__(self, *args, file_dialog=QFileDialog.getOpenFileNames, **kwargs):
super().__init__(
*args,
Expand All @@ -37,7 +36,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 +56,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 @@ -22,7 +22,6 @@


class OptionalFloatWidget(WidgetBase):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
try:
Expand Down
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 @@ -39,7 +39,6 @@


class OutputTrajectoryWidget(WidgetBase):

def __init__(self, *args, **kwargs):
super().__init__(*args, layout_type="QGridLayout", **kwargs)
default_value = self._configurator.default
Expand All @@ -62,7 +61,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
1 change: 0 additions & 1 deletion MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/QVectorsWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@


class VectorModel(QStandardItemModel):

type_changed = Signal()
input_is_valid = Signal(bool)

Expand Down
3 changes: 1 addition & 2 deletions MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/RangeWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@


class RangeWidget(WidgetBase):

def __init__(self, *args, **kwargs):
super().__init__(*args, layout_type="QGridLayout", **kwargs)
self.setup_fields(*args, **kwargs)
Expand Down Expand Up @@ -95,7 +94,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
3 changes: 1 addition & 2 deletions MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/UnitCellWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@


class UnitCellWidget(WidgetBase):

def __init__(self, *args, **kwargs):
super().__init__(*args, layout_type="grid", **kwargs)
self._changing_label = QLabel("Unit cell", parent=self._base)
Expand Down Expand Up @@ -81,7 +80,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
3 changes: 1 addition & 2 deletions MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/WidgetBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@


class WidgetBase(QObject):

valid_changed = Signal()
value_updated = Signal()
value_changed = Signal()
Expand Down Expand Up @@ -126,7 +125,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
Loading

0 comments on commit f466bc1

Please sign in to comment.