diff options
author | German M. Bravo <german.mb@deipi.com> | 2012-01-02 23:41:29 -0600 |
---|---|---|
committer | German M. Bravo <german.mb@deipi.com> | 2012-01-02 23:41:29 -0600 |
commit | b388a606bae87bc1a09f1739f98e3be2f0ac1406 (patch) | |
tree | 5424c6e1278c1eed38da5f46684c26a3018ef662 /setup.py | |
parent | a9d98b66d425a244d28d689dc9bcc0f13d811a3a (diff) | |
download | pyscss-b388a606bae87bc1a09f1739f98e3be2f0ac1406.tar.gz |
Version bump introducing speedups
Diffstat (limited to 'setup.py')
-rw-r--r-- | setup.py | 199 |
1 files changed, 124 insertions, 75 deletions
@@ -1,91 +1,140 @@ #!/usr/bin/env python -from setuptools import setup, Extension +import os +import sys +from setuptools import setup, Extension, Feature +from distutils.command.build_ext import build_ext +from distutils.errors import CCompilerError, DistutilsExecError, \ + DistutilsPlatformError from scss.scss_meta import PROJECT, URL, VERSION, AUTHOR, AUTHOR_EMAIL, LICENSE, DOWNLOAD_URL +# fail safe compilation shamelessly stolen from the simplejson +# setup.py file. Original author: Bob Ippolito + +is_jython = 'java' in sys.platform +is_pypy = hasattr(sys, 'pypy_version_info') + +speedups = Feature( + 'optional C speed-enhancement module', + standard=True, + ext_modules=[ + Extension( + 'scss._speedups', + sources=['scss/src/_speedups.c', 'scss/src/block_locator.c', 'scss/src/scanner.c'], + libraries=['pcre'] + ), + ], +) + +ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError) +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 + ext_errors += (IOError,) + + +extra = {} +if sys.version_info >= (3, 0): + extra['use_2to3'] = True + + +class BuildFailed(Exception): + pass + + +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() + + def build_extension(self, ext): + try: + build_ext.build_extension(self, ext) + except ext_errors: + raise BuildFailed() + except ValueError: + # this can happen on Windows 64 bit, see Python issue 7511 + if "'path'" in str(sys.exc_info()[1]): # works with Python 2 and 3 + raise BuildFailed() + raise + + +def echo(msg=''): + sys.stdout.write(msg + '\n') + def read(fname): - import os try: return open(os.path.join(os.path.dirname(__file__), fname)).read().strip() except IOError: return '' -extra = {} -import sys -if sys.version_info >= (3, 0): - extra.update( - use_2to3=True, +def run_setup(with_binary): + features = {} + if with_binary: + features['speedups'] = speedups + setup( + name=PROJECT, + version=VERSION, + description=read('DESCRIPTION'), + long_description=read('README.rst'), + author=AUTHOR, + author_email=AUTHOR_EMAIL, + url=URL, + download_url=DOWNLOAD_URL, + license=LICENSE, + keywords='css oocss xcss sass scss less precompiler', + classifiers=[ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Topic :: Software Development :: Code Generators", + "Topic :: Text Processing :: Markup", + "Topic :: Software Development :: Libraries :: Python Modules" + ], + packages=['scss'], + package_data={'scss': ['tests.rst']}, + cmdclass={'build_ext': ve_build_ext}, + features=features, + entry_points=""" + [console_scripts] + pyscss = scss:main + """, + **extra ) -EXT_MODULES = [ - Extension( - 'scss._scss', - sources=['scss/src/_scss.c', 'scss/src/block_locator.c', 'scss/src/scanner.c'], - libraries=['pcre'], - optional=True - ) -] -if '--with-accel' in sys.argv: - sys.argv.remove('--with-accel') -if '--without-accel' in sys.argv: - sys.argv.remove('--without-accel') - EXT_MODULES = [] -if EXT_MODULES: - print - print '+------------------------------------------------------------------+' - print '| |' - print '| pyScss, a Scss compiler for Python |' - print '| ================================== |' - print '| |' - print '| This package comes with an acceleration module in C. |' - print '| |' - print '| By default,the acceleration module is compiled and installed. |' - print '| Build and install without it by passing: --without-accel |' - print '| |' - print '+#################################################################-+' - print +def try_building_extension(): + try: + run_setup(True) + except BuildFailed: + LINE = '=' * 74 + BUILD_EXT_WARNING = 'WARNING: The C extension could not be ' \ + 'compiled, speedups are not enabled.' + + echo(LINE) + echo(BUILD_EXT_WARNING) + echo('Failure information, if any, is above.') + echo('Retrying the build without the C extension now.') + echo() + + run_setup(False) + + echo(LINE) + echo(BUILD_EXT_WARNING) + echo('Plain-Python installation succeeded.') + echo(LINE) + + +if not (is_pypy or is_jython): + try_building_extension() else: - print - print '+------------------------------------------------------------------+' - print '| |' - print '| pyScss, a Scss compiler for Python |' - print '| ================================== |' - print '| |' - print '| Acceleration module disabled by the user. |' - print '| |' - print '+#################################################################-+' - print - -setup(name=PROJECT, - version=VERSION, - description=read('DESCRIPTION'), - long_description=read('README.rst'), - author=AUTHOR, - author_email=AUTHOR_EMAIL, - url=URL, - download_url=DOWNLOAD_URL, - packages=['scss'], - license=LICENSE, - keywords='css oocss xcss sass scss less precompiler', - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Intended Audience :: Developers", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Topic :: Software Development :: Code Generators", - "Topic :: Text Processing :: Markup", - "Topic :: Software Development :: Libraries :: Python Modules" - ], - ext_modules=EXT_MODULES, - package_data={'scss': ['scss/tests.rst', 'LICENSE', 'CHANGELOG']}, - entry_points=""" - [console_scripts] - pyscss = scss:main - """, - **extra -) + run_setup(False) |