2

I just can't figure out why this is happening...

in my fabric file I have this...

def func():
    local("source ../venv/bin/activate")

It is returning 127 on the source command and I am not sure why, when i try to run source in my terminal manually it works. When I try a different command in fabric, like...

local("echo 'foo'")

it also works. Why would source be causing problems? I can't see any reason why this would be happening.

Joff
  • 11,247
  • 16
  • 60
  • 103

1 Answers1

4

source is unknown by sh. If you want to run a command in the context of a virtual environment, use Fabric's context managers and run the activate binary without source. I've adapted from this answer.

from __future__ import with_statement
from fabric.api import *
from contextlib import contextmanager as _contextmanager

env.activate = '. ./.env/bin/activate'

@_contextmanager
def virtualenv():
    with prefix(env.activate):
        yield

def deploy():
    with virtualenv():
        local('echo hello world!')
Community
  • 1
  • 1
jumbopap
  • 3,969
  • 5
  • 27
  • 47