Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tune/docs] Update custom syncer example #27252

Merged
merged 1 commit into from
Jul 29, 2022
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
2 changes: 1 addition & 1 deletion doc/source/tune/doc_code/faq.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def sync_down(
) -> bool:
cmd_str = self.sync_down_template.format(
source=remote_dir,
local_dir=local_dir,
target=local_dir,
)
subprocess.check_call(cmd_str, shell=True)
return True
Expand Down
34 changes: 33 additions & 1 deletion python/ray/tune/tests/test_syncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def sync_down(
) -> bool:
cmd_str = self.sync_down_template.format(
source=remote_dir,
local_dir=local_dir,
target=local_dir,
)
subprocess.check_call(cmd_str, shell=True)
return True
Expand Down Expand Up @@ -191,6 +191,38 @@ def test_syncer_sync_up_down(temp_data_dirs):
assert_file(True, tmp_target, "subdir_exclude/something/somewhere.txt")


def test_syncer_sync_up_down_custom(temp_data_dirs):
"""Check that syncing up and down works"""
tmp_source, tmp_target = temp_data_dirs

syncer = CustomCommandSyncer(
sync_up_template="cp -rf {source} `echo '{target}' | cut -c 8-`",
sync_down_template="cp -rf `echo '{source}' | cut -c 8-` {target}",
delete_template="rm -rf `echo '{target}' | cut -c 8-`",
)

# remove target dir (otherwise OS will copy into)
shutil.rmtree(tmp_target)

syncer.sync_up(local_dir=tmp_source, remote_dir=f"file://{tmp_target}")
syncer.wait()

# remove target dir to test sync down
shutil.rmtree(tmp_source)

syncer.sync_down(remote_dir=f"file://{tmp_target}", local_dir=tmp_source)
syncer.wait()

# Target dir should have all files
assert_file(True, tmp_source, "level0.txt")
assert_file(True, tmp_source, "level0_exclude.txt")
assert_file(True, tmp_source, "subdir/level1.txt")
assert_file(True, tmp_source, "subdir/level1_exclude.txt")
assert_file(True, tmp_source, "subdir/nested/level2.txt")
assert_file(True, tmp_source, "subdir_nested_level2_exclude.txt")
assert_file(True, tmp_source, "subdir_exclude/something/somewhere.txt")


def test_syncer_sync_exclude(temp_data_dirs):
"""Check that the exclude parameter works"""
tmp_source, tmp_target = temp_data_dirs
Expand Down