Skip to content

Commit 7d99ffb

Browse files
Ruff Format (#90)
* First ruff checks * Second ruff checks * ruff format * ruff format Error F * ruff format Error D (some) * ruff format Error D (some more) * intermediate ruff * intermediate ruff by julie * intermediate stuff by julie * Docstring by julie * Final things with julie * Update src/petab_gui/views/find_replace_bar.py Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 206e930 commit 7d99ffb

29 files changed

+2207
-1625
lines changed

pyproject.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,21 @@ include-package-data = true
5656

5757
[tool.setuptools.package-data]
5858
"petab_gui.assets" = ["PEtab.png"]
59+
60+
[tool.ruff]
61+
line-length = 79
62+
lint.select = [
63+
"F", # Pyflakes
64+
"I", # isort
65+
"D", # pydocstyle (PEP 257)
66+
"S", # flake8-bandit
67+
"B", # flake8-bugbear
68+
"C4", # flake8-comprehensions
69+
"T20", # flake8-print
70+
"W", # pycodestyle Warnings
71+
"E", # pycodestyle Errors
72+
"UP", # pyupgrade
73+
# "ANN", # flakes-annotations TODO: currently produces ~1500 errors to manual fix
74+
]
75+
[tool.ruff.lint.pydocstyle]
76+
convention = "pep257"

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
"""Setup script for petab-gui."""
33
from setuptools import setup # type: ignore
44

5-
65
if __name__ == "__main__":
7-
setup(version="0.0.1")
6+
setup(version="0.0.1")

src/petab_gui/C.py

Lines changed: 41 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Constants for the PEtab edit GUI."""
2+
23
import numpy as np
34

45
COLUMNS = {
@@ -30,36 +31,39 @@
3031
"nominalValue": {"type": np.float64, "optional": False},
3132
"estimate": {"type": np.object_, "optional": False},
3233
"initializationPriorType": {"type": np.object_, "optional": True},
33-
"initializationPriorParameters": {"type": np.object_, "optional": True},
34+
"initializationPriorParameters": {
35+
"type": np.object_,
36+
"optional": True,
37+
},
3438
"objectivePriorType": {"type": np.object_, "optional": True},
3539
"objectivePriorParameters": {"type": np.object_, "optional": True},
3640
},
3741
"condition": {
3842
"conditionId": {"type": np.object_, "optional": False},
3943
"conditionName": {"type": np.object_, "optional": False},
40-
}
44+
},
4145
}
4246

4347
CONFIG = {
44-
'window_title': 'My Application',
45-
'window_size': (800, 600),
46-
'table_titles': {
47-
'data': 'Data',
48-
'parameters': 'Parameters',
49-
'observables': 'Observables',
50-
'conditions': 'Conditions'
48+
"window_title": "My Application",
49+
"window_size": (800, 600),
50+
"table_titles": {
51+
"data": "Data",
52+
"parameters": "Parameters",
53+
"observables": "Observables",
54+
"conditions": "Conditions",
55+
},
56+
"summary_title": "Summary",
57+
"buttons": {
58+
"test_consistency": "Test Consistency",
59+
"proceed_optimization": "Proceed to Optimization",
5160
},
52-
'summary_title': 'Summary',
53-
'buttons': {
54-
'test_consistency': 'Test Consistency',
55-
'proceed_optimization': 'Proceed to Optimization'
56-
}
5761
}
5862

5963
# String constants
60-
ROW = 'row'
61-
COLUMN = 'column'
62-
INDEX = 'index'
64+
ROW = "row"
65+
COLUMN = "column"
66+
INDEX = "index"
6367

6468
COPY_FROM = "copy from"
6569
USE_DEFAULT = "use default"
@@ -120,66 +124,47 @@
120124
"observable": ALLOWED_STRATEGIES_OBS,
121125
"parameter": ALLOWED_STRATEGIES_PAR,
122126
"condition": ALLOWED_STRATEGIES_COND,
123-
"measurement": ALLOWED_STRATEGIES_MEAS
127+
"measurement": ALLOWED_STRATEGIES_MEAS,
124128
}
125129
DEFAULT_OBS_CONFIG = {
126130
"observableId": {
127-
"strategy": COPY_FROM, SOURCE_COLUMN: "observableFormula",
128-
DEFAULT_VALUE: "new_observable"
129-
},
130-
"observableName": {
131-
"strategy": COPY_FROM, SOURCE_COLUMN: "observableId"
132-
},
133-
"noiseFormula": {
134-
"strategy": USE_DEFAULT, DEFAULT_VALUE: 1
131+
"strategy": COPY_FROM,
132+
SOURCE_COLUMN: "observableFormula",
133+
DEFAULT_VALUE: "new_observable",
135134
},
135+
"observableName": {"strategy": COPY_FROM, SOURCE_COLUMN: "observableId"},
136+
"noiseFormula": {"strategy": USE_DEFAULT, DEFAULT_VALUE: 1},
136137
"observableTransformation": {
137138
"strategy": USE_DEFAULT,
138-
DEFAULT_VALUE: "lin"
139+
DEFAULT_VALUE: "lin",
139140
},
140-
"noiseDistribution": {
141-
"strategy": USE_DEFAULT,
142-
DEFAULT_VALUE: "normal"
143-
}
141+
"noiseDistribution": {"strategy": USE_DEFAULT, DEFAULT_VALUE: "normal"},
144142
}
145143
DEFAULT_PAR_CONFIG = {
146144
"parameterName": {
147-
"strategy": COPY_FROM, SOURCE_COLUMN: "parameterId",
148-
DEFAULT_VALUE: "new_parameter"
149-
},
150-
"parameterScale": {
151-
"strategy": USE_DEFAULT, DEFAULT_VALUE: "log10"
152-
},
153-
"lowerBound": {
154-
"strategy": MIN_COLUMN
155-
},
156-
"upperBound": {
157-
"strategy": MAX_COLUMN
158-
},
159-
"estimate": {
160-
"strategy": USE_DEFAULT, DEFAULT_VALUE: 1
161-
},
162-
"nominalValue": {
163-
"strategy": SBML_LOOK
145+
"strategy": COPY_FROM,
146+
SOURCE_COLUMN: "parameterId",
147+
DEFAULT_VALUE: "new_parameter",
164148
},
149+
"parameterScale": {"strategy": USE_DEFAULT, DEFAULT_VALUE: "log10"},
150+
"lowerBound": {"strategy": MIN_COLUMN},
151+
"upperBound": {"strategy": MAX_COLUMN},
152+
"estimate": {"strategy": USE_DEFAULT, DEFAULT_VALUE: 1},
153+
"nominalValue": {"strategy": SBML_LOOK},
165154
}
166155
DEFAULT_COND_CONFIG = {
167-
"conditionId": {
168-
"strategy": USE_DEFAULT, DEFAULT_VALUE: "new_condition"
169-
},
170-
"conditionName": {
171-
"strategy": COPY_FROM, SOURCE_COLUMN: "conditionId"
172-
}
156+
"conditionId": {"strategy": USE_DEFAULT, DEFAULT_VALUE: "new_condition"},
157+
"conditionName": {"strategy": COPY_FROM, SOURCE_COLUMN: "conditionId"},
173158
}
174159
DEFAULT_MEAS_CONFIG = {}
175160
DEFAULT_CONFIGS = {
176161
"observable": DEFAULT_OBS_CONFIG,
177162
"parameter": DEFAULT_PAR_CONFIG,
178163
"condition": DEFAULT_COND_CONFIG,
179-
"measurement": DEFAULT_MEAS_CONFIG
164+
"measurement": DEFAULT_MEAS_CONFIG,
180165
}
181166

182167
COMMON_ERRORS = {
183168
r"Error parsing '': Syntax error at \d+:\d+: mismatched input '<EOF>' "
184-
r"expecting \{[^}]+\}" : "Invalid empty cell!"
169+
r"expecting \{[^}]+\}": "Invalid empty cell!"
185170
}

src/petab_gui/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
from .app import main
1+
"""Package for the PETAB GUI."""
2+
3+
from .app import main

src/petab_gui/__main__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import sys
21
from petab_gui import app
32

3+
44
def main():
55
app.main()
66

7+
78
if __name__ == "__main__":
8-
main()
9+
main()

src/petab_gui/app.py

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,66 @@
1-
from PySide6.QtWidgets import QApplication
2-
from PySide6.QtGui import QFileOpenEvent, QIcon
3-
from PySide6.QtCore import QEvent
4-
from importlib.resources import files
5-
import sys
61
import os
7-
import petab.v1 as petab
2+
import sys
3+
from importlib.resources import files
4+
from pathlib import Path
5+
6+
from PySide6.QtCore import QEvent
7+
from PySide6.QtGui import QFileOpenEvent, QIcon
8+
from PySide6.QtWidgets import QApplication
89

9-
from .views import MainWindow
1010
from .controllers import MainController
1111
from .models import PEtabModel
12-
13-
from pathlib import Path
12+
from .views import MainWindow
1413

1514

1615
def find_example(path: Path) -> Path:
16+
"""Find the example directory by traversing up from the given path.
17+
18+
Args:
19+
path: The starting path to search from
20+
21+
Returns:
22+
Path: The path to the example directory
23+
24+
Raises:
25+
FileNotFoundError: If the example directory cannot be found
26+
"""
1727
while path.parent != path:
1828
if (path / "example").is_dir():
1929
return path / "example"
2030
path = path.parent
21-
31+
2232
raise FileNotFoundError("Could not find examples directory")
2333

2434

2535
def get_icon() -> QIcon:
26-
"""Get the Icon for the Window"""
36+
"""Get the Icon for the Window."""
2737
icon_path = files("petab_gui.assets").joinpath("PEtab.png")
2838
if not icon_path.is_file():
2939
raise FileNotFoundError(f"Icon file not found: {icon_path}")
30-
icon = QIcon(str(icon_path))
31-
return icon
40+
return QIcon(str(icon_path))
3241

3342

3443
class PEtabGuiApp(QApplication):
44+
"""Main application class for PEtab GUI.
45+
46+
Inherits from QApplication and sets up the MVC components.
47+
"""
48+
3549
def __init__(self):
50+
"""Initialize the PEtab GUI application.
51+
52+
Sets up the model, view, and controller components.
53+
Handles command line arguments for opening files.
54+
"""
3655
super().__init__(sys.argv)
3756

38-
# Load the stylesheet
39-
# self.apply_stylesheet()
4057
self.setWindowIcon(get_icon())
4158
self.model = PEtabModel()
4259
self.view = MainWindow()
4360
self.view.setWindowIcon(get_icon())
4461
self.controller = MainController(self.view, self.model)
4562

46-
# hack to be discussed
63+
# Connect the view to the controller
4764
self.view.controller = self.controller
4865

4966
if len(sys.argv) > 1 and os.path.isfile(sys.argv[1]):
@@ -52,27 +69,50 @@ def __init__(self):
5269
self.view.show()
5370

5471
def event(self, event):
72+
"""Handle application events.
73+
74+
Args:
75+
event: The Qt event to handle
76+
77+
Returns:
78+
bool: Result of the event handling from the parent class
79+
80+
Notes:
81+
Currently handles FileOpen events to open files dropped on
82+
the application.
83+
"""
5584
if event.type() == QEvent.FileOpen:
56-
openEvent = QFileOpenEvent(event)
85+
openEvent = QFileOpenEvent(event)
5786
self.controller.open_file(openEvent.file(), mode="overwrite")
5887

5988
return super().event(event)
6089

6190
def apply_stylesheet(self):
62-
"""Load and apply the QSS stylesheet."""
91+
"""Load and apply the QSS stylesheet to the application.
92+
93+
Reads the stylesheet.css file from the same directory as this module
94+
and applies it to the application. If the file doesn't exist,
95+
no stylesheet is applied.
96+
"""
6397
stylesheet_path = os.path.join(
6498
os.path.dirname(__file__), "stylesheet.css"
6599
)
66100
if os.path.exists(stylesheet_path):
67-
with open(stylesheet_path, "r") as f:
101+
with open(stylesheet_path) as f:
68102
self.setStyleSheet(f.read())
69103
else:
70-
print(f"Warning: Stylesheet '{stylesheet_path}' not found!")
104+
pass
71105

72106

73107
def main():
108+
"""Entry point for the PEtab GUI application.
109+
110+
Creates the application instance and starts the event loop.
111+
The function exits with the return code from the application.
112+
"""
74113
app = PEtabGuiApp()
75114
sys.exit(app.exec())
76115

116+
77117
if __name__ == "__main__":
78118
main()

0 commit comments

Comments
 (0)