Skip to content

Commit

Permalink
Add option to manually set extra apptainer bind points
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolai-vKuegelgen committed Oct 31, 2024
1 parent 2a79c27 commit 36ed378
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions stemcnv_check/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ def setup_argparse():
group_snake.add_argument('--no-cache', action='store_true',
help="Do not use a chache directory. The cache is used for workflow created metadata "
"(conda envs, singularity images, and VEP data). The default cache path is defined in the conifg file.")
group_snake.add_argument('--bind-points',
help="Additional bind points for apptainer containers, intended for expter users. "
"Use i.e. '/path' to make it availbale in apptainer, useful in case local directory "
"contains symlinks that won't resolve in the container.")

group_snake.add_argument('--target', '-t', default='complete',
choices=('complete', 'report', 'collate-summary', 'summary-tables', 'collate-cnv-calls',
Expand Down
8 changes: 6 additions & 2 deletions stemcnv_check/app/make_staticdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ def run_staticdata_workflow(args, array_name):
deployment_method=DeploymentMethod.parse_choices_set(['conda', 'apptainer']),
conda_prefix=cache_path,
apptainer_prefix=cache_path,
apptainer_args=make_apptainer_args(config, cache_path, not_existing_ok=True),
apptainer_args=make_apptainer_args(
config, cache_path, not_existing_ok=True, extra_bind_args=args.bind_points
),
),
)
.dag(
Expand Down Expand Up @@ -191,7 +193,9 @@ def run_staticdata_workflow(args, array_name):
deployment_method=DeploymentMethod.parse_choices_set(['conda', 'apptainer']),
conda_prefix=cache_path,
apptainer_prefix=cache_path,
apptainer_args=make_apptainer_args(config, cache_path, tmpdir=tmpdir, not_existing_ok=True),
apptainer_args=make_apptainer_args(
config, cache_path, tmpdir=tmpdir, not_existing_ok=True, extra_bind_args=args.bind_points
),
)
)
.dag(
Expand Down
2 changes: 1 addition & 1 deletion stemcnv_check/app/run_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def run_stemcnv_check_workflow(args):
"-s", str(importlib.resources.files(STEM_CNV_CHECK).joinpath('rules', 'StemCNV-check.smk')),
"--printshellcmds", "--rerun-incomplete",
"--sdm", "conda", "apptainer",
"--apptainer-args", make_apptainer_args(config, cache_path),
"--apptainer-args", make_apptainer_args(config, cache_path, extra_bind_args=args.bind_points),
#"--conda-frontend", args.conda_frontend,
]
if args.directory:
Expand Down
8 changes: 7 additions & 1 deletion stemcnv_check/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def rename_func(name): return name
return sample_tb.set_index('Sample_ID', drop=False)


def make_apptainer_args(config, cache_path, tmpdir=None, not_existing_ok=False):
def make_apptainer_args(config, cache_path, tmpdir=None, not_existing_ok=False, extra_bind_args=None):
"""Collect all outside filepaths that need to be bound inside container"""

bind_points = [
Expand Down Expand Up @@ -106,6 +106,12 @@ def make_apptainer_args(config, cache_path, tmpdir=None, not_existing_ok=False):

# Sort bind_points to make testing easier (loops over config_dict add them in a non-deterministic order)
bind_point_str = "-B " + ','.join(f"'{host}':'{cont}'" for host, cont in sorted(bind_points, key=lambda x: x[1]))
# allow additional arguments to be passed
if extra_bind_args:
if isinstance(extra_bind_args, str):
extra_bind_args = [extra_bind_args]
bind_point_str = bind_point_str + ',' + ','.join(list(extra_bind_args))

logging.debug("Binding points for apptainer: " + str(bind_point_str))

return bind_point_str
Expand Down
3 changes: 3 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ def get_expected(extra=[]):
expected = get_expected(expected_extra + ["'relative/bpm_manifest.bpm':'/outside/ExampleArray/bpm_manifest.bpm'"])
assert expected == helpers.make_apptainer_args(config, None)

# test with direct addition
assert expected+',/abcdef' == helpers.make_apptainer_args(config, None, extra_bind_args='/abcdef')

# test with cache_path & auto-creation of global paths
cache_path = '/path/to/cache'
config['global_settings'] = {
Expand Down

0 comments on commit 36ed378

Please sign in to comment.