Skip to content

Commit

Permalink
Merge pull request #107 from ReproNim/enh-pidlock
Browse files Browse the repository at this point in the history
ENH: make pass_git_config to allow to have no default + pass annex.pidlock if defined
  • Loading branch information
yarikoptic authored Dec 15, 2023
2 parents d817fbc + c0d30c9 commit 633c9f3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
33 changes: 25 additions & 8 deletions scripts/singularity_cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand All @@ -31,8 +31,6 @@
# THE SOFTWARE.
#

set -eu

function info() {
: # echo -e "I: " "$@" >&2
}
Expand All @@ -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 \
Expand All @@ -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")
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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" "[email protected]"
# 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" "$@" )
Expand Down
7 changes: 7 additions & 0 deletions scripts/tests/test_singularity_cmd.bats
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 633c9f3

Please sign in to comment.