Support setuptools

Bug #389358 reported by dialtone
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
txAMQP
Fix Released
Wishlist
Zooko Wilcox-O'Hearn

Bug Description

There's not much to add to the summary. It would be nice if txamqp was uploaded on pypi and supported setuptools (and easy_install as a consequence).

Revision history for this message
Esteve Fernandez (esteve) wrote :

DISCLAIMER: I don't know setuptools at all, we use distutils and build Debian packages using dh_pycentral/dh_pysupport.

Having said that, is setuptools compatible with distutils? Can both co-exist in the same project? How hard is it to add support for setuptools?

Changed in txamqp:
importance: Undecided → Wishlist
Revision history for this message
dialtone (dialtone) wrote :

Yes. Below there's the diff, very simple. The other part is to remember to update
the version number in the setup call and release to pypi using the following command:

$ python setup.py egg_info -RDb '' sdist register upload

Which will do everything you need and upload to pypi ready for easy_install.

And here's the diff:

=== modified file 'setup.py'
--- setup.py 2009-05-22 15:29:06 +0000
+++ setup.py 2009-06-20 00:23:32 +0000
@@ -1,4 +1,11 @@
-from distutils.core import setup
+#!/usr/bin/env python
+try:
+ # Load setuptools, to build a specific source package
+ import setuptools
+ setup = setuptools.setup
+except ImportError:
+ from distutils.core import setup
+
 from glob import glob

 setup(

Revision history for this message
Zooko Wilcox-O'Hearn (zooko) wrote :

There are several different issues involved in this ticket.

1. Can txamqp be installed with easy_install? The answer is that it already can. I just generated a source dist with "python ./setup.py sdist" on the current release of txamqp v0.2.1. This produced a file named "txAMQP-0.2.tar.gz". (Oops, that's a mistake -- it should have produced "txAMQP-0.2.1.tar.gz"; It appears that you forgot to change the version number in setup.py when you made v0.2.1). Then I ran "easy_install ./dist/txAMQP-0.2.tar.gz" and it worked. (Except, see below about "declaring dependencies".)

2. Is txamqp registered on pypi? No, it is not. You can easily fix this by running "python ./setup.py register". Or, you can go to http://pypi.python.org and clickety clickety click and fill in some fields to register it.

3. Is a txamqp distribution hosted on pypi? No, it is not. You can easily fix this by running "python ./setup.py sdist upload". Or, you can go to http://pypi.python.org and clickety clickety click and upload a distribution to be hosted there.

4. Is txamqp built using setuptools? Currently it isn't, but it doesn't need to be for any of the previous three features to work. Building txamqp using setuptools would allow for further features:

4.a. Declaring dependencies. If someone runs "easy_install txamqp", then txamqp will get installed. However, it will not run unless that person has also installed Twisted. setuptools allows you to declare that txamqp requires twisted, in which case someone who runs "easy_install txamqp" will also automatically get Twisted installed.

4.b. Development plugins. If your setup.py imports and uses setuptools instead of distutils, then you can for example use setuptools_pyflakes so that "python ./setup.py flakes" runs pyflakes on your code, or setuptools_trial so that "python ./setup.py test" runs trial on your code. There are other plugins, but those are the two that I use.

Note that it is possible to use setuptools optionally while also building with distutils if setuptools isn't installed. That's what the patch that dialtone showed does. Then people who don't have setuptools installed don't get either of the 4.a. or 4.b. features, but can continue building as they were before.

Revision history for this message
dialtone (dialtone) wrote :

Point taken. Then reject the diff but still upload the project to pypi. I don't wanna do it because the project is not mine and I don't want to claim anything about it, I'd rather leave the choice to its owners :).

Revision history for this message
Zooko Wilcox-O'Hearn (zooko) wrote :

Ah, yes I'm not either. Everything I wrote there was intended for the project owners (esteve?) to read and hopefully act upon.

Revision history for this message
Zooko Wilcox-O'Hearn (zooko) wrote :

Here's another reason to use setuptools: then you can use pkg_resources to find and read in a string at runtime. This is a better way to get the XML spec than passing a filename to xmlutil.parse(), because it can be hard to figure out what the filename should be at runtime, especially if you might be deployed inside a zip file, inside a py2exe app, etc.

I'm working on a patch that adds xmlutil.parseString() which takes a string instead of a filename. The txAMQP-using application that I'm using uses pkg_resources.resource_string() to read the XML spec file in at runtime and then passes it to this new xmlutil.parseString() function. txAMQP itself, its unit tests and example files, could use the same technique so that they would be able to find the spec even if things had been moved around by deployment.

Revision history for this message
Esteve Fernandez (esteve) wrote :

FWIW, although I was the original creator of txAMQP, I'm no longer the only one who owns it. Anyway, I created a new branch for this bug and a merge request.

Changed in txamqp:
status: New → In Progress
Revision history for this message
Zooko Wilcox-O'Hearn (zooko) wrote :

I'm sorry, I don't know how to create bzr branches, and I need to leave work now, so I'm pasting this patch into here so that I'll be able to access it from home over the weekend.

=== modified file 'setup.py'
--- setup.py 2009-05-22 15:29:06 +0000
+++ setup.py 2009-07-10 18:52:24 +0000
@@ -1,16 +1,24 @@
-from distutils.core import setup
-from glob import glob
+setupdict= {
+ 'name': 'txAMQP',
+ 'version': '0.2.6', # Zooko's version off of trunk on 2009-07-09.
+ 'author': 'Esteve Fernandez',
+ 'author_email': '<email address hidden>',
+ 'url': 'https://launchpad.net/txamqp',
+ }

-setup(
- name = 'txAMQP',
- version = '0.2',
- author = 'Esteve Fernandez',
- author_email = '<email address hidden>',
- packages = ['txamqp', 'txamqp.contrib', 'txamqp.contrib.thrift'],
- package_dir = {
+try:
+ from setuptools import setup, find_packages
+except ImportError:
+ from distutils.core import setup
+ setupdict['packages'] = ['txamqp', 'txamqp.contrib', 'txamqp.contrib.thrift']
+ setupdict['package_dir'] = {
         'txamqp': 'src/txamqp',
         'txamqp.contrib': 'src/txamqp/contrib',
         'txamqp.contrib.thrift': 'src/txamqp/contrib/thrift',
- },
- url = 'https://launchpad.net/txamqp',
-)
+ },
+else:
+ setupdict['packages'] = find_packages('src')
+ setupdict['package_dir'] = { '': 'src' }
+ setupdict['install_requires'] = ['Twisted']
+
+setup(**setupdict)

Revision history for this message
Zooko Wilcox-O'Hearn (zooko) wrote :
Revision history for this message
Esteve Fernandez (esteve) wrote :

I merged Zooko's branch. Thank you all for your work!

Changed in txamqp:
assignee: nobody → Zooko O'Whielacronx (zooko)
status: In Progress → Fix Committed
Changed in txamqp:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.