Skip to content

Commit

Permalink
setup: use llnl.util.link_tree instead of reimplementing
Browse files Browse the repository at this point in the history
  • Loading branch information
becker33 committed Dec 3, 2024
1 parent 2583778 commit 45485a0
Showing 1 changed file with 17 additions and 33 deletions.
50 changes: 17 additions & 33 deletions lib/benchpark/cmd/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,10 @@
from benchpark.debug import debug_print
from benchpark.runtime import RuntimeResources

bootstrapper = RuntimeResources(benchpark.paths.benchpark_home) # noqa
bootstrapper.bootstrap() # noqa

# 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, 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}")
for src_subdir, directories, files in os.walk(src):
relative_src_dir = pathlib.Path(os.path.relpath(src_subdir, src))
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)
import llnl.util.link_tree # noqa


def setup_parser(root_parser):
Expand Down Expand Up @@ -183,23 +165,25 @@ def command(args):
ramble_logs_dir.mkdir(parents=True)
ramble_spack_experiment_configs_dir.mkdir(parents=True)

def include_fn(fname):
def ignore_fn(fname):
# Only include .yaml files
# Always exclude files that start with "."
if fname.startswith("."):
return False
if fname.endswith(".yaml"):
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)
symlink_tree(
source_dir / "configs" / "common",
ramble_spack_experiment_configs_dir,
include_fn,
if fname.endswith(".yaml"):
return False
return True

configs_tree = llnl.util.link_tree.LinkTree(configs_src_dir)
experiment_tree = llnl.util.link_tree.LinkTree(experiments_src_dir)
modifier_tree = llnl.util.link_tree.LinkTree(modifier_config_dir)
for tree in (configs_tree, experiment_tree, modifier_tree):
tree.merge(ramble_configs_dir, ignore=ignore_fn)

common_configs_tree = llnl.util.link_tree.LinkTree(
source_dir / "configs" / "common"
)
common_configs_tree.merge(ramble_spack_experiment_configs_dir, ignore=ignore_fn)

template_name = "execute_experiment.tpl"
experiment_template_options = [
Expand Down

0 comments on commit 45485a0

Please sign in to comment.