Using virtualenv with provy

37 views
Skip to first unread message

John Donovan

unread,
Feb 11, 2013, 8:03:16 AM2/11/13
to pr...@googlegroups.com
Hi,
I'm new to provy, and I've been experimenting with setting up a simple Flask app on a Vagrant VM. As is generally best practice, I want to create a virtualenv for the app, but I'm having difficulty getting it working with pip. Here's my provyfile.py, mostly copied from the getting started code.

from provy.core import Role
from provy.more.debian import VirtualenvRole, PipRole, UserRole

class MyServer(Role):
    def provision(self):
        with self.using(UserRole) as role:
            role.ensure_user('wibble', identified_by='foobar', is_admin=True)

        self.update_file('simpleserver.py', '/home/wibble/simpleserver.py', owner='wibble', sudo=True)

        with self.using(PipRole) as pip, self.using(VirtualenvRole) as venv:
            venv.user = 'wibble'

            with venv('serverenv2'):
                pip.set_user('wibble')
                pip.ensure_requirements_installed('requirements.txt')

servers = {
    'test': {
        'myserver': {
            'address': '192.168.0.100',
            'user': 'vagrant',
            'roles': [
                MyServer
            ]
        }
    }
}

What I would like is for the virtualenv serverenv2 to be created for user wibble, and then for pip to do its thing with requirements.txt
What I get, however, is this:

Info: Provy is running using the 'test' set of servers.


*************************************
Provisioning vag...@192.168.0.100...
*************************************
[vag...@192.168.0.100] Login password for 'john': 
[12:44:35] Group wibble not found! Creating...
[12:44:35] Group wibble created!
[12:44:35] User wibble not found! Creating...
[12:44:35] User wibble created!
[12:44:35] Hashes differ  => None! Copying simpleserver.py to server 192.168.0.100!
[vag...@192.168.0.100] put: /var/folders/gh/wm64c4k94fbgb0v58syr2jnm0000gn/T/tmpNrnbh2 -> /home/wibble/simpleserver.py
[12:44:36] "change_file_owner" is deprecated, please use "change_path_owner" instead.
[12:44:36] Updating aptitude sources...
[12:44:42] Aptitude sources up-to-date
[12:44:43] curl is not installed (via aptitude)! Installing...
[12:44:48] curl is installed (via aptitude).
[12:44:48] python-setuptools is not installed (via aptitude)! Installing...
[12:44:52] python-setuptools is installed (via aptitude).
[12:44:53] python-dev is not installed (via aptitude)! Installing...
[12:45:09] python-dev is installed (via aptitude).
[12:45:13] virtualenv is not installed (via pip)! Installing...
[12:45:20] virtualenv installed!
[12:45:20] virtualenvwrapper is not installed (via pip)! Installing...
[12:45:46] virtualenvwrapper installed!
[vag...@192.168.0.100] sudo: virtualenv /home/vagrant/.virtualenvs/serverenv2
[vag...@192.168.0.100] out: Traceback (most recent call last):
[vag...@192.168.0.100] out:   File "/usr/local/bin/virtualenv", line 9, in <module>
[vag...@192.168.0.100] out:     load_entry_point('virtualenv==1.8.4', 'console_scripts', 'virtualenv')()
[vag...@192.168.0.100] out:   File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 964, in main
[vag...@192.168.0.100] out:     never_download=options.never_download)
[vag...@192.168.0.100] out:   File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 1065, in create_environment
[vag...@192.168.0.100] out:     site_packages=site_packages, clear=clear))
[vag...@192.168.0.100] out:   File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 1236, in install_python
[vag...@192.168.0.100] out:     mkdir(lib_dir)
[vag...@192.168.0.100] out:   File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 406, in mkdir
[vag...@192.168.0.100] out:     os.makedirs(path)
[vag...@192.168.0.100] out:   File "/usr/lib/python2.6/os.py", line 150, in makedirs
[vag...@192.168.0.100] out:     makedirs(head, mode)
[vag...@192.168.0.100] out:   File "/usr/lib/python2.6/os.py", line 150, in makedirs
[vag...@192.168.0.100] out:     makedirs(head, mode)
[vag...@192.168.0.100] out:   File "/usr/lib/python2.6/os.py", line 150, in makedirs
[vag...@192.168.0.100] out:     makedirs(head, mode)
[vag...@192.168.0.100] out:   File "/usr/lib/python2.6/os.py", line 157, in makedirs
[vag...@192.168.0.100] out:     mkdir(name, mode)
[vag...@192.168.0.100] out: OSError: [Errno 13] Permission denied: '/home/vagrant/.virtualenvs'


Fatal error: sudo() received nonzero return code 1 while executing!

Requested: virtualenv /home/vagrant/.virtualenvs/serverenv2
Executed: sudo -S -p 'sudo password:'  -u "wibble"  /bin/bash -l -c "virtualenv /home/vagrant/.virtualenvs/serverenv2"

Aborting.

I'm clearly missing something, because the virtualenv doesn't get created for any user.

Regards,
John

Bernardo Heynemann

unread,
Feb 12, 2013, 7:32:57 PM2/12/13
to provy
I think that's a bug. The virtualenv should've been created for user wiggle...

We'll fix it asap. Thanks for the report John.

Cheers,

Bernardo Heynemann
Developer @ globo.com


--
You received this message because you are subscribed to the Google Groups "provy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to provy+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Diogo Baeder

unread,
Feb 12, 2013, 10:14:08 PM2/12/13
to pr...@googlegroups.com
Indeed a bug. New issue opened for it, please refer to https://github.com/python-provy/provy/issues/117 .

Fix will be released with 0.6.1 (sometime this week); until then, please specify venv.base_directory as per the documentation:

Cheers,

Diogo

John Donovan

unread,
Feb 13, 2013, 11:59:35 AM2/13/13
to pr...@googlegroups.com
Fantastic, thanks Diogo. My workaround is as suggested in the bug report, explicitly setting the virtualenv's base_directory before the with() block.

-John
Reply all
Reply to author
Forward
0 new messages