Skip to content

Commit 5a386c8

Browse files
authored
Allow importing local file in custom file (#201)
1 parent d938dff commit 5a386c8

6 files changed

Lines changed: 44 additions & 28 deletions

File tree

packaging/build_exe.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
"PyQt6.QtXml",
5050
"PyQt6.QtXmlPatterns",
5151
"sphinx",
52-
"numpy.array_api",
5352
"pkg_resources",
5453
]
5554
IS_WINDOWS = sys.platform.startswith("win")
@@ -80,6 +79,12 @@ def build_exe():
8079
str(PACKAGING_PATH / "hooks"),
8180
"--log-level",
8281
"ERROR",
82+
"--collect-submodules",
83+
"numpy",
84+
"--collect-submodules",
85+
"scipy",
86+
"--collect-all",
87+
"matlab",
8388
str(main_path),
8489
]
8590

packaging/hooks/hook-matlab.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

rascal2/dialogs/startup_dialog.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
# global variable for required project files
1111
PROJECT_FILES = ["controls.json", "project.json"]
1212
EXAMPLES = {
13-
"absorption": "Shows absorption (imaginary SLD) effect usually seen below the critical edge",
14-
"domains_custom_layers": "Incoherent summing ('domains') from custom layer model",
15-
"domains_custom_XY": "Incoherent summing ('domains') from custom XY model",
16-
"domains_standard_layers": "Incoherent summing ('domains') from standard layer model",
13+
"DSPC_standard_layers": "Reflectivity analysis of a floating bilayer of DSPC using standard layer model",
1714
"DSPC_custom_layers": "Reflectivity analysis of a floating bilayer of DSPC using custom layer model",
1815
"DSPC_custom_XY": "Reflectivity analysis of a floating bilayer of DSPC using custom XY model",
19-
"DSPC_standard_layers": "Reflectivity analysis of a floating bilayer of DSPC using standard layer model",
16+
"domains_standard_layers": "Incoherent summing ('domains') from standard layer model",
17+
"domains_custom_layers": "Incoherent summing ('domains') from custom layer model",
18+
"domains_custom_XY": "Incoherent summing ('domains') from custom XY model",
19+
"absorption": "Shows absorption (imaginary SLD) effect usually seen below the critical edge",
2020
}
2121

2222

rascal2/ui/model.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import os
12
import shutil
3+
import sys
24
from json import JSONDecodeError
35
from pathlib import Path
46

@@ -63,7 +65,19 @@ def __init__(self):
6365
self.result_log = ""
6466
self.controls = None
6567

66-
self.save_path = ""
68+
self.__save_path = ""
69+
70+
@property
71+
def save_path(self):
72+
return self.__save_path
73+
74+
@save_path.setter
75+
def save_path(self, value):
76+
if self.__save_path in sys.path:
77+
sys.path.remove(self.__save_path)
78+
self.__save_path = value
79+
os.chdir(value)
80+
sys.path.append(value)
6781

6882
def create_project(self, name: str, save_path: str):
6983
"""Create a new RAT project and controls object.
@@ -125,6 +139,7 @@ def save_project(self, save_path):
125139
if self.results:
126140
self.results.save(Path(save_path, "results.json"))
127141
self.save_path = save_path
142+
os.chdir(save_path)
128143

129144
def is_project_example(self):
130145
return Path(self.save_path).is_relative_to(EXAMPLES_TEMP_PATH)

tests/ui/test_model.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,14 @@ def empty_results():
3838
return empty_results
3939

4040

41-
def test_create_project():
41+
@pytest.fixture
42+
def model():
43+
with patch("rascal2.ui.model.os.chdir", autospec=True):
44+
yield MainWindowModel()
45+
46+
47+
def test_create_project(model):
4248
"""The project should be set up with the desired name and default objets when a new project is created."""
43-
model = MainWindowModel()
4449
assert model.project is None
4550
assert model.controls is None
4651
assert model.results is None
@@ -53,8 +58,7 @@ def test_create_project():
5358
assert model.save_path == "C:/test"
5459

5560

56-
def test_save_project(empty_results):
57-
model = MainWindowModel()
61+
def test_save_project(empty_results, model):
5862
model.project = Project(calculation="domains", name="test project")
5963
model.controls = Controls(procedure="dream", resampleMinAngle=0.5)
6064
model.results = empty_results
@@ -73,9 +77,8 @@ def test_save_project(empty_results):
7377
assert '"fitParams": []' in results
7478

7579

76-
def test_load_project(empty_results):
80+
def test_load_project(empty_results, model):
7781
"""The load function should load the correct controls object from JSON."""
78-
model = MainWindowModel()
7982
project = Project(name="test project", calculation="domains")
8083

8184
with TemporaryDirectory() as tmpdir:
@@ -91,20 +94,17 @@ def test_load_project(empty_results):
9194

9295

9396
@patch("ratapi.utils.convert.r1_to_project")
94-
def test_load_r1_project(mock_r1_class):
97+
def test_load_r1_project(mock_r1_class, model):
9598
"""load_r1_project should call the conversion function and set the path correctly."""
96-
model = MainWindowModel()
9799
model.load_r1_project("test_path/r1project.mat")
98100

99101
mock_r1_class.assert_called_once()
100102
assert model.save_path == "test_path"
101103

102104

103105
@pytest.mark.parametrize("bad_json", ['{"field1":3', '{"procedure":"fry eggs"}'])
104-
def test_load_controls_error(bad_json):
106+
def test_load_controls_error(bad_json, model):
105107
"""The project load function should raise an error if the controls JSON is invalid or the parameters are invalid."""
106-
model = MainWindowModel()
107-
108108
with pytest.raises( # noqa (for nested with's: pytest.raises breaks if not by itself)
109109
ValueError,
110110
match="The controls.json file for this project is not valid.\n"
@@ -116,10 +116,8 @@ def test_load_controls_error(bad_json):
116116

117117

118118
@pytest.mark.parametrize("bad_json", ['{"calculation":"Do}', '{i"m not a good project file'])
119-
def test_load_project_decode_error(bad_json):
119+
def test_load_project_decode_error(bad_json, model):
120120
"""The project load function should raise an error if the project JSON is invalid JSON."""
121-
model = MainWindowModel()
122-
123121
with pytest.raises( # noqa (for nested with's: pytest.raises breaks if not by itself)
124122
ValueError, match="The project.json file for this project contains invalid JSON."
125123
):
@@ -132,10 +130,8 @@ def test_load_project_decode_error(bad_json):
132130
@pytest.mark.parametrize(
133131
"bad_json", ['{"calculation":"guessing"}', '{"parameters":[{"name":"parameter 1","thickness":0.51}]}']
134132
)
135-
def test_load_project_value_error(bad_json):
133+
def test_load_project_value_error(bad_json, model):
136134
"""The project load function should raise an error if the values are not valid."""
137-
model = MainWindowModel()
138-
139135
with pytest.raises( # noqa (for nested with's: pytest.raises breaks if not by itself)
140136
ValueError, match="The project.json file for this project is not valid."
141137
):

tests/ui/test_presenter.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ def __init__(self):
4747

4848
@pytest.fixture
4949
def presenter():
50-
with patch("rascal2.ui.presenter.LOGGER", autospec=True) as mock_log:
50+
with (
51+
patch("rascal2.ui.presenter.LOGGER", autospec=True) as mock_log,
52+
patch("rascal2.ui.model.os.chdir", autospec=True),
53+
):
5154
pr = MainWindowPresenter(MockWindowView())
5255
pr.runner = MagicMock()
5356
pr.model.controls = Controls()

0 commit comments

Comments
 (0)