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

Implement autoenv unload #30

Closed
turicas opened this issue Aug 11, 2012 · 23 comments
Closed

Implement autoenv unload #30

turicas opened this issue Aug 11, 2012 · 23 comments
Milestone

Comments

@turicas
Copy link

turicas commented Aug 11, 2012

In general I use autoenv to automatically activate my Python virtualenvs. It works pretty nice, but I miss a feature to automatically deactivate the virtualenv. It should deactivate the virtualenv if I change the directory to a path that is not inside the path which enabled the virtualenv. For example:

mkdir spam
echo "workon spam" > spam/.env
echo "deactivate" > spam/.env-unload
cd spam # run `source .env`, activating virtualenv 'spam'

# working in this directory...
mkdir eggs
cd eggs
touch ham
cd ..
echo "finished" > README.markdown
# finished working.

cd .. # runs `source .env-unload`, deactivating virtualenv

Another approach is to define bash functions inside .env (like autoenv_load and autoenv_unload) and call these functions instead of just sourcing .env/.env-unload.

@kennethreitz
Copy link
Contributor

Yeah, I've considered this for a while, but decided it's out of scope (for now).

Thanks for the suggestions though, I'll definitely consider them in the future.

@kennethreitz
Copy link
Contributor

I'll leave this issue open for discussion.

@kennethreitz kennethreitz reopened this Aug 14, 2012
@honzajavorek
Copy link
Contributor

I like the idea.

@JeffPaine
Copy link

+1

@Bankq
Copy link

Bankq commented Nov 17, 2012

I'd love if I can put it in .env with separate parts. Like

[load]
...
...
...

[unload]
...
...

@bahoo
Copy link

bahoo commented Nov 24, 2012

+1. I do see how it qualifies as out of scope, but I'd use an add-on (or completely separate) tool for handling unloading, if it existed.

@kazagistar
Copy link

Simple workaround: place this .env somewhere high in your directory tree (possibly in the root)

if [ -n "$VIRTUAL_ENV" ] ; then
    deactivate
fi

I am sure there are some horrible side effects I am not taking into consideration, but it works for me. <_<

@laithalissa
Copy link

I do hope you change you mind about this issue, but cool project anyway.

@bryanjos
Copy link

Awesome project. I would love to see this one feature added as well.

@blueyed
Copy link
Contributor

blueyed commented Sep 30, 2014

FYI: smartcd supports this.

@wangyandongnx
Copy link

+1 for the unload feature.

@msjaiswal
Copy link

+1

@blueyed
Copy link
Contributor

blueyed commented Oct 20, 2015

FYI: zsh-autoenv also supports this, either through a separate or the same file (where you can look at a variable to see which event it is).

@unforswearing
Copy link

+1

2 similar comments
@kevinpostal
Copy link

+1

@Atry
Copy link

Atry commented May 5, 2016

+1

@dasJ dasJ added this to the 0.3.0 milestone Aug 6, 2016
@luizs81
Copy link

luizs81 commented Aug 9, 2016

+1

@dasJ dasJ mentioned this issue Aug 26, 2016
5 tasks
@dasJ dasJ modified the milestones: 0.4.0, 0.3.0 Sep 7, 2016
@aliavni
Copy link

aliavni commented Dec 26, 2016

+1

@SashaOv
Copy link

SashaOv commented Dec 26, 2016

I would suggest documenting the workaround by @kazagistar above somewhere in README. It could be useful for many people

@yuanbohan
Copy link

+1

@wddabc
Copy link

wddabc commented Feb 12, 2018

Hi, I'm running into the same issue and found the suggestion by @kazagistar to be very useful. Thanks.

One minor issue of that snippet is it will always run whenever I enter the subfolders, which will unnecessarily deactivate and reactivate the env.
My two cents on the improvement:

recent_env=$(pwd)
while [ "${recent_env}" != "$HOME" ];do
    if [ -f ${recent_env}/.env ];then
        return
    fi
    recent_env=$(dirname "${recent_env}")
done
source deactivate

This will make sure the source deactivate runs only when there are no other .env files along the path except the one on the $HOME.

@kennethreitz
Copy link
Contributor

I recommend just using direnv for this functionality.

@hyperupcall
Copy link
Owner

hyperupcall commented Oct 14, 2023

Closed as this was implemented in v0.3.0. Sorry for the pings - I know this is an older thread. If you are still using autoenv, free make a new issue for bug reports / unexpected functionality.

Repository owner locked as resolved and limited conversation to collaborators Oct 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests