Skip to content

Commit

Permalink
refactor: write get_singularity_cache_dir()
Browse files Browse the repository at this point in the history
same behavior as before, just moved this from orchestrate() to its own function for the GUI to use too
  • Loading branch information
kelly-sovacool committed Aug 6, 2024
1 parent 36c52e0 commit adf6be9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/renee/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ def parsed_arguments(name, description):
type=lambda option: os.path.abspath(os.path.expanduser(option)),
required=False,
help=argparse.SUPPRESS,
default=get_sif_cache_dir(),
default=get_sif_cache_dir(hpc=get_hpcname()),
)

# Create NIDAP output folder
Expand Down
12 changes: 10 additions & 2 deletions src/renee/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
import os
import sys

from .util import get_hpcname

def get_singularity_cachedir(output_dir, cache_dir=None):
"""Returns the singularity cache directory.
If no user-provided cache directory is provided,
the default singularity cache is in the output directory.
"""
if not cache_dir:
cache_dir = os.path.join(output_dir, ".singularity")
return cache_dir


def get_sif_cache_dir(hpc=get_hpcname()):
def get_sif_cache_dir(hpc=None):
sif_dir = None
if hpc == "biowulf":
sif_dir = "/data/CCBR_Pipeliner/SIFS"
Expand Down
8 changes: 6 additions & 2 deletions src/renee/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
get_shared_resources_dir,
renee_base,
get_version,
get_singularity_cachedir,
get_hpcname,
)
from .cache import get_sif_cache_dir
from .run import run_in_context
Expand Down Expand Up @@ -176,8 +178,10 @@ def launch_gui(sub_args, debug=True):
mode="slurm",
runmode="run",
dry_run=True,
sif_cache=get_sif_cache_dir(),
singularity_cache=os.environ["SINGULARITY_CACHEDIR"],
sif_cache=get_sif_cache_dir(hpc=get_hpcname()),
singularity_cache=get_singularity_cachedir(
output_dir, os.environ.get("SINGULARITY_CACHEDIR", None)
),
tmp_dir=get_tmp_dir(None, output_dir),
shared_resources=get_shared_resources_dir(None, output_dir),
star_2_pass_basic=False,
Expand Down
9 changes: 3 additions & 6 deletions src/renee/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import shutil
import sys
import warnings
from .cache import get_singularity_cachedir


def renee_base(rel_path=""):
Expand Down Expand Up @@ -224,13 +225,9 @@ def orchestrate(
# to output directory
my_env = {}
my_env.update(os.environ)
cache = os.path.join(outdir, ".singularity")
my_env["SINGULARITY_CACHEDIR"] = cache

if alt_cache:
# Override the pipeline's default cache location
my_env["SINGULARITY_CACHEDIR"] = alt_cache
cache = alt_cache
cache = get_singularity_cachedir(output_dir=outdir, cache_dir=alt_cache)
my_env["SINGULARITY_CACHEDIR"] = cache

if additional_bind_paths:
# Add Bind PATHs for outdir and tmp dir
Expand Down
11 changes: 10 additions & 1 deletion tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os.path
import subprocess

from renee.src.renee.cache import get_sif_cache_dir
from renee.src.renee.cache import get_sif_cache_dir, get_singularity_cachedir

renee_run = (
"./bin/renee run "
Expand Down Expand Up @@ -56,3 +56,12 @@ def test_get_sif_cache_dir():
]
errors = [assertion for assertion in assertions if not eval(assertion)]
assert not errors, "errors occurred:\n{}".format("\n".join(errors))


def test_get_singularity_cachedir():
assertions = [
"get_singularity_cachedir('outdir') == 'outdir/.singularity'",
"get_singularity_cachedir('outdir', 'cache') == 'cache'",
]
errors = [assertion for assertion in assertions if not eval(assertion)]
assert not errors, "errors occurred:\n{}".format("\n".join(errors))

0 comments on commit adf6be9

Please sign in to comment.