Skip to content

Commit 45485a0

Browse files
committed
setup: use llnl.util.link_tree instead of reimplementing
1 parent 2583778 commit 45485a0

1 file changed

Lines changed: 17 additions & 33 deletions

File tree

lib/benchpark/cmd/setup.py

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,10 @@
2121
from benchpark.debug import debug_print
2222
from benchpark.runtime import RuntimeResources
2323

24+
bootstrapper = RuntimeResources(benchpark.paths.benchpark_home) # noqa
25+
bootstrapper.bootstrap() # noqa
2426

25-
# Note: it would be nice to vendor spack.llnl.util.link_tree, but that
26-
# involves pulling in most of llnl/util/ and spack/util/
27-
def symlink_tree(src, dst, include_fn=None):
28-
"""Like ``cp -R`` but instead of files, create symlinks"""
29-
src = os.path.abspath(src)
30-
dst = os.path.abspath(dst)
31-
# By default, we include all filenames
32-
include_fn = include_fn or (lambda f: True)
33-
for x in [src, dst]:
34-
if not os.path.isdir(x):
35-
raise ValueError(f"Not a directory: {x}")
36-
for src_subdir, directories, files in os.walk(src):
37-
relative_src_dir = pathlib.Path(os.path.relpath(src_subdir, src))
38-
dst_dir = pathlib.Path(dst) / relative_src_dir
39-
dst_dir.mkdir(parents=True, exist_ok=True)
40-
for x in files:
41-
if not include_fn(x):
42-
continue
43-
dst_symlink = dst_dir / x
44-
src_file = os.path.join(src_subdir, x)
45-
os.symlink(src_file, dst_symlink)
27+
import llnl.util.link_tree # noqa
4628

4729

4830
def setup_parser(root_parser):
@@ -183,23 +165,25 @@ def command(args):
183165
ramble_logs_dir.mkdir(parents=True)
184166
ramble_spack_experiment_configs_dir.mkdir(parents=True)
185167

186-
def include_fn(fname):
168+
def ignore_fn(fname):
187169
# Only include .yaml files
188170
# Always exclude files that start with "."
189171
if fname.startswith("."):
190-
return False
191-
if fname.endswith(".yaml"):
192172
return True
193-
return False
194-
195-
symlink_tree(configs_src_dir, ramble_configs_dir, include_fn)
196-
symlink_tree(experiment_src_dir, ramble_configs_dir, include_fn)
197-
symlink_tree(modifier_config_dir, ramble_configs_dir, include_fn)
198-
symlink_tree(
199-
source_dir / "configs" / "common",
200-
ramble_spack_experiment_configs_dir,
201-
include_fn,
173+
if fname.endswith(".yaml"):
174+
return False
175+
return True
176+
177+
configs_tree = llnl.util.link_tree.LinkTree(configs_src_dir)
178+
experiment_tree = llnl.util.link_tree.LinkTree(experiments_src_dir)
179+
modifier_tree = llnl.util.link_tree.LinkTree(modifier_config_dir)
180+
for tree in (configs_tree, experiment_tree, modifier_tree):
181+
tree.merge(ramble_configs_dir, ignore=ignore_fn)
182+
183+
common_configs_tree = llnl.util.link_tree.LinkTree(
184+
source_dir / "configs" / "common"
202185
)
186+
common_configs_tree.merge(ramble_spack_experiment_configs_dir, ignore=ignore_fn)
203187

204188
template_name = "execute_experiment.tpl"
205189
experiment_template_options = [

0 commit comments

Comments
 (0)