Skip to content

Commit fac4803

Browse files
committed
add warning if would overwrite results dir, suggest move/rename it
1 parent 893dad0 commit fac4803

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/virtualship/cli/_run.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import os
55
import shutil
6+
import sys
67
import time
78
from datetime import datetime
89
from pathlib import Path
@@ -131,9 +132,12 @@ def _run(
131132
return
132133

133134
# delete and create results directory
134-
if os.path.exists(expedition_dir.joinpath(RESULTS)):
135-
shutil.rmtree(expedition_dir.joinpath(RESULTS))
136-
os.makedirs(expedition_dir.joinpath(RESULTS))
135+
results_dir = expedition_dir.joinpath(RESULTS)
136+
_warn_overwrite(results_dir)
137+
138+
if os.path.exists(results_dir):
139+
shutil.rmtree(results_dir)
140+
os.makedirs(results_dir)
137141

138142
print("\n----- EXPEDITION SUMMARY ------")
139143

@@ -284,6 +288,21 @@ def _unique_id(expedition: Expedition, cache_dir: Path) -> str:
284288
return new_id
285289

286290

291+
def _warn_overwrite(results_dir: Path) -> None:
292+
if os.path.exists(results_dir):
293+
print(
294+
f"\nWARNING: The '{results_dir}' directory already exists and will be overwritten. If you want to keep the previous results, please move or rename the '{results_dir}' directory before re-running the expedition.\n"
295+
)
296+
decision = input(
297+
"Do you want to continue and overwrite the existing results? (y/n): "
298+
)
299+
if decision.lower() != "y":
300+
print("Expedition run cancelled by user.")
301+
sys.exit(0)
302+
if decision.lower() == "y":
303+
print("Continuing with expedition run and overwriting existing results...")
304+
305+
287306
def _load_checkpoint(expedition_dir: Path) -> Checkpoint | None:
288307
file_path = expedition_dir.joinpath(CHECKPOINT)
289308
try:

0 commit comments

Comments
 (0)