Skip to content

Commit c021d8f

Browse files
committed
Changes checks in save and load to parent directories
1 parent 027bca6 commit c021d8f

File tree

13 files changed

+17
-20
lines changed

13 files changed

+17
-20
lines changed

RATapi/examples/absorption/absorption.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def absorption():
108108
name="DPPC absorption",
109109
filename="volume_thiol_bilayer.py",
110110
language="python",
111-
path=pathlib.Path(__file__).parent.resolve(),
111+
path=pathlib.Path(__file__).parent,
112112
)
113113

114114
# Finally add the contrasts

RATapi/examples/absorption/volume_thiol_bilayer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def volume_thiol_bilayer(params, bulk_in, bulk_out, contrast):
133133

134134
CW = [cwThick, bulk_out[contrast], 0, bilayerRough]
135135

136-
if contrast == 0 or contrast == 2:
136+
if contrast == 1 or contrast == 3:
137137
output = [alloyUp, gold, SAMTAILS, SAMHEAD, CW, *BILAYER]
138138
else:
139139
output = [alloyDown, gold, SAMTAILS, SAMHEAD, CW, *BILAYER]

RATapi/examples/domains/domains_custom_XY.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def domains_custom_XY():
3535
name="Domain Layer",
3636
filename="domains_XY_model.py",
3737
language="python",
38-
path=pathlib.Path(__file__).parent.resolve(),
38+
path=pathlib.Path(__file__).parent,
3939
)
4040

4141
# Make contrasts

RATapi/examples/domains/domains_custom_layers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def domains_custom_layers():
3232
name="Alloy domains",
3333
filename="alloy_domains.py",
3434
language="python",
35-
path=pathlib.Path(__file__).parent.resolve(),
35+
path=pathlib.Path(__file__).parent,
3636
)
3737

3838
# Make a contrast

RATapi/examples/languages/run_custom_file_languages.py

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

88
import RATapi as RAT
99

10-
path = pathlib.Path(__file__).parent.resolve()
10+
path = pathlib.Path(__file__).parent
1111

1212
project = setup_problem.make_example_problem()
1313
controls = RAT.Controls()

RATapi/examples/languages/setup_problem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def make_example_problem():
5555
name="DSPC Model",
5656
filename="custom_bilayer.py",
5757
language="python",
58-
path=pathlib.Path(__file__).parent.resolve(),
58+
path=pathlib.Path(__file__).parent,
5959
)
6060

6161
# Also, add the relevant background parameters - one each for each contrast:

RATapi/examples/normal_reflectivity/DSPC_custom_XY.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def DSPC_custom_XY():
7575
name="DSPC Model",
7676
filename="custom_XY_DSPC.py",
7777
language="python",
78-
path=pathlib.Path(__file__).parent.resolve(),
78+
path=pathlib.Path(__file__).parent,
7979
)
8080

8181
# Also, add the relevant background parameters - one each for each contrast:

RATapi/examples/normal_reflectivity/DSPC_custom_layers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def DSPC_custom_layers():
5252
name="DSPC Model",
5353
filename="custom_bilayer_DSPC.py",
5454
language="python",
55-
path=pathlib.Path(__file__).parent.resolve(),
55+
path=pathlib.Path(__file__).parent,
5656
)
5757

5858
# Also, add the relevant background parameters - one each for each contrast:

RATapi/examples/normal_reflectivity/DSPC_function_background.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def DSPC_function_background():
148148
name="D2O Background Function",
149149
filename="background_function.py",
150150
language="python",
151-
path=pathlib.Path(__file__).parent.resolve(),
151+
path=pathlib.Path(__file__).parent,
152152
)
153153

154154
problem.background_parameters.append(name="Fn Ao", min=5e-7, value=8e-6, max=5e-5)

RATapi/project.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,8 @@ def write_item(item):
868868
+ f"'filename': '{item.filename}', "
869869
+ f"'function_name': '{item.function_name}', "
870870
+ f"'language': '{str(item.language)}', "
871-
+ f"'path': r'{str(item.path)}'" # Raw string to ensure backslash is not interpreted as escape
871+
# Raw string to ensure backslash is not interpreted as escape
872+
+ f"'path': r'{str(try_relative_to(item.path, script_path.parent))}'"
872873
+ "}"
873874
)
874875
return item_str
@@ -932,7 +933,7 @@ def make_custom_file_dict(item):
932933
"name": item.name,
933934
"filename": item.filename,
934935
"language": item.language,
935-
"path": try_relative_to(item.path, filepath),
936+
"path": try_relative_to(item.path, filepath.parent),
936937
}
937938

938939
json_dict["custom_files"] = [make_custom_file_dict(file) for file in attr]
@@ -968,7 +969,7 @@ def load(cls, path: Union[str, Path]) -> "Project":
968969
# file paths are saved as relative to the project directory
969970
for file in model_dict["custom_files"]:
970971
if not Path(file["path"]).is_absolute():
971-
file["path"] = Path(path, file["path"])
972+
file["path"] = Path(path.parent, file["path"]).resolve()
972973

973974
return cls.model_validate(model_dict)
974975

@@ -1038,7 +1039,7 @@ def try_relative_to(path: Path, relative_to: Path) -> str:
10381039
return str(path.relative_to(relative_to))
10391040
else:
10401041
warnings.warn(
1041-
"Could not save custom file path as relative to the project directory, "
1042+
"Could not write custom file path as relative to the project directory, "
10421043
"which means that it may not work on other devices. If you would like to share your project, "
10431044
"make sure your custom files are in a subfolder of the project save location.",
10441045
stacklevel=2,

0 commit comments

Comments
 (0)