fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fab-user] Generic prefix context manager?


From: Jorge Vargas
Subject: Re: [Fab-user] Generic prefix context manager?
Date: Tue, 7 Jul 2009 22:51:24 -0400

On Tue, Jul 7, 2009 at 5:37 PM, Matthew Wilson<address@hidden> wrote:
> Since I use a virtualenv on my servers, before I run "python zzz.py",
> I need to activate the virtualenv.  So I'm doing this right now:
>
>    run("source /home/matt/virtualenvs/foo/bin/activate && python zzz.py")
>
> I read through how fabric.context_managers.cd works.  It seems to set
> a key in the env dictionary.  Then in fabric.operations.run, that key
> is interpolated into the string to be sent as a command.
>
> It might be nice to have something like this:
>
> with context_managers.prefixes(['source
> /home/matt/virtualenv/foo/bin/activate', 'cd /home/matt/projects']):
>    run('python zzz.py')
>
> Thoughts?  I would have to change run to look in env.prefixes and glue
> all that junk in.
>
> Is there some much simpler way of activating a virtualenv before I run
> each one of my commands?
>
First of all let me tell you I love the idea. In fact I think fabric
should be totally aware of venvs and it should be even simpler
something like

with virtualenv('/path/to/venv/'):
    cmd('pip install package')

I haven't had time to code it. That said in the case of the venv there
is one little trick almost no one knows about. if you use the full
path to the venv's python executable you don't need to activate it. so
I do the following (seudo-code).

env.python = "/home/matt/virtualenvs/foo/bin/python"
run("%(python)s zzz.py" % env)

hope that helps.

> Matt
>
>
> --
> Matthew Wilson
> address@hidden
> http://tplus1.com
>
>
> _______________________________________________
> Fab-user mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/fab-user
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]