Skip to content

Commit

Permalink
Add allow_overwrite to Result.save
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnel committed Oct 14, 2023
1 parent b2881fd commit 1944216
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions glotaran/project/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,20 @@ class Config:
parameters_intitial: Parameters
parameters_optimized: Parameters

def save(self, path: Path, options: SavingOptions = SAVING_OPTIONS_DEFAULT):
def save(
self,
path: Path,
options: SavingOptions = SAVING_OPTIONS_DEFAULT,
allow_overwrite: bool = False,
):
if path.exists() and path.is_file():
raise GlotaranUserError("Save folder must be a path.")
path.mkdir()
raise GlotaranUserError("Save path must be a folder.")
if path.exists() and not allow_overwrite:
raise GlotaranUserError(
"Save path already exists. Use allow_overwrite=True to overwrite."
)
result_dict: dict[str, Any] = {"data": {}, "experiments": {}}
path.mkdir(exist_ok=True, parents=True)

# TODO: Save scheme or experiments
# experiment_folder = path / "experiments"
Expand All @@ -54,7 +63,7 @@ def save(self, path: Path, options: SavingOptions = SAVING_OPTIONS_DEFAULT):
# write_dict(experiment.dict(), experiment_path)

data_path = path / "data"
data_path.mkdir()
data_path.mkdir(exist_ok=True)
for label, data in self.data.items():
dataset_path = data_path / f"{label}.{options.data_format}"
result_dict["data"][label] = str(dataset_path)
Expand Down

0 comments on commit 1944216

Please sign in to comment.