Skip to content

Commit bff93e5

Browse files
committed
fordpath -> path
1 parent 85f40a0 commit bff93e5

File tree

3 files changed

+69
-71
lines changed

3 files changed

+69
-71
lines changed

manage/cli.py

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ def clean_workspace(
116116
# 2. Go through symlinks, figuring out which "children of task runs" to keep
117117
# Based on the rules of the framework, "children of task runs" should be run_*/ directories.
118118
# However, the user's workspace might happen to break these rules by putting directories not
119-
# named "run_*/" or files directly in task_runs/. Thus, I use the term "task_run_child_fordpaths"
119+
# named "run_*/" or files directly in task_runs/. Thus, I use the term "task_run_child_paths"
120120
# instead of "run_dpaths".
121-
task_run_child_fordpaths_to_keep = set()
121+
task_run_child_paths_to_keep = set()
122122

123123
if dbgym_workspace.dbgym_runs_path.exists():
124124
while symlink_fpaths_to_process:
@@ -127,66 +127,64 @@ def clean_workspace(
127127
# Path.resolve() resolves all layers of symlinks while os.readlink() only resolves one layer.
128128
# However, os.readlink() literally reads the string contents of the link. We need to do some
129129
# processing on the result of os.readlink() to convert it to an absolute path
130-
real_fordpath = symlink_fpath.resolve()
131-
one_layer_resolved_fordpath = os.readlink(symlink_fpath)
132-
assert str(real_fordpath) == str(
130+
real_path = symlink_fpath.resolve()
131+
one_layer_resolved_path = os.readlink(symlink_fpath)
132+
assert str(real_path) == str(
133133
os.readlink(symlink_fpath)
134134
), f"symlink_fpath ({symlink_fpath}) seems to point to *another* symlink. This is difficult to handle, so it is currently disallowed. Please resolve this situation manually."
135135

136136
# If the file doesn't exist, we'll just ignore it.
137-
if not real_fordpath.exists():
137+
if not real_path.exists():
138138
continue
139139
# We're only trying to figure out which direct children of task_runs/ to save. If the file isn't
140140
# even a descendant, we don't care about it.
141-
if not is_child_path(real_fordpath, dbgym_workspace.dbgym_runs_path):
141+
if not is_child_path(real_path, dbgym_workspace.dbgym_runs_path):
142142
continue
143143

144-
assert not real_fordpath.samefile(dbgym_workspace.dbgym_runs_path)
144+
assert not real_path.samefile(dbgym_workspace.dbgym_runs_path)
145145

146-
# Figure out the task_run_child_fordpath to put into task_run_child_fordpaths_to_keep
147-
task_run_child_fordpath = None
148-
if parent_dpath_of_path(real_fordpath).samefile(
146+
# Figure out the task_run_child_path to put into task_run_child_paths_to_keep
147+
task_run_child_path = None
148+
if parent_dpath_of_path(real_path).samefile(
149149
dbgym_workspace.dbgym_runs_path
150150
):
151151
# While it's true that it shouldn't be possible to symlink to a directory directly in task_runs/,
152152
# we'll just not delete it if the user happens to have one like this. Even if the user messed up
153153
# the structure somehow, it's just a good idea not to delete it.
154-
task_run_child_fordpath = real_fordpath
154+
task_run_child_path = real_path
155155
else:
156156
# Technically, it's not allowed to symlink to any files not in task_runs/run_*/[codebase]/[organization]/.
157157
# However, as with above, we won't just nuke files if the workspace doesn't follow this rule for
158158
# some reason.
159-
task_run_child_fordpath = real_fordpath
160-
while not parent_dpath_of_path(task_run_child_fordpath).samefile(
159+
task_run_child_path = real_path
160+
while not parent_dpath_of_path(task_run_child_path).samefile(
161161
dbgym_workspace.dbgym_runs_path
162162
):
163-
task_run_child_fordpath = parent_dpath_of_path(
164-
task_run_child_fordpath
165-
)
166-
assert task_run_child_fordpath != None
167-
assert parent_dpath_of_path(task_run_child_fordpath).samefile(
163+
task_run_child_path = parent_dpath_of_path(task_run_child_path)
164+
assert task_run_child_path != None
165+
assert parent_dpath_of_path(task_run_child_path).samefile(
168166
dbgym_workspace.dbgym_runs_path
169-
), f"task_run_child_fordpath ({task_run_child_fordpath}) is not a direct child of dbgym_workspace.dbgym_runs_path"
170-
task_run_child_fordpaths_to_keep.add(task_run_child_fordpath)
167+
), f"task_run_child_path ({task_run_child_path}) is not a direct child of dbgym_workspace.dbgym_runs_path"
168+
task_run_child_paths_to_keep.add(task_run_child_path)
171169

172-
# If on safe mode, add symlinks inside the task_run_child_fordpath to be processed
170+
# If on safe mode, add symlinks inside the task_run_child_path to be processed
173171
if mode == "safe":
174172
add_symlinks_in_dpath(
175173
symlink_fpaths_to_process,
176-
task_run_child_fordpath,
174+
task_run_child_path,
177175
processed_symlinks,
178176
)
179177

180178
# 3. Go through all children of task_runs/*, deleting any that we weren't told to keep
181179
# It's true that symlinks might link outside of task_runs/*. We'll just not care about those
182180
starting_num_files = _count_files_in_workspace(dbgym_workspace)
183181
if dbgym_workspace.dbgym_runs_path.exists():
184-
for child_fordpath in dbgym_workspace.dbgym_runs_path.iterdir():
185-
if child_fordpath not in task_run_child_fordpaths_to_keep:
186-
if child_fordpath.is_dir():
187-
shutil.rmtree(child_fordpath)
182+
for child_path in dbgym_workspace.dbgym_runs_path.iterdir():
183+
if child_path not in task_run_child_paths_to_keep:
184+
if child_path.is_dir():
185+
shutil.rmtree(child_path)
188186
else:
189-
os.remove(child_fordpath)
187+
os.remove(child_path)
190188
ending_num_files = _count_files_in_workspace(dbgym_workspace)
191189

192190
if verbose:

util/tests/unittest_workspace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def test_link_result_cannot_link_symlink(self) -> None:
273273
)
274274
with self.assertRaisesRegex(
275275
AssertionError,
276-
"result_fordpath \(.*\) should be a fully resolved path",
276+
"result_path \(.*\) should be a fully resolved path",
277277
):
278278
self.workspace.link_result(symlink_path)
279279

util/workspace.py

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -169,37 +169,37 @@ def __init__(self, dbgym_workspace_path: Path):
169169
# TODO(phw2): refactor our manual symlinking in postgres/cli.py to use link_result() instead
170170
def link_result(
171171
self,
172-
result_fordpath: Path,
172+
result_path: Path,
173173
custom_link_name: Optional[str] = None,
174174
) -> Path:
175175
"""
176-
result_fordpath must be a "result", meaning it was generated inside dbgym_workspace.dbgym_this_run_path.
177-
Further, result_fordpath must have been generated by this invocation to task.py. This also means that
178-
result_fordpath itself can be a file or a dir but not a symlink.
176+
result_path must be a "result", meaning it was generated inside dbgym_workspace.dbgym_this_run_path.
177+
Further, result_path must have been generated by this invocation to task.py. This also means that
178+
result_path itself can be a file or a dir but not a symlink.
179179
Given a file or directory in task_runs/run_*/[codebase]/[org], this will create a symlink inside
180180
symlinks/[codebase]/[org]/.
181181
Will override the old symlink if there is one, so that symlinks/ always contains the latest generated
182182
version of a file.
183183
This function will return the path to the symlink that was created.
184184
"""
185-
assert isinstance(result_fordpath, Path)
185+
assert isinstance(result_path, Path)
186186
assert is_fully_resolved(
187-
result_fordpath
188-
), f"result_fordpath ({result_fordpath}) should be a fully resolved path"
187+
result_path
188+
), f"result_path ({result_path}) should be a fully resolved path"
189189
assert is_child_path(
190-
result_fordpath, self.dbgym_this_run_path
190+
result_path, self.dbgym_this_run_path
191191
), "The result must have been generated in *this* run_*/ dir"
192-
assert not os.path.islink(result_fordpath)
192+
assert not os.path.islink(result_path)
193193

194194
if type(custom_link_name) is str:
195195
link_name = custom_link_name
196196
else:
197-
if os.path.isfile(result_fordpath):
198-
link_name = basename_of_path(result_fordpath) + ".link"
199-
elif os.path.isdir(result_fordpath):
200-
link_name = basename_of_path(result_fordpath) + ".link"
197+
if os.path.isfile(result_path):
198+
link_name = basename_of_path(result_path) + ".link"
199+
elif os.path.isdir(result_path):
200+
link_name = basename_of_path(result_path) + ".link"
201201
else:
202-
raise AssertionError("result_fordpath must be either a file or dir")
202+
raise AssertionError("result_path must be either a file or dir")
203203

204204
symlink_parent_dpath = self.dbgym_symlinks_path / self.app_name
205205
symlink_parent_dpath.mkdir(parents=True, exist_ok=True)
@@ -213,7 +213,7 @@ def link_result(
213213
), f'link_name ({link_name}) should end with ".link"'
214214
symlink_path = symlink_parent_dpath / link_name
215215
try_remove_file(symlink_path)
216-
try_create_symlink(result_fordpath, symlink_path)
216+
try_create_symlink(result_path, symlink_path)
217217

218218
return symlink_path
219219

@@ -560,27 +560,27 @@ def open_and_save(
560560
return open(open_fpath, mode=mode)
561561

562562

563-
def extract_from_task_run_fordpath(
564-
dbgym_workspace: DBGymWorkspace, task_run_fordpath: Path
563+
def extract_from_task_run_path(
564+
dbgym_workspace: DBGymWorkspace, task_run_path: Path
565565
) -> tuple[Path, str, Path, str]:
566566
"""
567567
The task_runs/ folder is organized like task_runs/run_*/[codebase]/[org]/any/path/you/want.
568568
This function extracts the [codebase] and [org] components
569569
"""
570-
assert isinstance(task_run_fordpath, Path)
571-
assert not task_run_fordpath.is_symlink()
572-
parent_dpath = task_run_fordpath.parent
570+
assert isinstance(task_run_path, Path)
571+
assert not task_run_path.is_symlink()
572+
parent_dpath = task_run_path.parent
573573
# TODO(phw2): make this a common function
574574
assert not parent_dpath.samefile(
575575
dbgym_workspace.dbgym_runs_path
576-
), f"task_run_fordpath ({task_run_fordpath}) should be inside a run_*/ dir instead of directly in dbgym_workspace.dbgym_runs_path ({dbgym_workspace.dbgym_runs_path})"
576+
), f"task_run_path ({task_run_path}) should be inside a run_*/ dir instead of directly in dbgym_workspace.dbgym_runs_path ({dbgym_workspace.dbgym_runs_path})"
577577
assert not parent_dpath_of_path(parent_dpath).samefile(
578578
dbgym_workspace.dbgym_runs_path
579-
), f"task_run_fordpath ({task_run_fordpath}) should be inside a run_*/[codebase]/ dir instead of directly in run_*/ ({dbgym_workspace.dbgym_runs_path})"
579+
), f"task_run_path ({task_run_path}) should be inside a run_*/[codebase]/ dir instead of directly in run_*/ ({dbgym_workspace.dbgym_runs_path})"
580580
assert not parent_dpath_of_path(parent_dpath_of_path(parent_dpath)).samefile(
581581
dbgym_workspace.dbgym_runs_path
582-
), f"task_run_fordpath ({task_run_fordpath}) should be inside a run_*/[codebase]/[organization]/ dir instead of directly in run_*/ ({dbgym_workspace.dbgym_runs_path})"
583-
# org_dpath is the run_*/[codebase]/[organization]/ dir that task_run_fordpath is in
582+
), f"task_run_path ({task_run_path}) should be inside a run_*/[codebase]/[organization]/ dir instead of directly in run_*/ ({dbgym_workspace.dbgym_runs_path})"
583+
# org_dpath is the run_*/[codebase]/[organization]/ dir that task_run_path is in
584584
org_dpath = parent_dpath
585585
while not parent_dpath_of_path(
586586
parent_dpath_of_path(parent_dpath_of_path(org_dpath))
@@ -617,7 +617,7 @@ def save_file(dbgym_workspace: DBGymWorkspace, fpath: Path) -> None:
617617
# 2. files or dirs generated by a run may be very large (up to 100s of GBs) so we don't want to copy them
618618
if is_child_path(fpath, dbgym_workspace.dbgym_runs_path):
619619
# get paths we'll need later.
620-
_, codebase_dname, org_dpath, org_dname = extract_from_task_run_fordpath(
620+
_, codebase_dname, org_dpath, org_dname = extract_from_task_run_path(
621621
dbgym_workspace, fpath
622622
)
623623
this_run_save_dpath = (
@@ -658,39 +658,39 @@ def save_file(dbgym_workspace: DBGymWorkspace, fpath: Path) -> None:
658658
# TODO(phw2): deprecate this once I'm done with unittest_workspace.py
659659
def link_result(
660660
dbgym_workspace: DBGymWorkspace,
661-
result_fordpath: Path,
661+
result_path: Path,
662662
custom_result_name: Optional[str] = None,
663663
) -> Path:
664664
"""
665-
result_fordpath must be a "result", meaning it was generated inside dbgym_workspace.dbgym_this_run_path.
666-
Further, result_fordpath must have been generated by this invocation to task.py. This also means that
667-
result_fordpath itself can be a file or a dir but not a symlink.
665+
result_path must be a "result", meaning it was generated inside dbgym_workspace.dbgym_this_run_path.
666+
Further, result_path must have been generated by this invocation to task.py. This also means that
667+
result_path itself can be a file or a dir but not a symlink.
668668
Given a file or directory in task_runs/run_*/[codebase]/[org], this will create a symlink inside
669669
symlinks/[codebase]/[org]/.
670670
Will override the old symlink if there is one, so that symlinks/ always contains the latest generated
671671
version of a file.
672672
This function will return the path to the symlink that was created.
673673
"""
674-
assert isinstance(result_fordpath, Path)
674+
assert isinstance(result_path, Path)
675675
assert is_fully_resolved(
676-
result_fordpath
677-
), f"result_fordpath ({result_fordpath}) should be a fully resolved path"
678-
assert is_child_path(result_fordpath, dbgym_workspace.dbgym_this_run_path)
679-
assert not os.path.islink(result_fordpath)
676+
result_path
677+
), f"result_path ({result_path}) should be a fully resolved path"
678+
assert is_child_path(result_path, dbgym_workspace.dbgym_this_run_path)
679+
assert not os.path.islink(result_path)
680680

681681
if type(custom_result_name) is str:
682682
result_name = custom_result_name
683683
else:
684-
if os.path.isfile(result_fordpath):
685-
result_name = basename_of_path(result_fordpath) + ".link"
686-
elif os.path.isdir(result_fordpath):
687-
result_name = basename_of_path(result_fordpath) + ".link"
684+
if os.path.isfile(result_path):
685+
result_name = basename_of_path(result_path) + ".link"
686+
elif os.path.isdir(result_path):
687+
result_name = basename_of_path(result_path) + ".link"
688688
else:
689-
raise AssertionError("result_fordpath must be either a file or dir")
689+
raise AssertionError("result_path must be either a file or dir")
690690

691691
# Figure out the parent directory path of the symlink
692-
codebase_dpath, codebase_dname, _, org_dname = extract_from_task_run_fordpath(
693-
dbgym_workspace, result_fordpath
692+
codebase_dpath, codebase_dname, _, org_dname = extract_from_task_run_path(
693+
dbgym_workspace, result_path
694694
)
695695
# We're only supposed to save files generated by us, which means they should be in cur_task_runs_path()
696696
assert codebase_dpath.samefile(
@@ -710,7 +710,7 @@ def link_result(
710710
), f'result_name ({result_name}) should end with ".link"'
711711
symlink_path = symlink_parent_dpath / result_name
712712
try_remove_file(symlink_path)
713-
try_create_symlink(result_fordpath, symlink_path)
713+
try_create_symlink(result_path, symlink_path)
714714

715715
return symlink_path
716716

0 commit comments

Comments
 (0)