views:

44

answers:

2

I've just started working with setuptools and virtualenv. My package requires the latest python-gearman that is only available from GitHub. The python-gearman version that's on PyPI is an old one. The Github source is setuptools-compatible, i.e. has setup.py, etc. Is there a way to make setuptools download and install the new version instead of looking for it on PyPI and installing the old one?

FYI, the new python-gearman is http://github.com/mtai/python-gearman

+1  A: 

Vanilla setuptools does not support downloading directly from a git repository but you can use one of the Download Source links from that page, like:

easy_install http://github.com/mtai/python-gearman/tarball/master
Ned Deily
So, in order to make sure that this version of python-gearman is installed on any server where my package is going to be, I'm going to have to run easy_install manually before installing my package?
andrei
If you use easy_install, yes. But, as others have pointed out, you could switch to `pip` or `buildout` which have more sophisticated requirements management. See, for example: http://pip.openplans.org/#requirements-files
Ned Deily
Actually, you don't have to manually run easy_install; you can simply add the extra link to your setup.py. I'll write an answer explaining the details.
pjeby
+2  A: 

So, the key here is to tell easy_install where the git version can be downloaded from. In this case, it's http://github.com/mtai/python-gearman/tarball/master. However, that link by itself won't work, because easy_install can't tell just by looking at the URL what it's going to get.

So, by changing it to http://github.com/mtai/python-gearman/tarball/master#egg=gearman-2.0.0beta instead, easy_install will be able to tell what package and version it is.

Now, the last step to making it work. Since this link is not on PyPI, you must add it to your package's dependency_links, e.g.:

setup(
   ...
   dependency_links = ['http://github.com/mtai/python-gearman/tarball/master#egg=gearman-2.0.0beta']
)

Now, when YOUR package is being installed, easy_install will discover that there is a "gearman 2.0.0beta" available for download from that URL, and happily pick it over the one on PyPI, if you specify "gearman>=2.0.0beta" in your dependencies..

(Normally, the way this sort of thing is done is to include a link on one's PyPI page to the downloadable source; in this case, if the author of the gearman package had included a link like the above, you'd be already set. Typically, people mark the development version with 'myproject-dev' and then people use a requirement of 'myproject>=somever,==dev', so that if there isn't a package of somever or higher, easy_install will try to check out or download the release.)

pjeby
I did what you suggested, but when I run "python setup.py develop", it says "writing dependency_links to foo.egg-info/dependency_links.txt", but doesn't actually download and install the package. I'm using a setuptools-based virtualenv if that helps.
andrei
You need to also have install_requires='gearman>=2.0.0beta'; did you include that?
pjeby
That worked. But in general, would you suggest using something like buildout for enforcing such requirements or, perhaps, Puppet or Chef?
andrei
I hear lots of good things about buildout, but haven't used it myself yet. If you need other things besides just Python code installed, I'd recommend you at least investigate buildout.
pjeby