Lanchd + virtualenv

View: New views
9 Messages — Rating Filter:   Alert me  

Lanchd + virtualenv

by grossetti :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello everyone,

I would like to create a Launchd plist entry to start a virtualenv and
run a python project. I created my plist, but I'm not sure how to get it
to activate the virtualenv and run the program. I thought that maybe I
could create two <dict> emtries :

        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
                "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
        <plist version="1.0">
        <dict>
                <key>Label</key>
                <string>com.example.virtualenv</string>
                <key>Program</key>
                <string>source</string>
                <key>ProgramArguments</key>
                <array>
                        <string>/path/to/myvirtualenv/bin/activate</string>
                </array>
                <key>RunAtLoad</key>
                <true/>
        </dict>
        <dict>
                <key>Label</key>
                <string>com.example.app</string>
                <key>Program</key>
                <string>python</string>
                <key>ProgramArguments</key>
                <array>
                        <string>/path/to/myproj/launcher.py</string>
                        <string>start</string>
                </array>
                <key>RunAtLoad</key>
                <true/>
        </dict>
        </plist>


but I'm not sure I can do that, and I have 2 programs to run for my
project, so would I create 3<dict> entries like so :

        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
                "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
        <plist version="1.0">
<!-- The virtualenv -->
        <dict>
                <key>Label</key>
                <string>com.example.virtualenv</string>
                <key>Program</key>
                <string>source</string>
                <key>ProgramArguments</key>
                <array>
                        <string>/path/to/myvirtualenv/bin/activate</string>
                </array>
                <key>RunAtLoad</key>
                <true/>
        </dict>
<!-- My app 1 -->
        <dict>
                <key>Label</key>
                <string>com.example.app1</string>
                <key>Program</key>
                <string>python</string>
                <key>ProgramArguments</key>
                <array>
                        <string>/path/to/myproj/launcher.py</string>
                        <string>app1</string>
                        <string>start</string>
                </array>
                <key>RunAtLoad</key>
                <true/>
        </dict>
<!-- My app 2 -->
        <dict>
                <key>Label</key>
                <string>com.example.app2</string>
                <key>Program</key>
                <string>python</string>
                <key>ProgramArguments</key>
                <array>
                        <string>/path/to/myproj/launcher.py</string>
                        <string>app2</string>
                        <string>start</string>
                </array>
                <key>RunAtLoad</key>
                <true/>
        </dict>
        </plist>

Or is there a better/another way to do this?
_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@...
http://mail.python.org/mailman/listinfo/pythonmac-sig

Re: Lanchd + virtualenv

by Aahz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Sep 25, 2009, Gabriel Rossetti wrote:
>
> I would like to create a Launchd plist entry to start a virtualenv and  
> run a python project. I created my plist, but I'm not sure how to get it  
> to activate the virtualenv and run the program. I thought that maybe I  
> could create two <dict> emtries :

Why not just write a single wrapper script that creates the virtualenv
and then runs the main program?  Python rocks!
--
Aahz (aahz@...)           <*>         http://www.pythoncraft.com/

gfarber: Thank God, or the belief system of your choice.
pddb: Does human perversity count as a belief system?
_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@...
http://mail.python.org/mailman/listinfo/pythonmac-sig

Re: Lanchd + virtualenv

by Orestis Markou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

No need for a wrapper script. In recent versions of virtualenv, you  
can do this:

     activate_this = 'path/to/virtualenv/bin/activate_this.py'
     if os.path.exists(activate_this):
         execfile(activate_this, dict(__file__=activate_this))

On 25 Σεπ 2009, at 3:56 μ.μ., Gabriel Rossetti wrote:

