Skip to content

Commit 61b3869

Browse files
committed
Enable docsting linting in ruff and cleans up some docstrings
1 parent 7e76b2a commit 61b3869

34 files changed

+163
-219
lines changed

packaging/build_exe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858

5959
def build_exe():
60-
"""Builds the executable for the rascal-2 application"""
60+
"""Builds the executable for the rascal-2 application."""
6161
os.environ["DELAY_MATLAB_START"] = "1"
6262
work_path = PACKAGING_PATH / "temp"
6363
dist_path = PACKAGING_PATH / "bundle"

pyproject.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,15 @@ line-length = 120
2828
extend-exclude = ["examples/*", "doc/*"]
2929

3030
[tool.ruff.lint]
31-
select = ["E", "F", "UP", "B", "SIM", "I", "N", "TD003", "A"]
32-
ignore = ["SIM108", "N817"]
31+
select = ["E", "F", "UP", "B", "SIM", "I", "N", "TD003", "A", "D"]
32+
ignore = ["SIM108", "N817", "D100", "D102", "D104", "D105", "D107", "D203", "D401"]
33+
34+
[tool.ruff.lint.pydocstyle]
35+
convention = "numpy"
36+
37+
# ignore docstring lints in the tests and install script
38+
[tool.ruff.lint.per-file-ignores]
39+
"tests/*" = ["D101", "D103"]
3340

3441
[tool.ruff.lint.flake8-pytest-style]
3542
fixture-parentheses = false

rascal2/config.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
def handle_scaling():
29-
"""Changes settings to handle UI scaling"""
29+
"""Changes settings to handle UI scaling."""
3030
if platform.system() == "Windows":
3131
from ctypes import windll
3232

@@ -121,7 +121,7 @@ def get_logger():
121121

122122

123123
def log_uncaught_exceptions(exc_type, exc_value, exc_traceback):
124-
"""Qt slots swallows exceptions but this ensures exceptions are logged"""
124+
"""Qt slots swallows exceptions but this ensures exceptions are logged."""
125125
logger = get_logger()
126126
logger.addHandler(logging.StreamHandler(stream=sys.stderr)) # print emergency crashes to terminal
127127
logger.critical("An unhandled exception occurred!", exc_info=(exc_type, exc_value, exc_traceback))
@@ -130,7 +130,7 @@ def log_uncaught_exceptions(exc_type, exc_value, exc_traceback):
130130

131131

132132
def run_matlab(ready_event, close_event, engine_output):
133-
"""Start a new matlab engine instance and waits until closed
133+
"""Start a new matlab engine instance and waits until closed.
134134
135135
Parameters
136136
----------
@@ -162,7 +162,7 @@ def run_matlab(ready_event, close_event, engine_output):
162162

163163

164164
def get_matlab_engine(engine_ready, engine_output, is_local=False):
165-
"""Get a MATLAB engine from the MatlabHelper or exception if no engine is available
165+
"""Get a MATLAB engine from the MatlabHelper or exception if no engine is available.
166166
167167
Parameters
168168
----------
@@ -204,7 +204,7 @@ def get_matlab_engine(engine_ready, engine_output, is_local=False):
204204

205205

206206
class MatlabHelper:
207-
"""Helper to start MATLAB on another process"""
207+
"""Helper to start MATLAB on another process."""
208208

209209
_instance = None
210210

@@ -220,7 +220,7 @@ def __new__(cls):
220220
return cls._instance
221221

222222
def async_start(self):
223-
"""Start MATLAB on a new process"""
223+
"""Start MATLAB on a new process."""
224224
self.manager = mp.Manager()
225225
self.engine_output = self.manager.list()
226226

@@ -257,7 +257,7 @@ def get_local_engine(self):
257257
return self.__engine
258258

259259
def get_matlab_path(self):
260-
"""Get MATLAB install directory
260+
"""Get MATLAB install directory.
261261
262262
Returns
263263
-------

rascal2/core/commands.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
@unique
1414
class CommandID(IntEnum):
15-
"""Unique ID for undoable commands"""
15+
"""Unique ID for undoable commands."""
1616

1717
EditControls = 1000
1818
EditProject = 2000
@@ -76,8 +76,7 @@ def redo(self):
7676
self.new_result = self.old_result
7777

7878
def mergeWith(self, command):
79-
"""Merges consecutive Edit controls commands if the attributes are the
80-
same."""
79+
"""Merges consecutive Edit controls commands if the attributes are the same."""
8180
# We should think about if merging all Edit controls irrespective of
8281
# attribute is the way to go for UX
8382
if list(self.new_values.keys()) != list(command.new_values.keys()):
@@ -93,11 +92,13 @@ def mergeWith(self, command):
9392
return True
9493

