Skip to content

Commit e6ae4de

Browse files
authored
Adds support for relative paths for custom files (#163)
* Adds support for relative paths for custom files * Bug fix * Changes checks in save and load to parent directories * Adds test for relative path
1 parent c83b5eb commit e6ae4de

File tree

15 files changed

+32
-21
lines changed

15 files changed

+32
-21
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/models.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,13 @@ class CustomFile(RATModel):
304304
filename: str = ""
305305
function_name: str = ""
306306
language: Languages = Languages.Python
307-
path: pathlib.Path = pathlib.Path(".")
307+
path: pathlib.Path = pathlib.Path(".").resolve()
308+
309+
@field_validator("path")
310+
@classmethod
311+
def resolve_relative_paths(cls, path: pathlib.Path) -> pathlib.Path:
312+
"""Return the absolute path of the given path."""
313+
return path.resolve()
308314

309315
def model_post_init(self, __context: Any) -> None:
310316
"""Autogenerate the function name from the filename if not set.

0 commit comments

Comments
 (0)