Skip to content

Commit 57a7f36

Browse files
committed
save now just has one filename parameter
1 parent cb5e6b6 commit 57a7f36

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

RATapi/project.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -837,18 +837,17 @@ def classlist_script(name, classlist):
837837
+ "\n)"
838838
)
839839

840-
def save(self, filepath: Union[str, Path], filename: str = "project"):
840+
def save(self, filepath: Union[str, Path] = "./project.json"):
841841
"""Save a project to a JSON file.
842842
843843
Parameters
844844
----------
845845
filepath : str or Path
846-
The path in which the project will be written.
847-
filename : str
848-
The name of the generated project file.
846+
The path to where the project file will be written.
849847
850848
"""
851-
filepath = Path(filepath)
849+
filepath = Path(filepath).with_suffix(".json")
850+
852851
json_dict = {}
853852
for field in self.model_fields:
854853
attr = getattr(self, field)
@@ -881,9 +880,8 @@ def make_custom_file_dict(item):
881880
json_dict[field] = [item.model_dump() for item in attr]
882881
else:
883882
json_dict[field] = attr
884-
885-
file = Path(filepath, f"{filename.removesuffix('.json')}.json")
886-
file.write_text(json.dumps(json_dict))
883+
884+
filepath.write_text(json.dumps(json_dict))
887885

888886
@classmethod
889887
def load(cls, path: Union[str, Path]) -> "Project":

tests/test_project.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,10 +1559,11 @@ def test_save_load(project, request):
15591559

15601560
with tempfile.TemporaryDirectory() as tmp:
15611561
# ignore relative path warnings
1562+
path = Path(tmp, "project.json")
15621563
with warnings.catch_warnings():
15631564
warnings.simplefilter("ignore")
1564-
original_project.save(tmp)
1565-
converted_project = RATapi.Project.load(Path(tmp, "project.json"))
1565+
original_project.save(path)
1566+
converted_project = RATapi.Project.load(path)
15661567

15671568
# resolve custom files in case the original project had unresolvable relative paths
15681569
for file in original_project.custom_files:

0 commit comments

Comments
 (0)