romeroqj
romeroqj

Reputation: 839

setup.py, setup() plus some other stuff

setup.py can contain any sort of Python code besides the call to the function setup(), I tested it with the following snippet:

from setuptools import setup

setup(name='MyPackage',
      packages=['mypackage'])

print "After setup()"

The print statement was executed normally. I tested this because the command (python setup.py install) made me doubt. Should I fearlessly treat setup.py as an arbitrary script that handles all my installation needs?

The background goes something like this: I'm writing a Python package that works as a stand-alone program, it's not intended to be imported. In distutils I found almost everything I need to handle the installation details like copying a script to the system path, copying extra data files, creating directories, etc. But there's still some procedures that go out of distutils' scope, e.g. system calls.

Should I just put this extra code I need into setup.py?

Upvotes: 1

Views: 146

Answers (3)

uzumaki
uzumaki

Reputation: 1963

If an error occures during the execution of setup(), the program will stop and no further code will be executed. But you might still want some additional code to be executed. In this case, use:

from setuptools import setup

try:
    setup(name='MyPackage',
          packages=['mypackage'])

finally:
    print "After setup()"

Upvotes: 0

pyroscope
pyroscope

Reputation: 4158

You might want to take a look at http://paver.github.com/paver/, which makes extending distutils with some project-specific tasks a breeze.

Upvotes: 0

Mikko Ohtamaa
Mikko Ohtamaa

Reputation: 83368

This recent blog post should answer most of your questions:

http://tarekziade.wordpress.com/2011/08/19/5-tips-for-packaging-your-python-projects/

A lot of work-in-progress, but not yet available, regarding packaging in Python world.

Upvotes: 1

Related Questions