Skip to content

Instantly share code, notes, and snippets.

@tomviner
Created September 17, 2011 22:51
Show Gist options
  • Save tomviner/1224460 to your computer and use it in GitHub Desktop.
Save tomviner/1224460 to your computer and use it in GitHub Desktop.
VirtualEnvWrappers with Fabric
def once(s):
"command_prefixes is a list of prefixes"
if s not in env.command_prefixes:
return s
return 'true'
@contextlib.contextmanager
def mycd(dir):
with prefix(once('cd %s' % dir)):
yield
@contextlib.contextmanager
def vwrap():
with prefix(once('source /usr/local/bin/virtualenvwrapper.sh')):
yield
@contextlib.contextmanager
def workon(ve):
with vwrap():
with prefix(once('workon %s' %ve)):
yield
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment