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

plugin: virtualenvwrapper doesn't cleanup properly after being disabled/reconfigured #12852

Open
mvk opened this issue Dec 18, 2024 · 1 comment
Assignees
Labels
Area: plugin Issue or PR related to a plugin Status: needs repro Bug that doesn't have a reproduction

Comments

@mvk
Copy link

mvk commented Dec 18, 2024

Describe the bug

hello.
virtualenvwrapper plugin has this feature where it installs a zsh chpwd hook function named workon_cwd.
It has a configurable env variable for people like me: DISABLE_VENV_CD.
However if you define export DISABLE_VENV_CD=1 and then source the plugin, it will leave previously defined function intact. :)

basically, when being sourced the plugin needs to check whether it needs the function and whether it is already present.

Steps to reproduce

Assuming you have oh-my-zsh installed at default location.

I. Enable the plugin virtualenvwrapper and see its operation:

$ omz plugin enable virtualenvwrapper
$ source ~/.zshrc
$ pushd "${PWD}"
$ cd /tmp
$ mkdir -p kuku
$ cd kuku
$ python3 -m venv .venv
$ cd ../kuku
(.venv) $ cd ../
$ popd

so far as expected.

II. Disable cd handling:

$ export DISABLE_VENV_CD=1
$ source ~/.zshrc
$ cd /tmp/kuku
(.venv) $ 

i.e. the hook is still working :)

Expected behavior

I expected at II last line I would not get any chpw hooks.

Screenshots and recordings

don't forget to clean up:

rm -fr /tmp/kuku

OS / Linux distribution

Mac OS 15.2

Zsh version

5.9

Terminal emulator

iTerm2

If using WSL on Windows, which version of WSL

None

Additional context

workarounds:

  1. use omz reload
  2. manually clean up

FIX:

add a test for DISABLE_VENV_CD undef or 0 and ensure that the hook is removed fromchpwd_functions`:

if [[ "${DISABLE_VENV_CD}" -eq 1 ]]; then
  autoload -U add-zsh-hook
  add-zsh-hook -d chpwd workon_cwd
fi

I know this is a rare use case and not a critical one.

@ohmyzsh ohmyzsh bot added this to Main project Dec 18, 2024
@github-project-automation github-project-automation bot moved this to Backlog in Main project Dec 18, 2024
@mcornella
Copy link
Member

Hi @mvk, thanks for the report.

The expectation we have in terms of plugin settings is that they are only read on plugin load, except in very few plugins.

To properly load a plugin, we need to reload the zsh session. Sourcing the zshrc file is not the way to do it, as there are many side effects.

Therefore, to do what you want, you need to:

  1. Set the variable setting in your .zshrc file (before OMZ is sourced), to make it persistent.
  2. Reload the zsh session: omz reload.

Please confirm that this works. If so, there is no need for the Pull Request.

Thanks!

@mcornella mcornella self-assigned this Dec 18, 2024
@mcornella mcornella added Area: plugin Issue or PR related to a plugin Status: needs repro Bug that doesn't have a reproduction labels Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: plugin Issue or PR related to a plugin Status: needs repro Bug that doesn't have a reproduction
Projects
Status: Backlog
Development

No branches or pull requests

2 participants