9594
def id(self):
96-
"""Returns ID used for merging commands"""
95+
"""Returns ID used for merging commands."""
9796
raise NotImplementedError
9897

9998

10099
class EditControls(AbstractModelEdit):
100+
"""Command for editing an attribute of the controls model."""
101+
101102
attribute = "controls"
102103

103104
@property
@@ -109,6 +110,8 @@ def id(self):
109110

110111

111112
class EditProject(AbstractModelEdit):
113+
"""Command for editing an attribute of the project model."""
114+
112115
attribute = "project"
113116

114117
@property
@@ -204,7 +207,7 @@ def update_calculation_outputs(
204207
results: ratapi.outputs.Results | ratapi.outputs.BayesResults,
205208
log: str,
206209
):
207-
"""Updates the project, results and log in the main window model
210+
"""Updates the project, results and log in the main window model.
208211
209212
Parameters
210213
----------

rascal2/core/worker.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ def __init__(self, func, args):
2222
self.stopped = False
2323

2424
def run(self):
25-
"""This function is executed on worker thread when the ``QThread.start``
26-
method is called."""
25+
"""Execute function on worker thread when the start method is called."""
2726
if self.stopped:
2827
return
2928

rascal2/dialogs/about_dialog.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@
1010

1111

1212
class AboutDialog(QtWidgets.QDialog):
13+
"""Dialog to display RasCAL about information.
14+
15+
Parameters
16+
----------
17+
parent : MainWindowView
18+
An instance of MainWindowView
19+
"""
20+
1321
def __init__(self, parent=None):
1422
super().__init__(parent)
15-
# Define internal variables
1623

1724
# Define main window
1825
self.setWindowTitle("About RasCAL 2")
@@ -62,10 +69,8 @@ def __init__(self, parent=None):
6269
main_layout.addStretch(1)
6370
self.setLayout(main_layout)
6471

65-
def update_rascal_info(self, parent):
66-
"""Obtain info about RASCAL (version, main settings etc.)
67-
retrieved from general class information
68-
"""
72+
def update_rascal_info(self):
73+
"""Obtain info about RASCAL (version, main settings etc.)."""
6974
matlab_path = MatlabHelper().get_matlab_path()
7075
if not matlab_path:
7176
matlab_path = "None"

rascal2/dialogs/settings_dialog.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111

1212

1313
class SettingsDialog(QtWidgets.QDialog):
14-
def __init__(self, parent):
15-
"""
16-
Dialog to adjust RasCAL-2 settings.
14+
"""Dialog to adjust RasCAL-2 settings.
1715
18-
Parameters
19-
----------
20-
parent : MainWindowView
21-
The view of the RasCAL-2 GUI
22-
"""
16+
Parameters
17+
----------
18+
parent : MainWindowView
19+
The view of the RasCAL-2 GUI
20+
"""
21+
22+
def __init__(self, parent):
2323
super().__init__(parent)
2424

2525
self.setModal(True)
@@ -59,32 +59,33 @@ def __init__(self, parent):
5959
self.setWindowTitle("Settings")
6060

6161
def update_settings(self) -> None:
62-
"""Accept the changed settings"""
62+
"""Accept the changed settings."""
6363
self.parent().settings = self.settings
6464
if self.parent().presenter.model.save_path:
6565
self.parent().settings.save(self.parent().presenter.model.save_path)
6666
self.matlab_tab.set_matlab_paths()
6767
self.accept()
6868

6969
def reset_default_settings(self) -> None:
70-
"""Reset the settings to the global defaults"""
70+
"""Reset the settings to the global defaults."""
7171
delete_local_settings(self.parent().presenter.model.save_path)
7272
self.parent().settings = Settings()
7373
self.accept()
7474

7575

7676
class SettingsTab(QtWidgets.QWidget):
77-
def __init__(self, parent: SettingsDialog, group: SettingsGroups):
78-
"""A tab in the Settings Dialog tab layout.
77+
"""A tab in the Settings Dialog tab layout.
7978
80-
Parameters
81-
----------
82-
parent : SettingsDialog
83-
The dialog in which this tab lies
84-
group : SettingsGroups
85-
The set of settings with this value in "title" field of the
86-
Settings object's "field_info" will be included in this tab.
87-
"""
79+
Parameters
80+
----------
81+
parent : SettingsDialog
82+
The dialog in which this tab lies
83+
group : SettingsGroups
84+
The set of settings with this value in "title" field of the
85+
Settings object's "field_info" will be included in this tab.
86+
"""
87+
88+
def __init__(self, parent: SettingsDialog, group: SettingsGroups):
8889
super().__init__(parent)
8990

9091
self.settings = parent.settings
@@ -124,8 +125,9 @@ def modify_setting(self, setting: str):
124125

125126

126127
class MatlabSetupTab(QtWidgets.QWidget):
128+
"""Dialog to adjust Matlab location settings."""
129+
127130
def __init__(self):
128-
"""Dialog to adjust Matlab location settings."""
129131
super().__init__()
130132

131133
form_layout = QtWidgets.QGridLayout()
@@ -171,7 +173,7 @@ def open_folder_selector(self) -> None:
171173
self.changed = True
172174

173175
def set_matlab_paths(self):
174-
"""Update MATLAB paths in arch file"""
176+
"""Update MATLAB paths in arch file."""
175177
if not self.changed:
176178
return
177179

rascal2/dialogs/startup_dialog.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ class StartupDialog(QtWidgets.QDialog):
2727
folder_selector = QtWidgets.QFileDialog.getExistingDirectory
2828

2929
def __init__(self, parent):
30-
"""
31-
Initialize dialog.
30+
"""Initialize dialog.
3231
3332
Parameters
3433
----------
3534
parent: MainWindowView
36-
An instance of the MainWindowView
35+
An instance of the MainWindowView
3736
"""
3837
super().__init__(parent)
3938

@@ -67,7 +66,7 @@ def compose_layout(self):
6766
self.setLayout(main_layout)
6867

6968
def create_loading_bar(self):
70-
"""Creates non-deterministic progress bar"""
69+
"""Creates non-deterministic progress bar."""
7170
self.loading_bar = QtWidgets.QProgressBar()
7271
self.loading_bar.setMinimum(0)
7372
self.loading_bar.setMaximum(0)
@@ -245,7 +244,7 @@ def create_project(self) -> None:
245244

246245

247246
class DisplayWidget(QtWidgets.QWidget):
248-
"""Fancy display widget for title and description items in a list"""
247+
"""Fancy display widget for title and description items in a list."""
249248

250249
def __init__(self, title, desc):
251250
super().__init__()
@@ -280,7 +279,7 @@ def compose_layout(self):
280279
self.setLayout(main_layout)
281280

282281
def create_load_tab(self):
283-
"""Creates the load project widget"""
282+
"""Creates the load project widget."""
284283
layout = QtWidgets.QVBoxLayout()
285284
layout.setSpacing(20)
286285

@@ -304,7 +303,7 @@ def create_load_tab(self):
304303
self.tabs.addTab(load_tab, "Load Project")
305304

306305
def create_list_widget_tab(self, tab_name: str):
307-
"""Create the list widget and add it to tab with given name
306+
"""Create the list widget and add it to tab with given name.
308307
309308
Parameters
310309
----------
@@ -328,7 +327,7 @@ def create_list_widget_tab(self, tab_name: str):
328327
return list_widget
329328

330329
def create_example_tab(self):
331-
"""Creates the example widget"""
330+
"""Creates the example widget."""
332331
self.example_list_widget = self.create_list_widget_tab("Examples")
333332

334333
for name, desc in EXAMPLES.items():
@@ -341,7 +340,7 @@ def create_example_tab(self):
341340
item.setSizeHint(item_widget.sizeHint())
342341

343342
def create_recent_tab(self):
344-
"""Creates the recent project widget"""
343+
"""Creates the recent project widget."""
345344
recent_projects = update_recent_projects()
346345
recent_projects = recent_projects[:6]
347346
self.recent_list_widget = self.create_list_widget_tab("Recent Projects")
@@ -396,7 +395,7 @@ def load_project(self, item=None):
396395
self.block_for_worker(True)
397396

398397
def block_for_worker(self, disabled: bool):
399-
"""Disable UI while worker is completing
398+
"""Disable UI while worker is completing.
400399
401400
Parameters
402401
----------

rascal2/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
def ui_execute():
13-
"""Creates main window and executes GUI event loop
13+
"""Creates main window and executes GUI event loop.
1414
1515
Returns
1616
-------
@@ -39,6 +39,7 @@ def ui_execute():
3939

4040

4141
def main():
42+
"""Entry point function for starting RasCAL."""
4243
multiprocessing.freeze_support()
4344
multiprocessing.set_start_method("spawn", force=True)
4445
sys.excepthook = log_uncaught_exceptions

rascal2/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def delete_local_settings(path: str | PathLike) -> None:
4141

4242

4343
class SettingsGroups(StrEnum):
44-
"""The groups of the RasCAL-2 settings, used to set tabs in the dialog"""
44+
"""The groups of the RasCAL-2 settings, used to set tabs in the dialog."""
4545

4646
General = "General"
4747
Logging = "Logging"

0 commit comments

Comments
 (0)