diff --git a/artwork b/artwork index 3125a66f..0bd92148 160000 --- a/artwork +++ b/artwork @@ -1 +1 @@ -Subproject commit 3125a66f1fc95fff8576f9d315713df9f05e8b70 +Subproject commit 0bd92148d43f66d79a0bd238fdec654ea3cc7e4b diff --git a/scripts/singularity_cmd b/scripts/singularity_cmd index 90f0ebd7..9246727c 100755 --- a/scripts/singularity_cmd +++ b/scripts/singularity_cmd @@ -8,7 +8,7 @@ # - cleansed environment variables # while bind mounting (and starting from) current directory. # -# COPYRIGHT: Yaroslav Halchenko 2019 +# COPYRIGHT: Yaroslav Halchenko 2019-2023 # # LICENSE: MIT # @@ -31,8 +31,6 @@ # THE SOFTWARE. # -set -eu - function info() { : # echo -e "I: " "$@" >&2 } @@ -43,11 +41,21 @@ function info() { # function pass_git_config() { var="$1" - default="$2" # git config reads without locking, but could lock for writing # so we might need to try multiple times setting the value - value=$(git config "$var" || echo "$default") + set +e + value=$(git config "$var") + ret=$? + set -e + + # if variable is not defined at all + if [ "$ret" = 1 ] ; then + # and default was not provided - nothing for us to do + [ "$#" -ge 2 ] || return 0 + # otherwise, use that default + value="$2" + fi # shellcheck disable=SC2034 for attempt in {1..5}; do git config -f "$BHOME/.gitconfig" "$var" >/dev/null \ @@ -62,6 +70,13 @@ function readlink_f() { readlink -f "$1" 2> /dev/null || python -c 'import sys, os ; print(os.path.realpath(sys.argv[1]))' "$1" } +if [ "$#" = 0 ]; then + echo "Using as a library. Run with 'exec' or 'run' command and options." + exit 0 +fi + +set -eu + info "PWD=$PWD" thisfile=$(readlink_f "$0") @@ -78,7 +93,7 @@ if [ -n "${DATALAD_CONTAINER_NAME:-}" ]; then export APPTAINERENV_DATALAD_CONTAINER_NAME="$DATALAD_CONTAINER_NAME" fi -# fix non-writable matplotlib cache dir in apptainer https://github.com/ReproNim/containers/issues/97 +# fix non-writable matplotlib cache dir in apptainer https://github.com/ReproNim/containers/issues/97 export SINGULARITYENV_MPLCONFIGDIR=/tmp/mpl-config export APPTAINERENV_MPLCONFIGDIR=/tmp/mpl-config @@ -89,9 +104,9 @@ export APPTAINERENV_MPLCONFIGDIR=/tmp/mpl-config # (double-bound) directory. Shortening the name of the directory is one way # to fix the problem. See https://github.com/ReproNim/containers/issues/57 if [ "$(uname -s)" = Darwin ]; then - tmpdir=$(mktemp -d -t s) + tmpdir=$(mktemp -d -t s) else - tmpdir=$(mktemp -d -t singtmp.XXXXXX) + tmpdir=$(mktemp -d -t singtmp.XXXXXX) fi # To know what base would need to be mounted within docker @@ -103,6 +118,8 @@ trap 'rm -fr "$tmpdir" && info "removed temp dir $tmpdir"' exit pass_git_config "user.name" "ReproNim User" pass_git_config "user.email" "nobody@example.com" +# only if set - pass pidlock so we could operate on NFS mounts, like on rolando +pass_git_config "annex.pidlock" # Common arguments for the singularity run SARGS=( -e -B "$PWD" -H "$BHOME" --pwd "$PWD" "$@" ) diff --git a/scripts/tests/test_singularity_cmd.bats b/scripts/tests/test_singularity_cmd.bats index 419be83e..96aa1443 100755 --- a/scripts/tests/test_singularity_cmd.bats +++ b/scripts/tests/test_singularity_cmd.bats @@ -1,4 +1,6 @@ #!/usr/bin/env bats +#emacs: -*- mode: shell-script; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- +#ex: set sts=4 ts=4 sw=4 noet: # # This test uses the Bash Automated Testing System # See: https://github.com/bats-core/bats-core @@ -22,6 +24,7 @@ cd "$BATS_TEST_DIRNAME" git annex get "$arg_test_img" +# bats test_tags=docker @test "verifying arguments passed to singularity_cmd Docker shim" { pull_singularity_shim @@ -41,22 +44,26 @@ git annex get "$arg_test_img" } +# bats test_tags=docker @test "verifying ability to singularity exec under /tmp subdir" { skip_if_travis_osx "skipping Singularity directory test on Travis OSX" check_subdir "$(_mktemp_dir_under /tmp)" } +# bats test_tags=docker @test "verifying ability to singularity exec under /tmp subdir (explicit use of docker)" { skip_if_travis_osx "skipping Singularity directory test on Travis OSX" export REPRONIM_USE_DOCKER=1 check_subdir "$(_mktemp_dir_under /tmp)" } +# bats test_tags=docker @test "verifying ability to singularity exec under $HOME subdir" { skip_if_travis_osx "skipping Singularity directory test on Travis OSX" check_subdir "$(_mktemp_dir_under $HOME)" } +# bats test_tags=docker @test "verifying ability to singularity exec under $HOME subdir (explicit use of docker)" { skip_if_travis_osx "skipping Singularity directory test on Travis OSX" export REPRONIM_USE_DOCKER=1