0

Added a PIL alpha_over extension in C, and code to setup.py to build it

I needed a way to let py2exe options be provided only when py2exe is
available. My solution (maybe not the best) was to put all the
arguments for the final setup() call into a dictionary, that is filled
in conditionally during the script's execution. This is why the file
is completely changed; however, it still does what it used to do (when
py2exe is available).
This commit is contained in:
Aaron Griffith
2010-10-23 12:57:37 -04:00
parent 32ba6c4424
commit 5a19b8b375
3 changed files with 290 additions and 11 deletions

View File

@@ -1,13 +1,68 @@
from distutils.core import setup
import py2exe
from distutils.core import setup, Extension
from distutils.command.build import build
from distutils.command.clean import clean
from distutils.dir_util import remove_tree
from distutils import log
import os, os.path
setup(console=['gmap.py'],
data_files=[('textures', ['textures/lava.png', 'textures/water.png']),
('', ['template.html'])],
zipfile = None,
options = {'py2exe': {
'bundle_files': 1,
}},
try:
import py2exe
except ImportError:
py2exe = None
# now, setup the keyword arguments for setup
# (because we don't know until runtime if py2exe is available)
setup_kwargs = {}
setup_kwargs['options'] = {}
setup_kwargs['ext_modules'] = []
setup_kwargs['cmdclass'] = {}
#
# py2exe options
#
if py2exe != None:
setup_kwargs['console'] = ['gmap.py']
setup_kwargs['data_files'] = [('textures', ['textures/lava.png', 'textures/water.png']),
('', ['template.html'])]
setup_kwargs['zipfile'] = None
setup_kwargs['options']['py2exe'] = {'bundle_files' : 1}
#
# _composite.c extension
#
setup_kwargs['ext_modules'].append(Extension('_composite', ['_composite.c']))
# tell build_ext to build the extension in-place
# (NOT in build/)
setup_kwargs['options']['build_ext'] = {'inplace' : 1}
# tell the build command to only run build_ext
build.sub_commands = [('build_ext', None)]
# custom clean command to remove in-place extension
class CustomClean(clean):
def run(self):
# do the normal cleanup
clean.run(self)
)
# try to remove '_composite.{so,pyd,...}' extension,
# regardless of the current system's extension name convention
build_ext = self.get_finalized_command('build_ext')
fname = build_ext.get_ext_fullpath('_composite')
pretty_fname = os.path.split(fname)[1]
if os.path.exists(fname):
try:
if not self.dry_run:
os.remove(fname)
log.info("removing '%s'", pretty_fname)
except OSError:
log.warn("'%s' could not be cleaned -- permission denied",
pretty_fname)
else:
log.debug("'%s' does not exist -- can't clean it",
pretty_fname)
setup_kwargs['cmdclass']['clean'] = CustomClean
###
setup(**setup_kwargs)