FSX / momoko

Wraps (asynchronous) Psycopg2 for Tornado.
http://momoko.61924.nl/
Other
363 stars 73 forks source link

env var set fails with pip install #113

Closed lsmag closed 9 years ago

lsmag commented 9 years ago

Hi,

I was trying to install Momoko with psycopg2cffi, your setup instructions work fine when I download the package and install it directly (MOMOKO_PSYCOPG2_IMPL=psycopg2cffi python setup.py install), but it fails when I try it with pip:

MOMOKO_PSYCOPG2_IMPL=psycopg2cffi pip install momoko

It'll always install psycopg2 instead. I assume this is a particular behaviour of pip (though not a bug, I believe), so it might be fine. Also, I use pip just indirectly with pip-tools. mostly pip-sync to do the first install.

So, there are two things here:

Like:

$ pip install psycopg2cffi momoko
# psycopg2cffi gets installed first, then momoko drops the psycopg2 dependency

As a bonus, it'll also work with pip-tools. I can make a PR with this new install method without dropping the current one (which tests rely on, if I'm not mistaken).

haizaar commented 9 years ago

I guess pip looks up dependencies on PyPi and momoko is registered on PyPi with psycopg2 dependency. I deduce this from the fact that pip downloads all of the stuff before installing it.

Regarding your second question, I frankly did not understand how do you declare dependencies there. Can you elaborate?

lsmag commented 9 years ago

If pip looks up on PyPI before installing the actual package, then my second suggestion wouldn't work without breaking the actual install method =D What I proposed was something like:

# on setup.py
dependencies = ['psycopg2']
try:
    import psycopg2cffi
    dependencies.pop()
except ImportError:
    pass

setup(dependencies=depencencies)  # or sth like that

If psycopg2cffi can be found, then don't install psycopg2, but it's useless now until I confirm the behavior you deduced. No problem, anyway, I can still force pip to install momoko+psycopg2cffi if I install from a git tag:

$ MOMOKO_PSYCOPG2_IMPL='psycopg2cffi' pip install -e "git+https://github.com/FSX/momoko.git@v2.1.1#egg=momoko"

And I still think it's a better one-liner than downloading and calling setup.py directly. What do you think adding this specific line in the docs?

haizaar commented 9 years ago

Well, I had a look at pip docs. They say:

It's important to be clear that pip determines package dependencies using install_requires metadata, not by discovering requirements.txt files embedded in projects.

If it loads setup.py and uses install_requires, then your trick should work. I suggest you try hacking pip to find out what's going on.