Source

greenlet-excstate / setup.py

Full commit
#!/usr/bin/env python

import os
import errno
import sys

from distutils import ccompiler
from distutils import dep_util
from distutils.command.build import build
from distutils.util import get_platform
from setuptools import Extension
from setuptools import setup

greenlet_extension = Extension(name='greenlet', sources=['greenlet.c'])

class build_asm(build):
    """A hack currently used by x64 Windows only. Since Microsoft removed
    support for inline assembler in their x64 C compiler, we have to run the
    assembler ourselves.
    """
    description = 'Assemble platform specific assembler files.'
    asm_files = {
        'win-amd64': {
            'options': ['/nologo', '/c'],
            'debug-options': [
                '/nologo', '/c', '/W3', '/Zi', '/Zd', '/D_DEBUG'],
            'output-file-arg': '/Fo',
            'files': ['platform/switch_x64_masm.asm'],
            'assembler': 'ml64',
            'linker-args': []},}
    def run(self):
        asm_info = self.asm_files.get(get_platform(), None)
        if asm_info is None:
            return
        c = ccompiler.new_compiler()
        c.initialize()
        assembler = c.find_exe(asm_info['assembler'])
        if self.debug:
            assembler_args = asm_info['debug-options']
        else:
            assembler_args = asm_info['options']
        for asm_file in asm_info['files']:
            output_filename = os.path.join(
                self.build_temp,
                os.path.splitext(asm_file)[0] + c.obj_extension)
            try:
                os.makedirs(os.path.dirname(output_filename))
            except OSError:
                if sys.exc_info()[1].errno != errno.EEXIST:
                    raise
            if not dep_util.newer(asm_file, output_filename):
                # This file hasn't been modified since it was last assembled,
                # so we skip it.
                continue
            c.spawn([assembler] + assembler_args + [
                    asm_info['output-file-arg'], output_filename, asm_file])
            greenlet_extension.extra_objects.append(output_filename)
        greenlet_extension.extra_link_args += asm_info['linker-args']


# Make sure build_asm is the first sub command run, so it runs before build_ext.
build.sub_commands.insert(0, ('build_asm', None))

setup(
    name="greenlet",
    version='0.3.1',
    description='Lightweight in-process concurrent programming',
    long_description=open(
        os.path.join(os.path.dirname(__file__), 'README'), 'r').read(),
    maintainer="Kyle Ambroff",
    maintainer_email="kyle@ambroff.com",
    url="http://bitbucket.org/ambroff/greenlet",
    license="MIT License",
    platforms=['any'],
    test_suite='tests.test_collector',
    headers=['greenlet.h'],
    cmdclass={'build_asm': build_asm},
    ext_modules=[greenlet_extension],
    classifiers=[
        'Intended Audience :: Developers',
        'License :: OSI Approved :: MIT License',
        'Natural Language :: English',
        'Programming Language :: Python',
        'Operating System :: OS Independent',
        'Topic :: Software Development :: Libraries :: Python Modules'])