'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?
Solution 1:[1]
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.
Solution 2:[2]
You might want to take a look at http://paver.github.com/paver/, which makes extending distutils with some project-specific tasks a breeze.
Solution 3:[3]
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()"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mikko Ohtamaa |
| Solution 2 | pyroscope |
| Solution 3 | uzumaki |
