Created
March 28, 2011 15:23
-
-
Save kennethreitz/890647 to your computer and use it in GitHub Desktop.
Automatic de/activating virtualenvs!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export WORKON_HOME=$HOME/.virtualenvs | |
source /usr/local/share/python//virtualenvwrapper.sh | |
export VIRTUALENV_USE_DISTRIBUTE="1" | |
function cd(){ | |
builtin cd "$@" | |
$(/Users/kreitz/.oh-my-zsh/tools/workon.py) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import os | |
import sys | |
def find_above(*names): | |
"""Attempt to locate a .workon file by searching parent dirs.""" | |
path = '.' | |
while os.path.split(os.path.abspath(path))[1]: | |
for name in names: | |
joined = os.path.join(path, name) | |
if os.path.exists(joined): | |
return os.path.abspath(joined) | |
path = os.path.join('..', path) | |
if __name__ == '__main__': | |
wo_file = find_above('.workon') | |
if wo_file and not 'VIRTUAL_ENV' in os.environ.keys(): | |
with open(wo_file) as f: | |
print('source {0}/bin/activate'.format(f.read())) | |
elif not wo_file and 'VIRTUAL_ENV' in os.environ.keys(): | |
print('deactivate') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment