I'd like to modify the setup.py script from the Ansible project so that I can install ansible into a virtualenv like so:
pip install -e git://github.com/lorin/ansible.git#egg=ansible
When I do this now, ansible doesn't run properly, because it can't import the ansible module.
$ ansible
Traceback (most recent call last):
File "/Users/lorin/.virtualenvs/ansible/bin/ansible", line 7, in <module>
execfile(__file__)
File "/Users/lorin/.virtualenvs/ansible/src/ansible/bin/ansible", line 25, in <module>
from ansible.runner import Runner
ImportError: No module named ansible.runner
From what I can tell, one or both of these files tells Python where to find the Ansible module.
$venv/lib/python2.7/sites-packages/ansible.egg-link:
/Users/lorin/.virtualenvs/ansible/src/ansible
.
$venv/lib/python2.7/sites-packages/easy-install.pth:
import sys; sys.__plen = len(sys.path)
./setuptools-0.6c11-py2.7.egg
./pip-1.0.2-py2.7.egg
/Users/lorin/.virtualenvs/ansible/src/ansible
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)
In both cases, it points to /Users/lorin/.virtualenvs/ansible/src/ansible, but I think it should actually point to /Users/lorin/.virtualenvs/ansible/src/ansible/lib, since the ansible module is a subset of that directory.
(Note: I can't just move the ansible/lib/ansible directory to ansible/ansible since the upstream project is unlikely to accept that change).
I tried to modify these files by hand to see if that would resolve the issue, but that revealed a new problem:
$ ansible
Traceback (most recent call last):
File "/Users/lorin/.virtualenvs/ansible/bin/ansible", line 4, in <module>
from pkg_resources import require; require('ansible==0.6')
File "build/bdist.linux-i686/egg/pkg_resources.py", line 2603, in <module>
File "build/bdist.linux-i686/egg/pkg_resources.py", line 666, in require
File "build/bdist.linux-i686/egg/pkg_resources.py", line 565, in resolve
pkg_resources.DistributionNotFound: ansible==0.6
And, "pip freeze" does not report that the package was installed at all:
$ pip freeze
Jinja2==2.6
PyYAML==3.10
paramiko==1.7.7.2
pycrypto==2.6
wsgiref==0.1.2
Even once I resolve these issues, I need to somehow set the ANSIBLE_LIBRARY environment variable to point to $venv/src/ansible/library when the virtualenv is activated.
So, to sum up, what do I need to do to:
- Get the various Python paths to point to the right directory?
- Deal with the version error?
- Set the
ANSIBLE_LIBRARYenvironment variable?
I also don't want to change the behavior of the setup.py script for the other use cases. I don't have any experience with any of the various Python build tools, so I'm at a loss.