Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stash/unstash of $PATH doesn't remove path correctly #45

Closed
dmitry-kabanov opened this issue May 22, 2016 · 4 comments
Closed

Stash/unstash of $PATH doesn't remove path correctly #45

dmitry-kabanov opened this issue May 22, 2016 · 4 comments

Comments

@dmitry-kabanov
Copy link

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

@blueyed
Copy link
Collaborator

blueyed commented May 22, 2016

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?!

@dmitry-kabanov
Copy link
Author

@blueyed What do you mean by "a failing test"? Something simpler, which can be run by others?

@blueyed
Copy link
Collaborator

blueyed commented May 28, 2016

@dmitry-kabanov
There's a test suite - please look into tests/*.t.

blueyed added a commit to blueyed/zsh-autoenv that referenced this issue Aug 19, 2017
blueyed added a commit to blueyed/zsh-autoenv that referenced this issue Aug 19, 2017
@blueyed
Copy link
Collaborator

blueyed commented Aug 19, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants