precimed / gsa-mixer

GNU General Public License v3.0
8 stars 2 forks source link

MIXER_PY use of PWD is confusing #9

Closed ofrei closed 1 day ago

ofrei commented 6 days ago

Mounting $PWD:/home is a handy trick that allows user to use relative path within current working directory while using containers . This works for both docker and singularity. This is an example of how to invoke mixer.py script:

# docker
export MIXER_PY="sudo docker run -v ${PWD}:/home -w /home ghcr.io/precimed/gsa-mixer:latest python /tools/mixer/precimed/mixer.py"

# singularity
export MIXER_PY="singularity exec --home $PWD:/home ${MIXER_SIF} python /tools/mixer/precimed/mixer.py"

An issue with this command is that $PWD is evaluate when user defines MIXER_PY. Later user may change working directory, but ${MIXER_PY} will still mount an old folde.

Is there a way of changing the above export commands so that $PWD is evaluated when we invoke $MIXER_PY ?

ofrei commented 4 days ago

Using functions might be the way to go:

funcPWD() { echo "$PWD"; }
export PYTHON="singularity exec --home funcPWD:/home $BIND ${MIXER_SIF} python"
espenhgn commented 4 days ago

I think there's no need to replace the system "pwd" function; this ought to work:

export PYTHON="singularity exec --home pwd:/home $BIND ${MIXER_SIF} python"
ofrei commented 4 days ago

@espenhgn thanks!! This works very well. I've played further with functions, also tried with eval, and also found that there is a pwd command (https://askubuntu.com/questions/476572/difference-in-use-between-pwd-and-pwd), but still didn't realise that the fix is so nice and simple.