Skip to content

Commit dde1f14

Browse files
committed
moved clean and replay to orchestrate
1 parent 0c01d07 commit dde1f14

File tree

8 files changed

+41
-38
lines changed

8 files changed

+41
-38
lines changed
File renamed without changes.

manage/cli.py renamed to orchestrate/clean.py

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from itertools import chain
55
from pathlib import Path
66

7-
import click
87
from gymlib.workspace import (
98
DBGymWorkspace,
109
get_runs_path_from_workspace_path,
@@ -14,7 +13,7 @@
1413
)
1514

1615

17-
# This is used in test_clean.py. It's defined here to avoid a circular import.
16+
# This is used in test_clean.py. However, we also need it in count_files_in_workspace, so it's defined here to avoid a circular import.
1817
class MockDBGymWorkspace:
1918
def __init__(self, scratchspace_path: Path):
2019
self.dbgym_workspace_path = scratchspace_path
@@ -24,32 +23,6 @@ def __init__(self, scratchspace_path: Path):
2423
self.dbgym_runs_path = get_runs_path_from_workspace_path(scratchspace_path)
2524

2625

27-
@click.group(name="manage")
28-
def manage_group() -> None:
29-
pass
30-
31-
32-
@click.command("clean")
33-
@click.pass_obj
34-
@click.option(
35-
"--mode",
36-
type=click.Choice(["safe", "aggressive"]),
37-
default="safe",
38-
help='The mode to clean the workspace (default="safe"). "aggressive" means "only keep run_*/ folders referenced by a file in symlinks/". "safe" means "in addition to that, recursively keep any run_*/ folders referenced by any symlinks in run_*/ folders we are keeping."',
39-
)
40-
def manage_clean(dbgym_workspace: DBGymWorkspace, mode: str) -> None:
41-
clean_workspace(dbgym_workspace, mode=mode, verbose=True)
42-
43-
44-
@click.command("count")
45-
@click.pass_obj
46-
def manage_count(dbgym_workspace: DBGymWorkspace) -> None:
47-
num_files = _count_files_in_workspace(dbgym_workspace)
48-
print(
49-
f"The workspace ({dbgym_workspace.dbgym_workspace_path}) has {num_files} total files/dirs/symlinks."
50-
)
51-
52-
5326
def add_symlinks_in_path(
5427
symlinks_stack: list[Path], root_path: Path, processed_symlinks: set[Path]
5528
) -> None:
@@ -66,7 +39,7 @@ def add_symlinks_in_path(
6639
processed_symlinks.add(file_path)
6740

6841

69-
def _count_files_in_workspace(
42+
def count_files_in_workspace(
7043
dbgym_workspace: DBGymWorkspace | MockDBGymWorkspace,
7144
) -> int:
7245
"""
@@ -173,15 +146,15 @@ def clean_workspace(
173146

174147
# 3. Go through all children of task_runs/*, deleting any that we weren't told to keep
175148
# It's true that symlinks might link outside of task_runs/*. We'll just not care about those
176-
starting_num_files = _count_files_in_workspace(dbgym_workspace)
149+
starting_num_files = count_files_in_workspace(dbgym_workspace)
177150
if dbgym_workspace.dbgym_runs_path.exists():
178151
for child_path in dbgym_workspace.dbgym_runs_path.iterdir():
179152
if child_path not in task_run_child_paths_to_keep:
180153
if child_path.is_dir():
181154
shutil.rmtree(child_path)
182155
else:
183156
os.remove(child_path)
184-
ending_num_files = _count_files_in_workspace(dbgym_workspace)
157+
ending_num_files = count_files_in_workspace(dbgym_workspace)
185158

186159
if verbose:
187160
logging.info(
@@ -190,7 +163,3 @@ def clean_workspace(
190163
logging.info(
191164
f"Workspace went from {starting_num_files - ending_num_files} to {starting_num_files}"
192165
)
193-
194-
195-
manage_group.add_command(manage_clean)
196-
manage_group.add_command(manage_count)

orchestrate/cli.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import click
2+
from gymlib.workspace import DBGymWorkspace
3+
4+
from orchestrate.clean import clean_workspace, count_files_in_workspace
5+
6+
7+
@click.group(name="manage")
8+
def manage_group() -> None:
9+
pass
10+
11+
12+
@click.command("clean")
13+
@click.pass_obj
14+
@click.option(
15+
"--mode",
16+
type=click.Choice(["safe", "aggressive"]),
17+
default="safe",
18+
help='The mode to clean the workspace (default="safe"). "aggressive" means "only keep run_*/ folders referenced by a file in symlinks/". "safe" means "in addition to that, recursively keep any run_*/ folders referenced by any symlinks in run_*/ folders we are keeping."',
19+
)
20+
def manage_clean(dbgym_workspace: DBGymWorkspace, mode: str) -> None:
21+
clean_workspace(dbgym_workspace, mode=mode, verbose=True)
22+
23+
24+
@click.command("count")
25+
@click.pass_obj
26+
def manage_count(dbgym_workspace: DBGymWorkspace) -> None:
27+
num_files = count_files_in_workspace(dbgym_workspace)
28+
print(
29+
f"The workspace ({dbgym_workspace.dbgym_workspace_path}) has {num_files} total files/dirs/symlinks."
30+
)
31+
32+
33+
manage_group.add_command(manage_clean)
34+
manage_group.add_command(manage_count)
File renamed without changes.
File renamed without changes.

gymlib_package/gymlib/tests/integtest_replay.py renamed to orchestrate/tests/integtest_replay.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import unittest
22

3-
from gymlib.replay import replay
43
from gymlib.tests.gymlib_integtest_util import GymlibIntegtestManager
54
from gymlib.tuning_artifacts import (
65
DBMSConfigDelta,
@@ -12,6 +11,7 @@
1211
from gymlib.workspace import DBGymWorkspace
1312

1413
from benchmark.tpch.constants import DEFAULT_TPCH_SEED
14+
from orchestrate.replay import replay
1515

1616

1717
class ReplayTests(unittest.TestCase):

manage/tests/unittest_clean.py renamed to orchestrate/tests/unittest_clean.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
verify_structure,
1111
)
1212

13-
from manage.cli import MockDBGymWorkspace, clean_workspace
13+
from orchestrate.clean import MockDBGymWorkspace, clean_workspace
1414

1515
# This is here instead of on `if __name__ == "__main__"` because we often run individual tests, which
1616
# does not go through the `if __name__ == "__main__"` codepath.

task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from benchmark.cli import benchmark_group
55
from dbms.cli import dbms_group
6-
from manage.cli import manage_group
6+
from orchestrate.cli import manage_group
77

88
# TODO(phw2): Save commit, git diff, and run command.
99
# TODO(phw2): Remove write permissions on old run_*/ dirs to enforce that they are immutable.

0 commit comments

Comments
 (0)