From f466bc181512f22e86976c57ad5eca64b0398ff4 Mon Sep 17 00:00:00 2001 From: Jacob Wilkins <46597752+oerc0122@users.noreply.github.com> Date: Mon, 10 Feb 2025 13:27:28 +0000 Subject: [PATCH] Fix ruff issues (#653) Add to workflows --- .github/workflows/{black.yml => lint.yml} | 19 +++-- .../Src/MDANSE_GUI/ElementsDatabaseEditor.py | 8 +- .../InputWidgets/AseInputFileWidget.py | 2 +- .../InputWidgets/AtomSelectionWidget.py | 1 - .../MDANSE_GUI/InputWidgets/BackupWidget.py | 2 +- .../InputWidgets/CorrelationFramesWidget.py | 1 - .../InputWidgets/DerivativeOrderWidget.py | 1 - .../InputWidgets/DistHistCutoffWidget.py | 1 - .../MDANSE_GUI/InputWidgets/DummyWidget.py | 2 +- .../MDANSE_GUI/InputWidgets/FramesWidget.py | 4 +- .../InputWidgets/HDFTrajectoryWidget.py | 1 - .../InputWidgets/InputFileWidget.py | 3 +- .../InputWidgets/InterpolationOrderWidget.py | 2 +- .../MDAnalysisCoordinateFileWidget.py | 1 - .../MDAnalysisMDTrajTimeStepWidget.py | 1 - .../MDAnalysisTopologyFileWidget.py | 1 - .../InputWidgets/MDTrajTopologyFileWidget.py | 1 - .../InputWidgets/MultiInputFileWidget.py | 5 +- .../InputWidgets/OptionalFloatWidget.py | 1 - .../InputWidgets/OutputFilesWidget.py | 2 +- .../InputWidgets/OutputStructureWidget.py | 2 +- .../InputWidgets/OutputTrajectoryWidget.py | 3 +- .../InputWidgets/PartialChargeWidget.py | 2 +- .../InputWidgets/ProjectionWidget.py | 2 +- .../MDANSE_GUI/InputWidgets/QVectorsWidget.py | 1 - .../MDANSE_GUI/InputWidgets/RangeWidget.py | 3 +- .../MDANSE_GUI/InputWidgets/UnitCellWidget.py | 3 +- .../MDANSE_GUI/InputWidgets/VectorWidget.py | 2 +- .../Src/MDANSE_GUI/InputWidgets/WidgetBase.py | 3 +- .../MDANSE_GUI/MolecularViewer/Contents.py | 4 +- .../MDANSE_GUI/MolecularViewer/Controls.py | 2 +- .../MolecularViewer/MolecularViewer.py | 7 +- .../Src/MDANSE_GUI/Session/LocalSession.py | 4 +- .../MDANSE_GUI/Session/StructuredSession.py | 6 +- .../Src/MDANSE_GUI/Subprocess/JobState.py | 7 -- .../MDANSE_GUI/Subprocess/JobStatusProcess.py | 6 +- .../Src/MDANSE_GUI/Subprocess/Subprocess.py | 1 - MDANSE_GUI/Src/MDANSE_GUI/TabbedWindow.py | 2 +- MDANSE_GUI/Src/MDANSE_GUI/Tabs/GeneralTab.py | 2 +- .../Src/MDANSE_GUI/Tabs/InstrumentTab.py | 1 - MDANSE_GUI/Src/MDANSE_GUI/Tabs/LoggingTab.py | 5 +- .../Src/MDANSE_GUI/Tabs/Models/JobHolder.py | 8 +- .../Src/MDANSE_GUI/Tabs/Models/JobTree.py | 2 +- .../MDANSE_GUI/Tabs/Models/PlotDataModel.py | 5 +- .../MDANSE_GUI/Tabs/Models/PlottingContext.py | 15 ++-- .../Tabs/PlotModifiers/AxesWrapper.py | 1 - .../Tabs/PlotModifiers/NormGenerator.py | 1 - .../Tabs/PlotModifiers/WeightGenerator.py | 1 - .../Src/MDANSE_GUI/Tabs/PlotSelectionTab.py | 1 - MDANSE_GUI/Src/MDANSE_GUI/Tabs/PlotTab.py | 1 - .../Src/MDANSE_GUI/Tabs/Plotters/Grid.py | 3 +- .../Src/MDANSE_GUI/Tabs/Plotters/Heatmap.py | 9 +- .../Src/MDANSE_GUI/Tabs/Plotters/Plotter.py | 1 - .../Tabs/Plotters/PlotterTemplate.py | 19 ++--- .../Src/MDANSE_GUI/Tabs/Plotters/Single.py | 5 +- .../Src/MDANSE_GUI/Tabs/Plotters/Text.py | 6 +- .../Src/MDANSE_GUI/Tabs/TrajectoryTab.py | 1 - .../Src/MDANSE_GUI/Tabs/Views/ActionsTree.py | 3 +- .../Src/MDANSE_GUI/Tabs/Views/Delegates.py | 7 +- .../Src/MDANSE_GUI/Tabs/Views/PlotDataView.py | 5 +- .../Src/MDANSE_GUI/Tabs/Views/RunTable.py | 3 +- .../MDANSE_GUI/Tabs/Views/TrajectoryView.py | 3 +- .../Src/MDANSE_GUI/Tabs/Visualisers/Action.py | 84 +++++++++++++------ .../Tabs/Visualisers/AnalysisInfo.py | 4 +- .../Tabs/Visualisers/DataPlotter.py | 2 +- .../MDANSE_GUI/Tabs/Visualisers/DataWidget.py | 19 ++--- .../Tabs/Visualisers/InstrumentDetails.py | 3 +- .../Tabs/Visualisers/InstrumentInfo.py | 10 +-- .../MDANSE_GUI/Tabs/Visualisers/JobLogInfo.py | 1 - .../Tabs/Visualisers/PlotDataInfo.py | 2 +- .../Tabs/Visualisers/PlotSettings.py | 29 ++++--- .../MDANSE_GUI/Tabs/Visualisers/PlotWidget.py | 4 +- MDANSE_GUI/Src/MDANSE_GUI/UnitsEditor.py | 2 +- .../Src/MDANSE_GUI/UserSettingsEditor.py | 1 - .../Src/MDANSE_GUI/Widgets/DataDialog.py | 2 +- .../Src/MDANSE_GUI/Widgets/DelayedButton.py | 1 - .../Src/MDANSE_GUI/Widgets/GeneralWidgets.py | 4 +- .../Widgets/NotificationTabWidget.py | 1 - .../MDANSE_GUI/Widgets/ResolutionDialog.py | 1 - .../MDANSE_GUI/Widgets/ResolutionWidget.py | 14 ++-- .../MDANSE_GUI/Widgets/RestrictedSlider.py | 1 - .../Src/MDANSE_GUI/Widgets/VectorWidget.py | 5 +- MDANSE_GUI/pyproject.toml | 43 ++++++++++ 83 files changed, 236 insertions(+), 224 deletions(-) rename .github/workflows/{black.yml => lint.yml} (50%) diff --git a/.github/workflows/black.yml b/.github/workflows/lint.yml similarity index 50% rename from .github/workflows/black.yml rename to .github/workflows/lint.yml index 6f3db0d75b..bcf4605c70 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/lint.yml @@ -1,4 +1,4 @@ -name: Black +name: Lint on: push: @@ -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" diff --git a/MDANSE_GUI/Src/MDANSE_GUI/ElementsDatabaseEditor.py b/MDANSE_GUI/Src/MDANSE_GUI/ElementsDatabaseEditor.py index f95606019b..451564b7f6 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/ElementsDatabaseEditor.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/ElementsDatabaseEditor.py @@ -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): @@ -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): @@ -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: @@ -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: diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/AseInputFileWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/AseInputFileWidget.py index 2cfad49425..5f9acd718a 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/AseInputFileWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/AseInputFileWidget.py @@ -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) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/AtomSelectionWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/AtomSelectionWidget.py index c7c6c784dc..64285f7197 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/AtomSelectionWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/AtomSelectionWidget.py @@ -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() diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/BackupWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/BackupWidget.py index 3ae63d7d04..8818a38160 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/BackupWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/BackupWidget.py @@ -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) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/CorrelationFramesWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/CorrelationFramesWidget.py index 475a577ebc..ef2a5b63f9 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/CorrelationFramesWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/CorrelationFramesWidget.py @@ -22,7 +22,6 @@ class CorrelationFramesWidget(FramesWidget): - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/DerivativeOrderWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/DerivativeOrderWidget.py index 55d76721eb..9d270296a2 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/DerivativeOrderWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/DerivativeOrderWidget.py @@ -29,7 +29,6 @@ class DerivativeOrderWidget(WidgetBase): - def __init__(self, *args, **kwargs): super().__init__(*args, layout_type="QHBoxLayout", **kwargs) self._field = QSpinBox(self._base) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/DistHistCutoffWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/DistHistCutoffWidget.py index 0edcf66527..1a9d59069b 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/DistHistCutoffWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/DistHistCutoffWidget.py @@ -18,7 +18,6 @@ class DistHistCutoffWidget(RangeWidget): - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/DummyWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/DummyWidget.py index 415305d5bd..8b5d2c2e12 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/DummyWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/DummyWidget.py @@ -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() diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/FramesWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/FramesWidget.py index 73a53fdba1..99a0de9ae2 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/FramesWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/FramesWidget.py @@ -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 @@ -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 diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/HDFTrajectoryWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/HDFTrajectoryWidget.py index 46de7aa1e5..df93080dcc 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/HDFTrajectoryWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/HDFTrajectoryWidget.py @@ -22,7 +22,6 @@ class HDFTrajectoryWidget(WidgetBase): - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) source_object = kwargs.get("source_object", None) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/InputFileWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/InputFileWidget.py index 2daaaab7b8..b7f126a046 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/InputFileWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/InputFileWidget.py @@ -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) @@ -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]}" ) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/InterpolationOrderWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/InterpolationOrderWidget.py index 84a2340230..567788bfa2 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/InterpolationOrderWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/InterpolationOrderWidget.py @@ -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) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/MDAnalysisCoordinateFileWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/MDAnalysisCoordinateFileWidget.py index 699ff6c460..6e32209d0d 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/MDAnalysisCoordinateFileWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/MDAnalysisCoordinateFileWidget.py @@ -23,7 +23,6 @@ class MDAnalysisCoordinateFileWidget( MultiInputFileWidget, MDAnalysisTopologyFileWidget ): - def __init__(self, *args, file_dialog=QFileDialog.getOpenFileNames, **kwargs): super().__init__( *args, diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/MDAnalysisMDTrajTimeStepWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/MDAnalysisMDTrajTimeStepWidget.py index 0457e089c2..b8215386a4 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/MDAnalysisMDTrajTimeStepWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/MDAnalysisMDTrajTimeStepWidget.py @@ -17,7 +17,6 @@ class MDAnalysisMDTrajTimeStepWidget(FloatWidget): - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/MDAnalysisTopologyFileWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/MDAnalysisTopologyFileWidget.py index 2f3ea88807..d6c832b704 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/MDAnalysisTopologyFileWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/MDAnalysisTopologyFileWidget.py @@ -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) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/MDTrajTopologyFileWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/MDTrajTopologyFileWidget.py index a85634f9f1..893b97534f 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/MDTrajTopologyFileWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/MDTrajTopologyFileWidget.py @@ -17,7 +17,6 @@ class MDTrajTopologyFileWidget(InputFileWidget): - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/MultiInputFileWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/MultiInputFileWidget.py index 3fb641da95..cc94abbeff 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/MultiInputFileWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/MultiInputFileWidget.py @@ -24,7 +24,6 @@ class MultiInputFileWidget(InputFileWidget): - def __init__(self, *args, file_dialog=QFileDialog.getOpenFileNames, **kwargs): super().__init__( *args, @@ -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(), @@ -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]}" ) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/OptionalFloatWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/OptionalFloatWidget.py index 5dfba5784f..07804849b8 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/OptionalFloatWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/OptionalFloatWidget.py @@ -22,7 +22,6 @@ class OptionalFloatWidget(WidgetBase): - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) try: diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/OutputFilesWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/OutputFilesWidget.py index de0bb80563..22f1ca1c34 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/OutputFilesWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/OutputFilesWidget.py @@ -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"): diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/OutputStructureWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/OutputStructureWidget.py index 809b3cec6f..a0c73b25b8 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/OutputStructureWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/OutputStructureWidget.py @@ -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: diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/OutputTrajectoryWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/OutputTrajectoryWidget.py index 5df88bf814..059d2a350d 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/OutputTrajectoryWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/OutputTrajectoryWidget.py @@ -39,7 +39,6 @@ class OutputTrajectoryWidget(WidgetBase): - def __init__(self, *args, **kwargs): super().__init__(*args, layout_type="QGridLayout", **kwargs) default_value = self._configurator.default @@ -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"): diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/PartialChargeWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/PartialChargeWidget.py index d9d9b97703..4d357189aa 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/PartialChargeWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/PartialChargeWidget.py @@ -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") diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/ProjectionWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/ProjectionWidget.py index d9431c7665..650bde8ac9 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/ProjectionWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/ProjectionWidget.py @@ -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) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/QVectorsWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/QVectorsWidget.py index b61d868b58..f2722755a7 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/QVectorsWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/QVectorsWidget.py @@ -24,7 +24,6 @@ class VectorModel(QStandardItemModel): - type_changed = Signal() input_is_valid = Signal(bool) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/RangeWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/RangeWidget.py index 9a37357e3a..0fc198860c 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/RangeWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/RangeWidget.py @@ -22,7 +22,6 @@ class RangeWidget(WidgetBase): - def __init__(self, *args, **kwargs): super().__init__(*args, layout_type="QGridLayout", **kwargs) self.setup_fields(*args, **kwargs) @@ -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 diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/UnitCellWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/UnitCellWidget.py index 9cd21342a2..3232d8ef65 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/UnitCellWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/UnitCellWidget.py @@ -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) @@ -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()}" ) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/VectorWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/VectorWidget.py index e976061e92..8865afbd8c 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/VectorWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/VectorWidget.py @@ -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 diff --git a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/WidgetBase.py b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/WidgetBase.py index bc87a69524..86be1bc077 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/WidgetBase.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/WidgetBase.py @@ -29,7 +29,6 @@ class WidgetBase(QObject): - valid_changed = Signal() value_updated = Signal() value_changed = Signal() @@ -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" ) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/MolecularViewer/Contents.py b/MDANSE_GUI/Src/MDANSE_GUI/MolecularViewer/Contents.py index 1365f6e9ae..10cda18707 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/MolecularViewer/Contents.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/MolecularViewer/Contents.py @@ -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) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/MolecularViewer/Controls.py b/MDANSE_GUI/Src/MDANSE_GUI/MolecularViewer/Controls.py index 49518e1aa8..a1acbcc0f0 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/MolecularViewer/Controls.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/MolecularViewer/Controls.py @@ -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 = {} diff --git a/MDANSE_GUI/Src/MDANSE_GUI/MolecularViewer/MolecularViewer.py b/MDANSE_GUI/Src/MDANSE_GUI/MolecularViewer/MolecularViewer.py index 7f48c6a2fd..fdc22a3318 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/MolecularViewer/MolecularViewer.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/MolecularViewer/MolecularViewer.py @@ -13,6 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # + from typing import List import numpy as np @@ -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 ) @@ -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) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Session/LocalSession.py b/MDANSE_GUI/Src/MDANSE_GUI/Session/LocalSession.py index 23dba24093..c34e96cda4 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Session/LocalSession.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Session/LocalSession.py @@ -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 @@ -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) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Session/StructuredSession.py b/MDANSE_GUI/Src/MDANSE_GUI/Session/StructuredSession.py index 4ea4b1e230..94af2a50a3 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Session/StructuredSession.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Session/StructuredSession.py @@ -29,7 +29,6 @@ class UserSettingsModel(QStandardItemModel): - file_loaded = Signal(str) def __init__(self, *args, settings_filename: str = "", **kwargs): @@ -135,7 +134,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}]" ) @@ -187,7 +186,6 @@ def writeout_settings(self): class SettingsGroup: - def __init__(self, group_name: str) -> None: self._name = group_name self._settings = {} @@ -261,9 +259,7 @@ def as_dict(self): class SettingsFile: - def __init__(self, name, settings_path: str = None): - if settings_path is None: settings_path = PLATFORM.application_directory() self._top_name = name diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Subprocess/JobState.py b/MDANSE_GUI/Src/MDANSE_GUI/Subprocess/JobState.py index 9a220476c0..84f812349e 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Subprocess/JobState.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Subprocess/JobState.py @@ -17,7 +17,6 @@ class JobState(ABC): - _label = "JobState" _allowed_actions = [] @@ -54,7 +53,6 @@ def fail(self): class Running(JobState): - _label = "Running" _allowed_actions = [ "Pause", @@ -92,7 +90,6 @@ def fail(self): class Aborted(JobState): - _label = "Aborted" _allowed_actions = ["Delete"] @@ -119,7 +116,6 @@ def fail(self): class Failed(JobState): - _label = "Failed" _allowed_actions = ["Delete"] @@ -146,7 +142,6 @@ def fail(self): class Finished(JobState): - _label = "Finished" _allowed_actions = ["Delete"] @@ -173,7 +168,6 @@ def fail(self): class Starting(JobState): - _label = "Starting" _allowed_actions = [ "Pause", @@ -206,7 +200,6 @@ def fail(self): class Paused(JobState): - _label = "Paused" _allowed_actions = [ "Resume", diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Subprocess/JobStatusProcess.py b/MDANSE_GUI/Src/MDANSE_GUI/Subprocess/JobStatusProcess.py index 8bb1c505f3..fc5052de11 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Subprocess/JobStatusProcess.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Subprocess/JobStatusProcess.py @@ -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 @@ -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)) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Subprocess/Subprocess.py b/MDANSE_GUI/Src/MDANSE_GUI/Subprocess/Subprocess.py index 3056ab7b33..d321946827 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Subprocess/Subprocess.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Subprocess/Subprocess.py @@ -26,7 +26,6 @@ class Subprocess(Process): - def __init__(self, *args, **kwargs): super().__init__() job_name = kwargs.get("job_name") diff --git a/MDANSE_GUI/Src/MDANSE_GUI/TabbedWindow.py b/MDANSE_GUI/Src/MDANSE_GUI/TabbedWindow.py index af0e29d32e..a684a0088e 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/TabbedWindow.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/TabbedWindow.py @@ -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) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/GeneralTab.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/GeneralTab.py index 37635b55ea..51cc0e9ca2 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/GeneralTab.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/GeneralTab.py @@ -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 diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/InstrumentTab.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/InstrumentTab.py index 0406482504..28ab525b58 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/InstrumentTab.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/InstrumentTab.py @@ -42,7 +42,6 @@ class InstrumentTab(GeneralTab): - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._core.add_button("Create Instrument", self._view.add_instrument) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/LoggingTab.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/LoggingTab.py index d41cb5b055..9d2f41bfc4 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/LoggingTab.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/LoggingTab.py @@ -36,7 +36,6 @@ class GuiLogHandler(Handler): - def __init__(self, *args, **kwargs): self._visualiser = None super().__init__(*args, **kwargs) @@ -78,7 +77,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( @@ -88,7 +87,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) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Models/JobHolder.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Models/JobHolder.py index f001a5cfe6..be126de2b6 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Models/JobHolder.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Models/JobHolder.py @@ -38,7 +38,6 @@ class JobThread(QThread): - def __init__( self, job_comm: "JobCommunicator", @@ -83,14 +82,13 @@ 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) class JobLogHandler(Handler): - def __init__(self): super().__init__() self.records = [] @@ -329,7 +327,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) @@ -341,7 +339,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) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Models/JobTree.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Models/JobTree.py index 83d19428b5..c29d48ab75 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Models/JobTree.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Models/JobTree.py @@ -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 diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Models/PlotDataModel.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Models/PlotDataModel.py index f5c2b91b5b..43e43be239 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Models/PlotDataModel.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Models/PlotDataModel.py @@ -58,13 +58,12 @@ def populate(self, file): child.setData(key, role=Qt.ItemDataRole.UserRole) try: file[key][:] - except: + except Exception: child._item_type = "group" self.appendRow(child) class DataSetItem(BasicPlotDataItem): - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._item_type = "dataset" @@ -79,7 +78,6 @@ def file_number(self) -> int: class DataFileItem(BasicPlotDataItem): - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._item_type = "file" @@ -92,7 +90,6 @@ def file_number(self) -> int: class MDADataStructure: - def __init__(self, filename: str): self._file = h5py.File(filename) self.check_metadata() diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Models/PlottingContext.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Models/PlottingContext.py index 5ea30bc5ed..7280973915 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Models/PlottingContext.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Models/PlottingContext.py @@ -56,7 +56,6 @@ def get_mpl_colours(): class SingleDataset: - def __init__(self, name: str, source: "h5py.File"): self._name = name self._filename = source.filename @@ -102,27 +101,27 @@ def set_data_limits(self, limit_string: str): if ":" in token: try: slice_parts = [int(x) for x in token.split(":")] - except: + except Exception: continue if len(slice_parts) < 4: complete_subset_list += list(range(*slice_parts)) elif "-" in token: try: slice_parts = [int(x) for x in token.split("-")] - except: + except Exception: continue if len(slice_parts) == 2: complete_subset_list += list(range(slice_parts[0], slice_parts[1])) elif "," in token: try: slice_parts = [int(x) for x in token.split(",")] - except: + except Exception: continue complete_subset_list += list(slice_parts) else: try: complete_subset_list += [int(token)] - except: + except Exception: continue if len(complete_subset_list) == 0: self._data_limits = None @@ -189,7 +188,7 @@ def curves_vs_axis(self, axis_unit: str) -> List[np.ndarray]: def planes_vs_axis(self, axis_number: int) -> List[np.ndarray]: self._planes = {} self._plane_labels = {} - found = -1 + _found = -1 total_ndim = len(self._data.shape) if total_ndim == 1: return @@ -228,7 +227,6 @@ def planes_vs_axis(self, axis_number: int) -> List[np.ndarray]: class SingleCurve: - def __init__(self, data_name: str, file_name: str, *args, **kwargs): self._name = data_name self._filename = file_name @@ -289,7 +287,6 @@ def standard_items(self, key: int) -> List["QStandardItem"]: class PlottingContext(QStandardItemModel): - needs_an_update = Signal() def __init__(self, *args, unit_lookup=None, **kwargs): @@ -321,7 +318,7 @@ def colormap(self): backup_cmap = "viridis" try: cmap = self._unit_lookup._settings.group("colours").get("colormap") - except: + except Exception: return backup_cmap else: if cmap in mpl.colormaps(): diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/PlotModifiers/AxesWrapper.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/PlotModifiers/AxesWrapper.py index 7b8ae58d89..b5ba9c5f4d 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/PlotModifiers/AxesWrapper.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/PlotModifiers/AxesWrapper.py @@ -24,7 +24,6 @@ class AxesWrapper: - def __init__(self, *args, **kwargs): self._axes = kwargs.pop("axes", None) self._plot_elements = [] diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/PlotModifiers/NormGenerator.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/PlotModifiers/NormGenerator.py index 9e86e0a6a1..2f6ba2bf31 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/PlotModifiers/NormGenerator.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/PlotModifiers/NormGenerator.py @@ -18,6 +18,5 @@ class NullNorms: - def __call__(self, *args, **kwds) -> float: return 1.0 diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/PlotModifiers/WeightGenerator.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/PlotModifiers/WeightGenerator.py index c0ac7a1054..c4f3d4ad1f 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/PlotModifiers/WeightGenerator.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/PlotModifiers/WeightGenerator.py @@ -18,6 +18,5 @@ class NullWeights: - def __call__(self, *args, **kwds) -> float: return 1.0 diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/PlotSelectionTab.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/PlotSelectionTab.py index 3d798ac448..ab0d60d6ad 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/PlotSelectionTab.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/PlotSelectionTab.py @@ -37,7 +37,6 @@ class PlotSelectionTab(GeneralTab): - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._core.add_button("Load .MDA results", self.load_files) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/PlotTab.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/PlotTab.py index d3fb6dde4b..6b3ca87290 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/PlotTab.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/PlotTab.py @@ -36,7 +36,6 @@ class PlotTab(GeneralTab): - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._visualiser._unit_lookup = self diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/Grid.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/Grid.py index 284b8b5e7f..d94ded0577 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/Grid.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/Grid.py @@ -27,7 +27,6 @@ class Grid(Plotter): - def __init__(self) -> None: super().__init__() self._figure = None @@ -103,7 +102,7 @@ def plot( except ValueError: try: temp_curve.set_marker(int(marker)) - except: + except Exception: pass xlimits, ylimits = axes.get_xlim(), axes.get_ylim() try: diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/Heatmap.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/Heatmap.py index 658cf29f08..fea0751b6c 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/Heatmap.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/Heatmap.py @@ -31,7 +31,6 @@ class Heatmap(Plotter): - def __init__(self) -> None: super().__init__() self._figure = None @@ -130,8 +129,8 @@ def plot( self._backup_images = {} self._backup_arrays = {} self._backup_scale_interpolators = {} - xaxis_unit = None - yaxis_unit = None + _xaxis_unit = None + _yaxis_unit = None self._axes = [] if not update_only: self._last_axes_units = {} @@ -158,7 +157,7 @@ def plot( nplots += 1 try: self._backup_scale_interpolators[ds_num](51.2) - except: + except Exception: percentiles = np.linspace(0, 100.0, 21) results = [np.percentile(ds._data, perc) for perc in percentiles] self._backup_scale_interpolators[ds_num] = interp1d( @@ -200,7 +199,7 @@ def plot( conversion_factor = measure(1.0, value, equivalent=True).toval( target_unit ) - except: + except Exception: limits += [axis_array[0], axis_array[-1]] axis_units.append(value) else: diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/Plotter.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/Plotter.py index 564cf42fc4..652cc03043 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/Plotter.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/Plotter.py @@ -27,7 +27,6 @@ class Plotter(metaclass=SubclassFactory): - def __init__(self) -> None: self._figure = None self._axes = [] diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/PlotterTemplate.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/PlotterTemplate.py index c13d756923..8d7ad49328 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/PlotterTemplate.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/PlotterTemplate.py @@ -31,7 +31,6 @@ class PlotterTemplate(metaclass=SubclassFactory): - def __init__(self) -> None: self._figure = None self._axes = {} @@ -73,21 +72,21 @@ def convert_units(self): best_unit, best_axis = (dataset._axes_units[axis_label], axis_label) except KeyError: best_unit, best_axis = dataset.longest_axis() - plotlabel = dataset._labels["medium"] + _plotlabel = dataset._labels["medium"] xaxis_unit = self._plotting_context.get_conversion_factor(best_unit) try: - conversion_factor = measure(1.0, best_unit, equivalent=True).toval( + _conversion_factor = measure(1.0, best_unit, equivalent=True).toval( xaxis_unit ) - except: + except Exception: LOG.warning(f"Could not convert {best_unit} to {xaxis_unit}") - conversion_factor = 1.0 + _conversion_factor = 1.0 def apply_weights(self): for dataset_number, dataset in self._datasets: try: scale_factor = self._weight_generator(dataset) - except: + except Exception: scale_factor = 1.0 self._scale_factors[dataset_number].append([scale_factor]) @@ -95,7 +94,7 @@ def apply_norms(self): for dataset_number, dataset in self._datasets.items(): try: scale_factor = self._norm_generator(dataset) - except: + except Exception: scale_factor = 1.0 self._scale_factors[dataset_number].append([scale_factor]) @@ -191,14 +190,14 @@ def apply_settings(self, plotting_context: "PlottingContext", colours=None): return try: matplotlib_style = colours["style"] - except: + except Exception: pass else: if matplotlib_style is not None: mpl_style.use(matplotlib_style) try: bkg_col = colours["background"] - except: + except Exception: pass else: if bkg_col is not None: @@ -206,7 +205,7 @@ def apply_settings(self, plotting_context: "PlottingContext", colours=None): axes.set_facecolor(bkg_col) try: col_seq = colours["curves"] - except: + except Exception: pass else: if col_seq is not None: diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/Single.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/Single.py index 0dba100ea7..df9edd373b 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/Single.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/Single.py @@ -26,7 +26,6 @@ class Single(Plotter): - def __init__(self) -> None: super().__init__() self._figure = None @@ -146,7 +145,7 @@ def plot( conversion_factor = measure(1.0, best_unit, equivalent=True).toval( xaxis_unit ) - except: + except Exception: continue else: if dataset._n_dim == 1: @@ -162,7 +161,7 @@ def plot( except ValueError: try: temp.set_marker(int(marker)) - except: + except Exception: pass self._active_curves.append(temp) self._backup_curves.append([temp.get_xdata(), temp.get_ydata()]) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/Text.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/Text.py index 9a8aad707d..0fc20d0349 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/Text.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Plotters/Text.py @@ -186,7 +186,7 @@ def process_1D_data( conversion_factor = measure(1.0, best_unit, equivalent=True).toval( xaxis_unit ) - except: + except Exception: return f"Could not convert {best_unit} to {xaxis_unit}." else: header_lines.append(f"{self._comment} units of x axis here: {xaxis_unit}") @@ -316,7 +316,7 @@ def process_ND_data( ) LOG.debug(f"Data shape: {dataset._data.shape}") temp = [] - ncols = len(new_axes) + 1 + _ncols = len(new_axes) + 1 ax_lengths = [len(new_axes[ax_num]) for ax_num in axis_numbers.values()] total_lines = reduce(lambda x, y: x * y, ax_lengths) if is_preview: @@ -472,7 +472,7 @@ def plot( self._toolbar = toolbar self._pc_backup = plotting_context self._figure = target - xaxis_unit = None + _xaxis_unit = None self._active_curves = [] self._backup_curves = [] self.apply_settings(plotting_context, colours) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/TrajectoryTab.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/TrajectoryTab.py index 7a2a79e661..14c8210242 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/TrajectoryTab.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/TrajectoryTab.py @@ -44,7 +44,6 @@ class TrajectoryTab(GeneralTab): - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._core.add_button("Load .MDT Trajectories", self.load_trajectories) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Views/ActionsTree.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Views/ActionsTree.py index 06827b9a63..a463cb5818 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Views/ActionsTree.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Views/ActionsTree.py @@ -100,6 +100,5 @@ def connect_to_visualiser(self, visualiser: Union[Action, TextInfo]) -> None: self.item_details.connect(visualiser.update_panel) else: raise NotImplementedError( - f"Unable to connect view {type(self)} to visualiser " - f"{type(visualiser)}" + f"Unable to connect view {type(self)} to visualiser {type(visualiser)}" ) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Views/Delegates.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Views/Delegates.py index 7b72b38a57..66c85b1131 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Views/Delegates.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Views/Delegates.py @@ -29,7 +29,6 @@ class ColourPicker(QStyledItemDelegate): - def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) @@ -51,7 +50,6 @@ def setModelData(self, editor, model, index): class MainAxisCombo(QItemDelegate): - def __init__(self, *args, **kwargs) -> None: self._items = [] super().__init__(*args, **kwargs) @@ -85,7 +83,6 @@ def currentIndexChanged(self): class MplStyleCombo(QItemDelegate): - def __init__(self, *args, mpl_items=None, **kwargs) -> None: self._items = list([str(x) for x in mpl_items.keys()]) super().__init__(*args, **kwargs) @@ -118,7 +115,6 @@ def currentIndexChanged(self): class RadiusSpinBox(QItemDelegate): - def __init__(self, *args, mpl_items=None, **kwargs) -> None: self._minimum = 0.0 self._step = 0.01 @@ -144,7 +140,6 @@ def valueChanged(self): class ProgressDelegate(QItemDelegate): - progress_role = Qt.UserRole + 1000 def paint(self, painter, option, index): @@ -152,7 +147,7 @@ def paint(self, painter, option, index): progress_max = max(index.data(self.progress_role + 1) - 1, 1) try: int(progress) - except: + except Exception: progress = 0 opt = QStyleOptionProgressBar() opt.rect = option.rect diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Views/PlotDataView.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Views/PlotDataView.py index 4aff584573..d4db9f2428 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Views/PlotDataView.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Views/PlotDataView.py @@ -104,7 +104,7 @@ def on_select_dataset(self, index): for attr in mda_data_structure.attrs: text += f"{attr}: {mda_data_structure.attrs[attr]}\n" self.item_details.emit(text) - except: + except Exception: self.item_details.emit("No additional information included.") @Slot(QModelIndex) @@ -148,6 +148,5 @@ def connect_to_visualiser( self.item_details.connect(visualiser.update_panel) else: raise NotImplementedError( - f"Unable to connect view {type(self)} to visualiser " - f"{type(visualiser)}" + f"Unable to connect view {type(self)} to visualiser {type(visualiser)}" ) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Views/RunTable.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Views/RunTable.py index 592613c16e..e5a4e7b612 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Views/RunTable.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Views/RunTable.py @@ -163,6 +163,5 @@ def connect_to_visualiser(self, visualiser: TextInfo) -> None: self.jobs_logs.connect(visualiser.update_panel) else: raise NotImplementedError( - f"Unable to connect view {type(self)} to visualiser " - f"{type(visualiser)}" + f"Unable to connect view {type(self)} to visualiser {type(visualiser)}" ) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Views/TrajectoryView.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Views/TrajectoryView.py index a97932e770..411c932fb7 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Views/TrajectoryView.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Views/TrajectoryView.py @@ -80,6 +80,5 @@ def connect_to_visualiser(self, visualiser: Union[View3D, TrajectoryInfo]) -> No self.item_details.connect(visualiser.update_panel) else: raise NotImplementedError( - f"Unable to connect view {type(self)} to visualiser " - f"{type(visualiser)}" + f"Unable to connect view {type(self)} to visualiser {type(visualiser)}" ) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/Action.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/Action.py index e70ba43ab9..a71be04475 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/Action.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/Action.py @@ -14,28 +14,64 @@ # along with this program. If not, see . # import os -from pathlib import PurePath import traceback +from pathlib import PurePath import numpy as np +from MDANSE.Framework.Jobs.IJob import IJob +from MDANSE.MLogging import LOG +from MDANSE_GUI.InputWidgets import ( + AseInputFileWidget, + AtomMappingWidget, + AtomSelectionWidget, + AtomTransmutationWidget, + BackupWidget, + BooleanWidget, + ComboWidget, + CorrelationFramesWidget, + DerivativeOrderWidget, + DistHistCutoffWidget, + FloatWidget, + FramesWidget, + HDFTrajectoryWidget, + InputDirectoryWidget, + InputFileWidget, + InstrumentResolutionWidget, + IntegerWidget, + InterpolationOrderWidget, + MDAnalysisCoordinateFileWidget, + MDAnalysisMDTrajTimeStepWidget, + MDAnalysisTopologyFileWidget, + MDTrajTopologyFileWidget, + MoleculeWidget, + MultiInputFileWidget, + MultipleCombosWidget, + OptionalFloatWidget, + OutputDirectoryWidget, + OutputFilesWidget, + OutputStructureWidget, + OutputTrajectoryWidget, + PartialChargeWidget, + ProjectionWidget, + QVectorsWidget, + RangeWidget, + RunningModeWidget, + StringWidget, + UnitCellWidget, + VectorWidget, +) +from MDANSE_GUI.Tabs.Visualisers.InstrumentInfo import SimpleInstrument +from MDANSE_GUI.Widgets.DelayedButton import DelayedButton +from qtpy.QtCore import Signal, Slot from qtpy.QtWidgets import ( - QPushButton, + QCheckBox, QFileDialog, - QVBoxLayout, - QWidget, QHBoxLayout, - QCheckBox, + QPushButton, QTextEdit, + QVBoxLayout, + QWidget, ) -from qtpy.QtCore import Signal, Slot - -from MDANSE.MLogging import LOG -from MDANSE.Framework.Jobs.IJob import IJob - -from MDANSE_GUI.Widgets.DelayedButton import DelayedButton -from MDANSE_GUI.InputWidgets import * -from MDANSE_GUI.Tabs.Visualisers.InstrumentInfo import SimpleInstrument - widget_lookup = { # these all come from MDANSE_GUI.InputWidgets "FloatConfigurator": FloatWidget, @@ -190,8 +226,7 @@ def update_panel(self, job_name: str) -> None: dtype = value[0] ddict = value[1] configurator = job_instance.configuration[key] - if not "label" in ddict.keys(): - ddict["label"] = key + ddict.setdefault("label", key) ddict["configurator"] = configurator ddict["source_object"] = self._input_trajectory widget_class = widget_lookup[dtype] @@ -208,12 +243,11 @@ def update_panel(self, job_name: str) -> None: dtype = value[0] ddict = value[1] configurator = job_instance.configuration[key] - if not "label" in ddict.keys(): - ddict["label"] = key + ddict.setdefault("label", key) ddict["configurator"] = configurator ddict["source_object"] = self._input_trajectory ddict["trajectory_configurator"] = self._trajectory_configurator - if not dtype in widget_lookup.keys(): + if dtype not in widget_lookup: ddict["tooltip"] = ( "This is not implemented in the MDANSE GUI at the moment, and it MUST BE!" ) @@ -258,8 +292,8 @@ def update_panel(self, job_name: str) -> None: default_check_status = ( self._parent_tab._settings.group("Execution").get("auto-load") == "True" ) - except: - LOG.debug(f"Converter tab could not load auto-load settings") + except Exception: + LOG.debug("Converter tab could not load auto-load settings") default_check_status = False if default_check_status: self.post_execute_checkbox.setChecked(True) @@ -373,8 +407,8 @@ def cancel_dialog(self): @Slot() def save_dialog(self): try: - cname = self._job_name - except: + _cname = self._job_name + except Exception: currentpath = PurePath(os.path.abspath(".")) else: currentpath = PurePath( @@ -390,8 +424,8 @@ def save_dialog(self): return None path = PurePath(os.path.split(result)[0]) try: - cname = self._job_name - except: + _cname = self._job_name + except Exception: pass else: self._parent_tab.set_path(self._job_name + "_script", str(path)) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/AnalysisInfo.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/AnalysisInfo.py index b22b663b7e..9113bda710 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/AnalysisInfo.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/AnalysisInfo.py @@ -46,14 +46,14 @@ def filter(self, some_text: str, line_break="
"): def summarise_chemical_system(self, job_name): try: temp_instance = IJob.create(job_name) - except: + except Exception: return "" text = "\n ==== Input Parameter summary ==== \n" params = temp_instance.get_default_parameters() for key, value in params.items(): try: text += f"parameters['{key}'] = {value[0]} # {value[1]} \n" - except: + except Exception: continue text += " ===== \n" return text diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/DataPlotter.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/DataPlotter.py index 62a8514793..327f0cd6b4 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/DataPlotter.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/DataPlotter.py @@ -154,4 +154,4 @@ def clear(self): if self._model is None: return self._model.clear() - LOG.info(f"Cleared the plot") + LOG.info("Cleared the plot") diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/DataWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/DataWidget.py index c618ce68a2..8c5c8c4fbf 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/DataWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/DataWidget.py @@ -46,7 +46,6 @@ class DataWidget(QWidget): - change_slider_labels = Signal(object) change_slider_limits = Signal(object) reset_slider_values = Signal(bool) @@ -159,7 +158,7 @@ def save_to_file(self): nsets = len(self._plotter._pc_backup.datasets()) except AttributeError: return - except: + except Exception: LOG.warning("DataWidget could not determine the number of datasets.") else: if nsets == 0: # do not create a file if there are no data @@ -167,7 +166,7 @@ def save_to_file(self): try: PLATFORM.create_directory(os.path.dirname(self._output_widget.text())) target = open(target_path, "w", newline="") - except: + except Exception: LOG.error(f"Could not open file for writing: {target_path}") else: writer = csv.writer( @@ -181,13 +180,13 @@ def save_to_file(self): writer.writerow(row) target.close() - @Slot(object) - def slider_change(self, new_values: object): - """Not used for text output.""" + # @Slot(object) + # def slider_change(self, new_values: object): + # """Not used for text output.""" - @Slot(bool) - def set_slider_values(self, reset_needed: bool): - """Not used for text output.""" + # @Slot(bool) + # def set_slider_values(self, reset_needed: bool): + # """Not used for text output.""" def set_context(self, new_context: "PlottingContext"): self._plotting_context = new_context @@ -257,7 +256,7 @@ def plot_data(self, update_only=False): self._current_path = PurePath(os.path.split(dataset._filename)[0]) break except Exception as e: - LOG.error(f"DataWidget error: {e}" f"traceback {format_exc()}") + LOG.error(f"DataWidget error: {e}traceback {format_exc()}") def make_canvas(self): """Creates a matplotlib figure for plotting diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/InstrumentDetails.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/InstrumentDetails.py index 2731e227f9..a4be4badcc 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/InstrumentDetails.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/InstrumentDetails.py @@ -32,7 +32,6 @@ class InstrumentDetails(QWidget): - instrument_details_changed = Signal(int) def __init__(self, *args, **kwargs): @@ -149,7 +148,7 @@ def toggle_axis_fields(self): else: widget.setEnabled(True) if "axis_2" in name: - if not "Circular" in self._current_instrument._qvector_type: + if "Circular" not in self._current_instrument._qvector_type: widget.setEnabled(False) else: widget.setEnabled(True) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/InstrumentInfo.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/InstrumentInfo.py index 3f83f68bcd..52738487d5 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/InstrumentInfo.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/InstrumentInfo.py @@ -13,9 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -from qtpy.QtCore import Slot, Signal -from qtpy.QtWidgets import QTextBrowser from qtpy.QtCore import Signal, Slot, Qt +from qtpy.QtWidgets import QTextBrowser from qtpy.QtGui import QStandardItem from MDANSE.MLogging import LOG @@ -25,7 +24,6 @@ class SimpleInstrument: - sample_options = ["isotropic", "crystal"] technique_options = ["QENS", "INS"] resolution_options = [str(x) for x in widget_text_map.keys()] @@ -84,7 +82,7 @@ def update_item(self): def create_resolution_params(self): if not self._configured: return - general_resolution = ("gaussian", {"mu": 0.0, "sigma": 0.2}) + _general_resolution = ("gaussian", {"mu": 0.0, "sigma": 0.2}) calculator = ResolutionCalculator() try: calculator.update_model(self._resolution_type) @@ -131,7 +129,7 @@ def create_q_vector_params(self): _q_step, _q_min, _q_max, _q_width = self.sanitize_numbers() try: conversion_factor = measure(1.0, iunit=self._q_unit).toval("1/nm") - except: + except Exception: raise ValueError(f"Could not convert unit: {self._q_unit}") else: conversion_factor = float(conversion_factor) @@ -164,7 +162,7 @@ def create_q_vector_params(self): def filter_qvector_generator(self): new_list = [str(x) for x in self.qvector_options] if self._sample == "isotropic": - new_list = [str(x) for x in new_list if not "Lattice" in x] + new_list = [str(x) for x in new_list if "Lattice" not in x] if self._technique == "QENS": new_list = [str(x) for x in new_list if "Spherical" in x] return new_list diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/JobLogInfo.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/JobLogInfo.py index a150649dad..c96b9c7f3b 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/JobLogInfo.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/JobLogInfo.py @@ -18,7 +18,6 @@ class JobLogInfo(TextInfo): - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setStyleSheet("font-family: Courier New;") diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/PlotDataInfo.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/PlotDataInfo.py index e8bac120ac..6fea8ce932 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/PlotDataInfo.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/PlotDataInfo.py @@ -37,7 +37,7 @@ def __init__(self, *args, **kwargs): def update_panel(self, input_text): try: text = "\n".join([f"{key}: {item}" for key, item in input_text.items()]) - except: + except Exception: text = str(input_text) filtered = self.filter(text) self.setHtml(filtered) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/PlotSettings.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/PlotSettings.py index c29af48d76..9d61bce750 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/PlotSettings.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/PlotSettings.py @@ -28,7 +28,6 @@ class PlotSettings(QWidget): - plot_settings_changed = Signal() def __init__(self, *args, settings=None, **kwargs) -> None: @@ -52,7 +51,7 @@ def set_style(self, style_name: str): ) try: mpl.style.use(style_name) - except: + except Exception: LOG.error(f"Could not set matplotlib style to {style_name}") backup_style = self._unit_lookup._settings.default_value( "matplotlib", "style" @@ -84,12 +83,12 @@ def update_units(self): unit_group = self._settings.group("units") try: energy = self._unit_fields["energy"].currentText() - except: + except Exception: LOG.warning("Could not get the energy unit from GUI") else: try: measure(1.0, "rad/ps", equivalent=True).toval(energy) - except: + except Exception: energy = self._settings.default_value("units", "energy") else: if not unit_group.set("energy", energy): @@ -100,12 +99,12 @@ def update_units(self): ) try: time = self._unit_fields["time"].currentText() - except: + except Exception: LOG.warning("Could not get the time unit from GUI") else: try: measure(1.0, "ps").toval(time) - except: + except Exception: time = self._settings.default_value("units", "time") else: if not unit_group.set("time", time): @@ -114,12 +113,12 @@ def update_units(self): ) try: distance = self._unit_fields["distance"].currentText() - except: + except Exception: LOG.warning("Could not get the distance unit from GUI") else: try: measure(1.0, "nm").toval(distance) - except: + except Exception: distance = self._settings.default_value("units", "distance") else: if not unit_group.set("distance", distance): @@ -130,12 +129,12 @@ def update_units(self): ) try: reciprocal = self._unit_fields["reciprocal"].currentText() - except: + except Exception: LOG.warning("Could not get the reciprocal space unit from GUI") else: try: measure(1.0, "1/nm").toval(reciprocal) - except: + except Exception: reciprocal = self._settings.default_value("units", "reciprocal") else: if not unit_group.set("reciprocal", reciprocal): @@ -174,7 +173,7 @@ def make_layout(self, width=12.0, height=9.0, dpi=100): style_selector.addItems(style_list_filtered) try: style_string = self._settings.group("matplotlib").get("style") - except: + except Exception: style_string = "default" style_selector.setCurrentText(style_string) style_selector.currentTextChanged.connect(self.set_style) @@ -184,7 +183,7 @@ def make_layout(self, width=12.0, height=9.0, dpi=100): try: current_cmap = colour_group.get("colormap") except KeyError: - LOG.warning(f"Could not get colormap from colours") + LOG.warning("Could not get colormap from colours") colour_group.add( "colormap", "viridis", @@ -194,8 +193,8 @@ def make_layout(self, width=12.0, height=9.0, dpi=100): else: if current_cmap not in mpl.colormaps(): current_cmap = "viridis" - except: - LOG.warning(f"Could not get the colours group") + except Exception: + LOG.warning("Could not get the colours group") current_cmap = "viridis" cmap_selector = QComboBox(self) cmap_selector.addItems(mpl.colormaps()) @@ -229,7 +228,7 @@ def make_layout(self, width=12.0, height=9.0, dpi=100): self._unit_fields["reciprocal"] = reciprocal_combo try: unit_group = self._settings.group("units") - except: + except Exception: pass else: current_energy = unit_group.get("energy") diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/PlotWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/PlotWidget.py index 271b936a88..0405269828 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/PlotWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/PlotWidget.py @@ -41,7 +41,6 @@ class SliderPack(QWidget): - new_values = Signal(object) def __init__(self, *args, n_sliders=2, **kwargs) -> None: @@ -152,7 +151,6 @@ def collect_values(self): class PlotWidget(QWidget): - change_slider_labels = Signal(object) change_slider_limits = Signal(object) reset_slider_values = Signal(bool) @@ -175,7 +173,7 @@ def set_context(self, new_context: "PlottingContext"): def set_plotter(self, plotter_option: str): try: self._plotter = Plotter.create(plotter_option) - except: + except Exception: self._plotter = Plotter() self.change_slider_labels.emit(self._plotter.slider_labels()) self.change_slider_limits.emit(self._plotter.slider_limits()) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/UnitsEditor.py b/MDANSE_GUI/Src/MDANSE_GUI/UnitsEditor.py index 2393f0d7b0..e7c5a0804c 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/UnitsEditor.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/UnitsEditor.py @@ -196,7 +196,7 @@ def newUnitDialog(self): nu_dialog = InputDialog(fields=dialog_variables) nu_dialog.got_values.connect(self.model.addNewUnit) nu_dialog.show() - result = nu_dialog.exec() + _result = nu_dialog.exec() if __name__ == "__main__": diff --git a/MDANSE_GUI/Src/MDANSE_GUI/UserSettingsEditor.py b/MDANSE_GUI/Src/MDANSE_GUI/UserSettingsEditor.py index 8054ab6462..8b9edaccfc 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/UserSettingsEditor.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/UserSettingsEditor.py @@ -30,7 +30,6 @@ class SettingsView(QTreeView): - def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Widgets/DataDialog.py b/MDANSE_GUI/Src/MDANSE_GUI/Widgets/DataDialog.py index aeb594daf1..5cb857433b 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Widgets/DataDialog.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Widgets/DataDialog.py @@ -39,7 +39,7 @@ def __init__( input_data: List[np.ndarray], input_units: List[str], is_input=False, - **kwargs + **kwargs, ): super().__init__(*args, **kwargs) diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Widgets/DelayedButton.py b/MDANSE_GUI/Src/MDANSE_GUI/Widgets/DelayedButton.py index aaceda17e6..e3228cda7d 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Widgets/DelayedButton.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Widgets/DelayedButton.py @@ -19,7 +19,6 @@ class DelayedButton(QPushButton): - needs_updating = Signal() def __init__(self, *args, **kwargs): diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Widgets/GeneralWidgets.py b/MDANSE_GUI/Src/MDANSE_GUI/Widgets/GeneralWidgets.py index 7dfc028e33..49d2331259 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Widgets/GeneralWidgets.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Widgets/GeneralWidgets.py @@ -350,7 +350,7 @@ def createTrajectory(*args, direction="out", **kwargs): direction -- if 'in', create a FileDialog for an exisitng file, if 'out', a FileDialog for creating a new file. """ - kind = kwargs.get("kind", "String") + _kind = kwargs.get("kind", "String") default_value = kwargs.get("default", "") tooltip_text = kwargs.get( "tooltip", "Specify the name of the output trajectory." @@ -580,7 +580,7 @@ def __init__(self, *args, fields: Iterable["InputVariable"] = None, **kwargs): format = var.format values = var.values widget = var.widget - helper_dialog = var.helper_dialog + _helper_dialog = var.helper_dialog tooltip = var.tooltip placeholder = var.placeholder number_of_inputs = var.number_of_inputs diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Widgets/NotificationTabWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/Widgets/NotificationTabWidget.py index fa8e386c61..3a13453e35 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Widgets/NotificationTabWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Widgets/NotificationTabWidget.py @@ -20,7 +20,6 @@ class NotificationTabWidget(QTabWidget): - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._normal_colours = {} diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Widgets/ResolutionDialog.py b/MDANSE_GUI/Src/MDANSE_GUI/Widgets/ResolutionDialog.py index db6c67ea52..680b3fed11 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Widgets/ResolutionDialog.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Widgets/ResolutionDialog.py @@ -25,7 +25,6 @@ class ResolutionDialog(QDialog): - parameters_changed = Signal(dict) def __init__(self, *args, **kwargs): diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Widgets/ResolutionWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/Widgets/ResolutionWidget.py index b0c39e7621..c019a441e6 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Widgets/ResolutionWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Widgets/ResolutionWidget.py @@ -139,7 +139,6 @@ def revert_parameters(values: dict, peak_type: str) -> List[float]: class ResolutionCalculator: - def __init__(self) -> None: self._valid = False self._fwhm_value = 1.0 @@ -211,7 +210,7 @@ def recalculate_peak(self, fwhm, centre, eta, unit): ) try: self._resolution.set_kernel(self._omega_axis, 1.0) - except: + except Exception: self._valid = False else: self._valid = True @@ -251,7 +250,6 @@ def summarise_results(self, rounding_precision=3): class ResolutionWidget(QWidget): - parameters_changed = Signal(dict) def __init__(self, *args, **kwargs): @@ -363,16 +361,16 @@ def recalculate_peak(self): """ try: fwhm = abs(float(self._fwhm.text())) - except: + except Exception: return try: centre = float(self._centre.text()) - except: + except Exception: return if "oigt" in self._resolution_name: try: eta = float(self._eta.text()) - except: + except Exception: return else: eta = None @@ -411,7 +409,7 @@ def update_fields(self, widget_values): new_eta = new_params.get("eta", "0.0") try: fwhm, centre = revert_parameters(new_params, new_function_name) - except: + except Exception: self.blockSignals(False) return self._peak_selector.setCurrentText(offical_name) @@ -490,7 +488,7 @@ def update_plot(self): + self._calculator._centre_value ) ys = np.array([0.0, hh, hh, 0.0]) - if not "deal" in self._resolution_name: + if "deal" not in self._resolution_name: axes.plot(xs * self._calculator._factor_value, ys, "r:") axes.grid(True) scale = self._calculator._factor_value diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Widgets/RestrictedSlider.py b/MDANSE_GUI/Src/MDANSE_GUI/Widgets/RestrictedSlider.py index ed9ddef3f8..587fdd6c41 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Widgets/RestrictedSlider.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Widgets/RestrictedSlider.py @@ -19,7 +19,6 @@ class RestrictedSlider(QSlider): - new_limit = Signal(object) def __init__(self, *args, **kwargs): diff --git a/MDANSE_GUI/Src/MDANSE_GUI/Widgets/VectorWidget.py b/MDANSE_GUI/Src/MDANSE_GUI/Widgets/VectorWidget.py index b9153c4523..a822822915 100644 --- a/MDANSE_GUI/Src/MDANSE_GUI/Widgets/VectorWidget.py +++ b/MDANSE_GUI/Src/MDANSE_GUI/Widgets/VectorWidget.py @@ -26,13 +26,12 @@ class VectorWidget(QWidget): - value_changed = Signal(list) def __init__(self, *args, dtype=None, **kwargs) -> None: label_text = kwargs.pop("label", "Vector input") super().__init__(*args, **kwargs) - if dtype is "int": + if dtype == "int": self._dtype = "int" else: self._dtype = "float" @@ -76,7 +75,7 @@ def setText(self, input_string: str): self.set_value( [converter(x) for x in input_string.strip("[]()").split(",")] ) - except: + except Exception: self.set_value([0, 0, 0]) def text(self): diff --git a/MDANSE_GUI/pyproject.toml b/MDANSE_GUI/pyproject.toml index 72c184f873..c4bf93ed78 100644 --- a/MDANSE_GUI/pyproject.toml +++ b/MDANSE_GUI/pyproject.toml @@ -61,3 +61,46 @@ mdanse_elements_database = "MDANSE_GUI.Scripts.mdanse_elements_database:main" mdanse_gui = "MDANSE_GUI.Scripts.mdanse_gui:main" mdanse_periodic_table = "MDANSE_GUI.Scripts.mdanse_periodic_table:main" mdanse_units_editor = "MDANSE_GUI.Scripts.mdanse_units_editor:main" + +[tool.ruff] +line-length = 88 +indent-width = 4 +target-version = "py39" + +[tool.ruff.lint] +select = [ + "E4", "E7", "E9", "F", # Defaults + # "PL", # Pylint errors + # "E", # Pycodestyle + # "W", # Pycodestyle warnings + # "F", # Pyflakes + # "B", # Flake8 bugbear + # "SIM", # Flake8 Simplify + # "A", # Flake8 builtins + # "COM", # Flake8 commas + # "ISC", # Flake8 implicit string concat + # "RSE", # Flake8 raise + # "FA", # Flake8 future + # "FBT", # Flake8 boolean trap + # "C4", # Flake8 comprehensions + # "Q", # Flake8 Quotes + # "RET", # Flake8 return + # "ARG", # Flake8 unused args + # "PTH", # Flake8 use pathlib + # "I", # Isort + # "RUF", # Ruff specific + # "FURB",# Refurb + # "PERF",# Perflint + # "D", # Pydocstyle + # "UP", # Pyupgrade +] +ignore = [ + "F401", # Unused import in init + "E402", # Import not at top + "PLR0913", # Too many arguments + "PLR0912", # Too many branches + "PLR0915", # Too many statements +] + +# [tool.setuptools.packages.find] +# where = ["src"]