Modify setup.py to support pip installation from github

I would like to modify the setup.py script from Ansible so that I can set access to the virtual file like this:

pip install -e git://github.com/lorin/ansible.git#egg=ansible 

When I do this now, ansible is not working properly because it cannot import an indispensable 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 tell 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 module in question is a subset of this directory.

(Note: I cannot just move the ansible / lib / ansible directory to an accessible / indispensable one, as the upstream project is unlikely to accept this change).

I tried to manually modify these files to see if this fixes the problem, but this 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 when I solve these problems, I need to somehow set the environment variable ANSIBLE_LIBRARY to point to $venv/src/ansible/library when virtualenv is activated.

So, to summarize, what I need to do to:

  • Get various Python paths to point to the correct directory?
  • Fix version error
  • Set the environment variable ANSIBLE_LIBRARY ?

I also do not want to change the setup.py script behavior for other use cases. I have no experience with any Python building tools, so I'm at a loss.

+4
source share
2 answers

The problem with the editable installation ( -e flag) is that it requires the project to have a structure such as:

 ├── projectname │  ├── projectname │  │  ├── __init__.py │  │  └── anotherfile.py │  └── setup.py 

Note that the subdirectory is projectname . In the case of Ansible it does not have this structure. Therefore, it does not work with an editable installation.

Just remove this -e flag and it may work:

 pip install -e git://github.com/lorin/ansible.git#egg=ansible 
+3
source

All Articles