Skip to content
Snippets Groups Projects
setup.py 3.72 KiB
Newer Older
  • Learn to ignore specific revisions
  • Bob Ippolito's avatar
    Bob Ippolito committed
    #!/usr/bin/env python
    
    from __future__ import with_statement
    
    Bob Ippolito's avatar
    Bob Ippolito committed
    
    
    Bob Ippolito's avatar
    Bob Ippolito committed
    import sys
    
    try:
        from setuptools import setup, Extension, Command
    except ImportError:
        from distutils.core import setup, Extension, Command
    
    Bob Ippolito's avatar
    Bob Ippolito committed
    from distutils.command.build_ext import build_ext
    
    from distutils.errors import CCompilerError, DistutilsExecError, \
        DistutilsPlatformError
    
    Bob Ippolito's avatar
    Bob Ippolito committed
    
    
    IS_PYPY = hasattr(sys, 'pypy_translation_info')
    
    Bob Ippolito's avatar
    Bob Ippolito committed
    VERSION = '3.6.4'
    
    Bob Ippolito's avatar
    Bob Ippolito committed
    DESCRIPTION = "Simple, fast, extensible JSON encoder/decoder for Python"
    
    
    with open('README.rst', 'r') as f:
       LONG_DESCRIPTION = f.read()
    
    Bob Ippolito's avatar
    Bob Ippolito committed
    
    CLASSIFIERS = filter(None, map(str.strip,
    
    Development Status :: 5 - Production/Stable
    
    Bob Ippolito's avatar
    Bob Ippolito committed
    Intended Audience :: Developers
    License :: OSI Approved :: MIT License
    
    License :: OSI Approved :: Academic Free License (AFL)
    
    Bob Ippolito's avatar
    Bob Ippolito committed
    Programming Language :: Python
    
    Programming Language :: Python :: 2
    Programming Language :: Python :: 2.5
    Programming Language :: Python :: 2.6
    Programming Language :: Python :: 2.7
    Programming Language :: Python :: 3
    Programming Language :: Python :: 3.3
    
    Programming Language :: Python :: 3.4
    
    Programming Language :: Python :: Implementation :: CPython
    Programming Language :: Python :: Implementation :: PyPy
    
    Bob Ippolito's avatar
    Bob Ippolito committed
    Topic :: Software Development :: Libraries :: Python Modules
    """.splitlines()))
    
    
    if sys.platform == 'win32' and sys.version_info > (2, 6):
       # 2.6's distutils.msvc9compiler can raise an IOError when failing to
       # find the compiler
    
       # It can also raise ValueError http://bugs.python.org/issue7511
    
       ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError,
    
    else:
       ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
    
    
    class BuildFailed(Exception):
        pass
    
    Bob Ippolito's avatar
    Bob Ippolito committed
    
    class ve_build_ext(build_ext):
        # This class allows C extension building to fail.
    
    
        def run(self):
            try:
                build_ext.run(self)
    
            except DistutilsPlatformError:
    
                raise BuildFailed()
    
    Bob Ippolito's avatar
    Bob Ippolito committed
        def build_extension(self, ext):
            try:
                build_ext.build_extension(self, ext)
    
            except ext_errors:
    
                raise BuildFailed()
    
    Bob Ippolito's avatar
    Bob Ippolito committed
    
    class TestCommand(Command):
        user_options = []
    
        def initialize_options(self):
            pass
    
        def finalize_options(self):
            pass
    
        def run(self):
            import sys, subprocess
            raise SystemExit(
    
                subprocess.call([sys.executable,
                                 # Turn on deprecation warnings
                                 '-Wd',
                                 'simplejson/tests/__init__.py']))
    
    Bob Ippolito's avatar
    Bob Ippolito committed
    
    
    def run_setup(with_binary):
    
    Bob Ippolito's avatar
    Bob Ippolito committed
        cmdclass = dict(test=TestCommand)
    
        if with_binary:
    
    Bob Ippolito's avatar
    Bob Ippolito committed
            kw = dict(
                ext_modules = [
                    Extension("simplejson._speedups", ["simplejson/_speedups.c"]),
                ],
                cmdclass=dict(cmdclass, build_ext=ve_build_ext),
            )
    
    Bob Ippolito's avatar
    Bob Ippolito committed
            kw = dict(cmdclass=cmdclass)
    
    Bob Ippolito's avatar
    Bob Ippolito committed
    
    
        setup(
            name="simplejson",
            version=VERSION,
            description=DESCRIPTION,
            long_description=LONG_DESCRIPTION,
            classifiers=CLASSIFIERS,
            author="Bob Ippolito",
            author_email="bob@redivi.com",
    
    Bob Ippolito's avatar
    Bob Ippolito committed
            url="http://github.com/simplejson/simplejson",
    
            license="MIT License",
    
    Bob Ippolito's avatar
    Bob Ippolito committed
            packages=['simplejson', 'simplejson.tests'],
    
            platforms=['any'],
    
    Bob Ippolito's avatar
    Bob Ippolito committed
            **kw)
    
        run_setup(not IS_PYPY)
    
    except BuildFailed:
    
        BUILD_EXT_WARNING = ("WARNING: The C extension could not be compiled, "
                             "speedups are not enabled.")
        print('*' * 75)
        print(BUILD_EXT_WARNING)
        print("Failure information, if any, is above.")
        print("I'm retrying the build without the C extension now.")
        print('*' * 75)
    
        print('*' * 75)
        print(BUILD_EXT_WARNING)
        print("Plain-Python installation succeeded.")
        print('*' * 75)