Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/virtualship/cli/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def _run(
expedition = _get_expedition(expedition_dir)

# unique id to determine if an expedition has 'changed' since last run (to avoid re-selecting problems when user makes tweaks to schedule to deal with problems encountered)
expedition_id = _unique_id(expedition, expedition_dir)
cache_dir = expedition_dir.joinpath(CACHE)
expedition_id = _unique_id(expedition, cache_dir)

# dedicated problems directory for this expedition
problems_dir = expedition_dir.joinpath(
Expand Down Expand Up @@ -234,6 +235,10 @@ def _run(
if os.path.exists(expedition_dir.joinpath(CHECKPOINT)):
os.remove(expedition_dir.joinpath(CHECKPOINT))

# delete cache dir if when --difficulty-level is 'easy' (no useful information to cache in this case, and can interfere with re-runs)
if difficulty_level == "easy" and os.path.exists(cache_dir):
shutil.rmtree(cache_dir)

print("\n------------- END -------------\n")

# end timing
Expand All @@ -242,7 +247,7 @@ def _run(
print(f"[TIMER] Expedition completed in {elapsed / 60.0:.2f} minutes.")


def _unique_id(expedition: Expedition, expedition_dir: Path) -> str:
def _unique_id(expedition: Expedition, cache_dir: Path) -> str:
"""
Return a unique id for the expedition (marked by datetime), which can be used to determine whether the expedition has 'changed' since the last run.

Expand All @@ -252,7 +257,6 @@ def _unique_id(expedition: Expedition, expedition_dir: Path) -> str:
new_id = datetime.now().strftime("%Y%m%d%H%M%S")
previous_id = None

cache_dir = expedition_dir.joinpath(CACHE)
if not cache_dir.exists():
cache_dir.mkdir()
id_path = cache_dir.joinpath(EXPEDITION_IDENTIFIER)
Expand Down
9 changes: 8 additions & 1 deletion tests/cli/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def execute(self, measurements, out_path):

def test_run(tmp_path, monkeypatch):
"""Testing as if using pre-downloaded, local data."""
difficulty_level = "easy"

expedition_dir = tmp_path / "expedition_dir"
expedition_dir.mkdir()
(expedition_dir / EXPEDITION).write_text(get_example_expedition())
Expand All @@ -54,7 +56,7 @@ def test_run(tmp_path, monkeypatch):
fake_data_dir.mkdir()

_run(
expedition_dir, difficulty_level="easy", from_data=fake_data_dir
expedition_dir, difficulty_level=difficulty_level, from_data=fake_data_dir
) # problems turned off here

results_dir = expedition_dir / "results"
Expand All @@ -64,3 +66,8 @@ def test_run(tmp_path, monkeypatch):
assert cost_file.exists()
content = cost_file.read_text()
assert "cost:" in content

# check cache dir is deleted at end of expedition when difficulty-level is easy
if difficulty_level == "easy":
cache_dir = expedition_dir / "cache"
assert not cache_dir.exists()