Skip to content

Commit

Permalink
avoid copying swap files, backup files, and other kinds of transient …
Browse files Browse the repository at this point in the history
…files which might live in config or experiment dirs
  • Loading branch information
scheibelp committed Mar 7, 2024
1 parent 7ad6f71 commit 53fb745
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions bin/benchpark
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,14 @@ def run_command(command_str, env=None):
text=True,
)


# Note: it would be nice to vendor spack.llnl.util.link_tree, but that
# involves pulling in most of llnl/util/ and spack/util/
def symlink_tree(src, dst):
def symlink_tree(src, dst, include_fn=None):
"""Like ``cp -R`` but instead of files, create symlinks"""
src = os.path.abspath(src)
dst = os.path.abspath(dst)
# By default, we include all filenames
include_fn = include_fn or (lambda f: True)
for x in [src, dst]:
if not os.path.isdir(x):
raise ValueError(f"Not a directory: {x}")
Expand All @@ -197,6 +198,8 @@ def symlink_tree(src, dst):
dst_dir = pathlib.Path(dst) / relative_src_dir
dst_dir.mkdir(parents=True, exist_ok=True)
for x in files:
if not include_fn(x):
continue
dst_symlink = dst_dir / x
src_file = os.path.join(src_subdir, x)
os.symlink(src_file, dst_symlink)
Expand Down Expand Up @@ -256,9 +259,19 @@ def benchpark_setup_handler(args):
modifier_config_dir = source_dir / "modifiers" / modifier / "configs"

ramble_configs_dir.mkdir(parents=True)
symlink_tree(configs_src_dir, ramble_configs_dir)
symlink_tree(experiment_src_dir, ramble_configs_dir)
symlink_tree(modifier_config_dir, ramble_configs_dir)

def include_fn(fname):
# Only include .yaml and .tpl files
# Always exclude files that start with "."
if fname.startswith("."):
return False
if fname.endswith(".yaml") or fname.endswith(".tpl"):
return True
return False

symlink_tree(configs_src_dir, ramble_configs_dir, include_fn)
symlink_tree(experiment_src_dir, ramble_configs_dir, include_fn)
symlink_tree(modifier_config_dir, ramble_configs_dir, include_fn)

spack_location = experiments_root / "spack"
ramble_location = experiments_root / "ramble"
Expand Down

0 comments on commit 53fb745

Please sign in to comment.