> Hello everyone,
>
> I would like to create a Launchd plist entry to start a virtualenv  
> and run a python project. I created my plist, but I'm not sure how  
> to get it to activate the virtualenv and run the program. I thought  
> that maybe I could create two <dict> emtries :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
> "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
> <plist version="1.0">
> <dict>
> <key>Label</key>
> <string>com.example.virtualenv</string>
> <key>Program</key>
> <string>source</string>
> <key>ProgramArguments</key>
> <array>
> <string>/path/to/myvirtualenv/bin/activate</string>
> </array>
> <key>RunAtLoad</key>
> <true/>
> </dict>
> <dict>
> <key>Label</key>
> <string>com.example.app</string>
> <key>Program</key>
> <string>python</string>
> <key>ProgramArguments</key>
> <array>
> <string>/path/to/myproj/launcher.py</string>
> <string>start</string>
> </array>
> <key>RunAtLoad</key>
> <true/>
> </dict>
> </plist>
>
>
> but I'm not sure I can do that, and I have 2 programs to run for my  
> project, so would I create 3<dict> entries like so :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
> "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
> <plist version="1.0">
> <!-- The virtualenv -->
> <dict>
> <key>Label</key>
> <string>com.example.virtualenv</string>
> <key>Program</key>
> <string>source</string>
> <key>ProgramArguments</key>
> <array>
> <string>/path/to/myvirtualenv/bin/activate</string>
> </array>
> <key>RunAtLoad</key>
> <true/>
> </dict>
> <!-- My app 1 -->
> <dict>
> <key>Label</key>
> <string>com.example.app1</string>
> <key>Program</key>
> <string>python</string>
> <key>ProgramArguments</key>
> <array>
> <string>/path/to/myproj/launcher.py</string>
> <string>app1</string>
> <string>start</string>
> </array>
> <key>RunAtLoad</key>
> <true/>
> </dict>
> <!-- My app 2 -->
> <dict>
> <key>Label</key>
> <string>com.example.app2</string>
> <key>Program</key>
> <string>python</string>
> <key>ProgramArguments</key>
> <array>
> <string>/path/to/myproj/launcher.py</string>
> <string>app2</string>
> <string>start</string>
> </array>
> <key>RunAtLoad</key>
> <true/>
> </dict>
> </plist>
>
> Or is there a better/another way to do this?
> _______________________________________________
> Pythonmac-SIG maillist  -  Pythonmac-SIG@...
> http://mail.python.org/mailman/listinfo/pythonmac-sig

_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@...
http://mail.python.org/mailman/listinfo/pythonmac-sig

Parent Message unknown Re: Lanchd + virtualenv

by grossetti :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
How about running the python exec directly from the virtual env :

/Users/me/Desktop/virtual_python_root/bin/python
Python 2.5.1 (r251:54863, Jun 17 2009, 20:37:34)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> wx.__path__
['/Users/me/Desktop/virtual_python_root/lib/python2.5/site-packages/wx-2.8-mac-unicode/wx']

it seams work work correctly (correct me if I'm wrong). I the wrote my plist like so :

<?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
        <plist version="1.0">
        <dict>
                <key>StandardOutPath</key>
                <string>test.log</string>
                <key>StandardErrorPath</key>
                <string>test-err.log</string>
                <key>EnvironmentVariables</key>
                <dict>
                        <key>PYTHONPATH</key>
                        <string>/Users/me/Desktop/virtual_python_root/lib/python2.5/site-packages:/Users/me/Desktop/myproj</string>
                        <string>DYLD_LIBRARY_PATH</string>
                        <string>/Users/me/Desktop/virtual_python_root/wx/2.8/lib</string>
                </dict>
                <key>KeepAlive</key>
                <dict>
                        <key>SuccessfulExit</key>
                        <false/>
                </dict>
                <key>Label</key>
                <string>com.test.virtualenv</string>
                <key>Program</key>
                        <string>/Users/me/Desktop/virtual_python_root/bin/python</string>
                <key>ProgramArguments</key>
                <array>
                        <string>python.virtualenv</string>
                        <string>./launcher.py</string>
                        <string>app1</string>
                </array>
                 <key>WorkingDirectory</key>
                 <string>/Users/me/Desktop/Arimaz-Trunk/src</string>
        </dict>
        </plist>

and again it seams to work (correct me again if I messed up somewhere).

What is the advantage of using your method?

Gabriel


On Fri 25/09/09 17:01 , "Orestis Markou" orestis@... sent:
No need for a wrapper script. In recent versions of virtualenv, you
can do this:

activate_this = 'path/to/virtualenv/bin/activate_this.py'
if os.path.exists(activate_this):
execfile(activate_this, dict(__file__=activate_this))

On 25 Σεπ 2009, at 3:56 μ.μ., Gabriel Rossetti wrote:

> Hello everyone,
>
> I would like to create a Launchd plist entry to start a virtualenv
> and run a python project. I created my plist, but I'm not sure how
> to get it to activate the virtualenv and run the program. I thought
> that maybe I could create two emtries :
>
>
>
> "http://www.apple.com/DTDs/PropertyList-1.0.dtd%26quot%3B%26gt">http://www.apple.com/DTDs/PropertyList-1.0.dtd">;
>
>
> Label
> com.example.virtualenv
> Program
> source
> ProgramArguments
>
> /path/to/myvirtualenv/bin/activate
>
> RunAtLoad
>
>
>
> Label
> com.example.app
> Program
> python
> ProgramArguments
>
> /path/to/myproj/launcher.py
> start
>
> RunAtLoad
>
>
>
>
>
> but I'm not sure I can do that, and I have 2 programs to run for my
> project, so would I create 3 entries like so :
>
>
>
> "http://www.apple.com/DTDs/PropertyList-1.0.dtd%26quot%3B%26gt">http://www.apple.com/DTDs/PropertyList-1.0.dtd">;
>
>
>
> Label
> com.example.virtualenv
> Program
> source
> ProgramArguments
>
> /path/to/myvirtualenv/bin/activate
>
> RunAtLoad
>
>
>
>
> Label
> com.example.app1
> Program
> python
> ProgramArguments
>
> /path/to/myproj/launcher.py
> app1
> start
>
> RunAtLoad
>
>
>
>
> Label
> com.example.app2
> Program
> python
> ProgramArguments
>
> /path/to/myproj/launcher.py
> app2
> start
>
> RunAtLoad
>
>
>
>
> Or is there a better/another way to do this?
> _______________________________________________
> Pythonmac-SIG maillist - Pythonmac-SIG@...
> http://mail.python.org/mailman/listinfo/pythonmac-sig">http://mail.python.org/mailman/listinfo/pythonmac-sig



_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@...
http://mail.python.org/mailman/listinfo/pythonmac-sig

Re: Lanchd + virtualenv

by Orestis Markou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 25 Σεπ 2009, at 6:31 μ.μ., gabriel.rossetti@... wrote:

> How about running the python exec directly from the virtual env :
>
> and again it seams to work (correct me again if I messed up  
> somewhere).
>
> What is the advantage of using your method?

None in particular, apart from the fact that a python script can be  
more flexible in deciding whether to activate a virtualenv or not, or  
even which virtualenv. If you are certain that the virtualenv will  
always be at the same place, then hardcoding it into the .plist is fine.

In my case, this snippet appears in a pyobjc app, where I don't have a  
lot of control on which python is used (it's complicated).

Orestis

>
> Gabriel
>
>
> On Fri 25/09/09 17:01 , "Orestis Markou" orestis@... sent:
> No need for a wrapper script. In recent versions of virtualenv, you
> can do this:
>
> activate_this = 'path/to/virtualenv/bin/activate_this.py'
> if os.path.exists(activate_this):
> execfile(activate_this, dict(__file__=activate_this))
>
> On 25 Σεπ 2009, at 3:56 μ.μ., Gabriel Rossetti wrote:
>
> > Hello everyone,
> >
> > I would like to create a Launchd plist entry to start a virtualenv
> > and run a python project. I created my plist, but I'm not sure how
> > to get it to activate the virtualenv and run the program. I thought
> > that maybe I could create two emtries :
> >
> >
> >
> > "http://www.apple.com/DTDs/PropertyList-1.0.dtd%26quot%3B 
> %26gt">http://www.apple.com/DTDs/PropertyList-1.0.dtd">;
> >
> >
> > Label
> > com.example.virtualenv
> > Program
> > source
> > ProgramArguments
> >
> > /path/to/myvirtualenv/bin/activate
> >
> > RunAtLoad
> >
> >
> >
> > Label
> > com.example.app
> > Program
> > python
> > ProgramArguments
> >
> > /path/to/myproj/launcher.py
> > start
> >
> > RunAtLoad
> >
> >
> >
> >
> >
> > but I'm not sure I can do that, and I have 2 programs to run for my
> > project, so would I create 3 entries like so :
> >
> >
> >
> > "http://www.apple.com/DTDs/PropertyList-1.0.dtd%26quot%3B 
> %26gt">http://www.apple.com/DTDs/PropertyList-1.0.dtd">;
> >
> >
> >
> > Label
> > com.example.virtualenv
> > Program
> > source
> > ProgramArguments
> >
> > /path/to/myvirtualenv/bin/activate
> >
> > RunAtLoad
> >
> >
> >
> >
> > Label
> > com.example.app1
> > Program
> > python
> > ProgramArguments
> >
> > /path/to/myproj/launcher.py
> > app1
> > start
> >
> > RunAtLoad
> >
> >
> >
> >
> > Label
> > com.example.app2
> > Program
> > python
> > ProgramArguments
> >
> > /path/to/myproj/launcher.py
> > app2
> > start
> >
> > RunAtLoad
> >
> >
> >
> >
> > Or is there a better/another way to do this?
> > _______________________________________________
> > Pythonmac-SIG maillist - Pythonmac-SIG@...
> > http://mail.python.org/mailman/listinfo/pythonmac-sig">http://
> mail.python.org/mailman/listinfo/pythonmac-sig
>
>

_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@...
http://mail.python.org/mailman/listinfo/pythonmac-sig

Re: Lanchd + virtualenv

by grossetti :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Orestis Markou wrote:

>
> On 25 Σεπ 2009, at 6:31 μ.μ., gabriel.rossetti@... wrote:
>
>> How about running the python exec directly from the virtual env :
>>
>> and again it seams to work (correct me again if I messed up somewhere).
>>
>> What is the advantage of using your method?
>
> None in particular, apart from the fact that a python script can be
> more flexible in deciding whether to activate a virtualenv or not, or
> even which virtualenv. If you are certain that the virtualenv will
> always be at the same place, then hardcoding it into the .plist is fine.
>
> In my case, this snippet appears in a pyobjc app, where I don't have a
> lot of control on which python is used (it's complicated).
>
> Orestis

Ok, in my case I control everything so I'll hardcode it. I'll keep your
msg in a corner as I may one day need it, thank you for the explanation
and help.

>
>>
>> Gabriel
>>
>>
>> On Fri 25/09/09 17:01 , "Orestis Markou" orestis@... sent:
>> No need for a wrapper script. In recent versions of virtualenv, you
>> can do this:
>>
>> activate_this = 'path/to/virtualenv/bin/activate_this.py'
>> if os.path.exists(activate_this):
>> execfile(activate_this, dict(__file__=activate_this))
>>
>> On 25 Σεπ 2009, at 3:56 μ.μ., Gabriel Rossetti wrote:
>>
>> > Hello everyone,
>> >
>> > I would like to create a Launchd plist entry to start a virtualenv
>> > and run a python project. I created my plist, but I'm not sure how
>> > to get it to activate the virtualenv and run the program. I thought
>> > that maybe I could create two emtries :
>> >
>> >
>> >
>> >
>> "http://www.apple.com/DTDs/PropertyList-1.0.dtd%26quot%3B%26gt">http://www.apple.com/DTDs/PropertyList-1.0.dtd">;
>>
>> >
>> >
>> > Label
>> > com.example.virtualenv
>> > Program
>> > source
>> > ProgramArguments
>> >
>> > /path/to/myvirtualenv/bin/activate
>> >
>> > RunAtLoad
>> >
>> >
>> >
>> > Label
>> > com.example.app
>> > Program
>> > python
>> > ProgramArguments
>> >
>> > /path/to/myproj/launcher.py
>> > start
>> >
>> > RunAtLoad
>> >
>> >
>> >
>> >
>> >
>> > but I'm not sure I can do that, and I have 2 programs to run for my
>> > project, so would I create 3 entries like so :
>> >
>> >
>> >
>> >
>> "http://www.apple.com/DTDs/PropertyList-1.0.dtd%26quot%3B%26gt">http://www.apple.com/DTDs/PropertyList-1.0.dtd">;
>>
>> >
>> >
>> >
>> > Label
>> > com.example.virtualenv
>> > Program
>> > source
>> > ProgramArguments
>> >
>> > /path/to/myvirtualenv/bin/activate
>> >
>> > RunAtLoad
>> >
>> >
>> >
>> >
>> > Label
>> > com.example.app1
>> > Program
>> > python
>> > ProgramArguments
>> >
>> > /path/to/myproj/launcher.py
>> > app1
>> > start
>> >
>> > RunAtLoad
>> >
>> >
>> >
>> >
>> > Label
>> > com.example.app2
>> > Program
>> > python
>> > ProgramArguments
>> >
>> > /path/to/myproj/launcher.py
>> > app2
>> > start
>> >
>> > RunAtLoad
>> >
>> >
>> >
>> >
>> > Or is there a better/another way to do this?
>> > _______________________________________________
>> > Pythonmac-SIG maillist - Pythonmac-SIG@...
>> >
>> http://mail.python.org/mailman/listinfo/pythonmac-sig">http://mail.python.org/mailman/listinfo/pythonmac-sig 
>>
>>
>>
>
_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@...
http://mail.python.org/mailman/listinfo/pythonmac-sig

Re: Lanchd + virtualenv

by Ronald Oussoren :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 25 Sep, 2009, at 14:56, Gabriel Rossetti wrote:

> Hello everyone,
>
> I would like to create a Launchd plist entry to start a virtualenv  
> and run a python project. I created my plist, but I'm not sure how  
> to get it to activate the virtualenv and run the program.

Unless you do something special you don't have to activate the  
virtualenv at all, just make sure that the '#!' line in the script  
you're starting refers to the python in the virtualenv (instead of  
having '#!/usr/bin/env python').

I have a virtualenv containing a mercurial installation and regularly  
use the mercurial command-line tools without activating the virtualenv.

Ronald



_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@...
http://mail.python.org/mailman/listinfo/pythonmac-sig

smime.p7s (2K) Download Attachment

Re: Lanchd + virtualenv

by grossetti :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ronald Oussoren wrote:

>
> On 25 Sep, 2009, at 14:56, Gabriel Rossetti wrote:
>
>> Hello everyone,
>>
>> I would like to create a Launchd plist entry to start a virtualenv
>> and run a python project. I created my plist, but I'm not sure how to
>> get it to activate the virtualenv and run the program.
>
> Unless you do something special you don't have to activate the
> virtualenv at all, just make sure that the '#!' line in the script
> you're starting refers to the python in the virtualenv (instead of
> having '#!/usr/bin/env python').
>
> I have a virtualenv containing a mercurial installation and regularly
> use the mercurial command-line tools without activating the virtualenv.
>
> Ronald
>
Ok, thanks, so from what I understand I only need to activate it if I
have to install a package into it.

Gabriel
_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@...
http://mail.python.org/mailman/listinfo/pythonmac-sig

Re: Lanchd + virtualenv

by Ronald Oussoren :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 30 Sep, 2009, at 17:31, Gabriel Rossetti wrote:

> Ronald Oussoren wrote:
>>
>> On 25 Sep, 2009, at 14:56, Gabriel Rossetti wrote:
>>
>>> Hello everyone,
>>>
>>> I would like to create a Launchd plist entry to start a virtualenv  
>>> and run a python project. I created my plist, but I'm not sure how  
>>> to get it to activate the virtualenv and run the program.
>>
>> Unless you do something special you don't have to activate the  
>> virtualenv at all, just make sure that the '#!' line in the script  
>> you're starting refers to the python in the virtualenv (instead of  
>> having '#!/usr/bin/env python').
>>
>> I have a virtualenv containing a mercurial installation and  
>> regularly use the mercurial command-line tools without activating  
>> the virtualenv.
>>
>> Ronald
>>
> Ok, thanks, so from what I understand I only need to activate it if  
> I have to install a package into it.
You only have to activate when you need to have executables from the  
virtualenv on your shell's search-path (that is $PATH). Activating is  
handy when you are installing software, but is also needed when a  
script in the virtualenv executes another script in the environment  
and assumes that that other script is on the search-path.

Ronald
>
> Gabriel



_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@...
http://mail.python.org/mailman/listinfo/pythonmac-sig

smime.p7s (2K) Download Attachment