Stash/unstash of $PATH doesn't remove path correctly
dmitry-kabanov opened this issue · 4 comments
I have the following bug.
I try to stash two paths to $PATH. I will call them below like this:
code/bin
is my custom path (in the log below it is/home/kabanod/job/ffm/shock-attached/code/bin
)python/bin
is path to python interpreter (in the log below it is/home/kabanod/apps/python/3.4/bin
)
What do I do? In .autoenv.zsh
I prepend $PATH
with the path to the python/bin
directory using Environment Modules command (module load python/3.4
) and then prepend $PATH with code/bin
path (using stash
command). In .autoenv_leave.zsh
I unstash $PATH
from my code/bin
path and then unload python/bin
path.
Expected behavior. Both paths are removed from $PATH
.
What happens. python/bin
path is removed from $PATH
, however, an explicit call to stash
doesn't remove code/bin
path from $PATH
.
I also tried to use autostash
functionality with no success.
This is the full log:
kabanod@kw12608 ~/job/ffm/shock-attached
% echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
kabanod@kw12608 ~/job/ffm/shock-attached
% cd good-experiments
Attempting to load unauthorized env file!
-rw-r--r-- 1 kabanod kw-users 260 May 22 18:21 /home/kabanod/job/ffm/shock-attached/good-experiments/.autoenv.zsh
**********************************************
echo "Begin '.autoenv.zsh': " $PATH
module load python/3.4
echo "After 'module load python/3.4': " $PATH
code_path=$HOME/job/ffm/shock-attached/code
autostash PYTHONPATH=$code_path:
stash PATH=$code_path/bin:$PATH
echo "After stash: " $PATH
unset code_path
**********************************************
Would you like to authorize it? (type 'yes') yes
Begin '.autoenv.zsh': /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
After 'module load python/3.4': /home/kabanod/apps/python/3.4/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
After stash: /home/kabanod/job/ffm/shock-attached/code/bin:/home/kabanod/apps/python/3.4/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
kabanod@kw12608 ~/job/ffm/shock-attached/good-experiments
± % cd ..
Attempting to load unauthorized env file!
-rw-r--r-- 1 kabanod kw-users 157 May 22 18:21 /home/kabanod/job/ffm/shock-attached/good-experiments/.autoenv_leave.zsh
**********************************************
echo "Begin '.autoenv_leave.zsh': " $PATH
unstash PATH
echo "After unstash: " $PATH
module unload python/3.4
echo "After 'module unload python/3.4': " $PATH
**********************************************
Would you like to authorize it? (type 'yes') yes
Begin '.autoenv_leave.zsh': /home/kabanod/job/ffm/shock-attached/code/bin:/home/kabanod/apps/python/3.4/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
After unstash: /home/kabanod/job/ffm/shock-attached/code/bin:/home/kabanod/apps/python/3.4/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
After 'module unload python/3.4': /home/kabanod/job/ffm/shock-attached/code/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
kabanod@kw12608 ~/job/ffm/shock-attached
% echo $PATH
/home/kabanod/job/ffm/shock-attached/code/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
It would be great/helpful if you could create a failing test for that (in a PR).
But (from only skimming it) it sounds like stashing only supports one level?!
@blueyed What do you mean by "a failing test"? Something simpler, which can be run by others?
@dmitry-kabanov
There's a test suite - please look into tests/*.t
.
The problem is that the current dir during the "leave" event is the new dir, and therefore the "unstash" does not find the expected old value (which is based on the directory).
(see 986a760)
#72 should fix this, by setting varstash_dir
when sourcing the "leave" file.
However, using autostash
/ autounstash
should have worked before already.