[Twisted-Python] How to configure setup.py for a twistd TAP app

Chris Miles miles.chris at gmail.com
Thu Dec 20 02:23:44 EST 2007

On 20/12/2007, at 1:21 AM, Jean-Paul Calderone wrote:

> On Thu, 20 Dec 2007 00:15:59 +1100, Chris Miles  
> <miles.chris at gmail.com> wrote:
>> I want to deploy my Twisted app as a Twisted Application Plugin  
>> for  twistd as per
>> http://twistedmatrix.com/projects/core/documentation/howto/tap.html
>> I want to distribute my app as a tarball, so the user would untar  
>> it  and run "python setup.py install".  Then they would run "twistd  
>> myapp"  to start it.
>> How do I configure setup.py so that twisted/plugins/myapp.py is  
>> created?
> Since your app depends on Twisted, the user should already have a  
> directory
> named "twisted/plugins" in their install directory (probably their  
> system-
> wide site-packages, but not necessary).  Twisted itself creates and  
> installs
> this directory.  Your installer needs to do just two things: put  
> myapp.py
> into that directory and regenerate the plugin cache.
> One way in which to accomplish the first thing is like this:
>   Pass a list like ["twisted.plugins"] for the packages keyword  
> argument
>   to distutils setup()
>   Pass a dict like {'twisted': ['plugins/myapp.py']} for the  
> package_data
>   keyword argument to distutils setup()
>   Include a line like "graft twisted" in your MANIFEST.in
> http://twistedmatrix.com/projects/core/documentation/howto/plugin.html#auto3
> gives an example of how to do the second thing.

Thanks Jean-Paul, that worked great, with both distutils.core.setup  
and twisted.python.dist.setup.  When I used the latter I didn't need  
to regenerate the plugin cache, twistd picked up the new command  
immediately after install.  Is this the advantage of  
twisted.python.dist.setup ?

The technique also (mostly) worked using setuptools.setup.  twistd  
picks up the new command, but spits out a UserWarning due to the  
appearance of the duplicate twisted package within the egg directory.

__init__.py:3: UserWarning: Module twisted was already imported from / 
packages/twisted/__init__.pyc, but /Library/Frameworks/ 
myproject-0.0.0-py2.4.egg is being added to sys.path
   import pkg_resources
Usage: twistd [options]

I'd like to use setuptools, if possible, due to my project's  
dependencies on other setuptools-managed packages, but I can live  
without it if it's not fully compatible with Twisted application  

Chris Miles

More information about the Twisted-Python mailing list