Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 113 lines (97 sloc) 3.619 kb
d2aba83e »
2012-02-18 Initial project structure.
1 import re
9505cc6f »
2012-03-12 Change setup.py to try without Cython and fallback on pure-python
2 import sys
d2aba83e »
2012-02-18 Initial project structure.
3 import os.path
7caeb802 »
2012-03-27 Start the documentation
4 from setuptools import setup, Extension
f900b30d »
2012-03-13 Do not depend on setuptools.
5 from distutils.errors import (
6 CCompilerError, DistutilsExecError, DistutilsPlatformError)
9505cc6f »
2012-03-12 Change setup.py to try without Cython and fallback on pure-python
7 try:
8 from Cython.Distutils import build_ext
9 import Cython.Compiler.Version
10 CYTHON_INSTALLED = True
11 except ImportError:
f900b30d »
2012-03-13 Do not depend on setuptools.
12 from distutils.command.build_ext import build_ext
9505cc6f »
2012-03-12 Change setup.py to try without Cython and fallback on pure-python
13 CYTHON_INSTALLED = False
d2aba83e »
2012-02-18 Initial project structure.
14
15
9505cc6f »
2012-03-12 Change setup.py to try without Cython and fallback on pure-python
16 ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
17 if sys.platform == 'win32' and sys.version_info > (2, 6):
18 # 2.6's distutils.msvc9compiler can raise an IOError when failing to
19 # find the compiler
20 ext_errors += (IOError,)
21
22 class BuildFailed(Exception):
23 pass
24
25 class ve_build_ext(build_ext):
26 # This class allows C extension building to fail.
27
28 def run(self):
29 try:
30 build_ext.run(self)
31 except DistutilsPlatformError:
32 raise BuildFailed
33
34 def build_extension(self, ext):
35 try:
36 build_ext.build_extension(self, ext)
37 except ext_errors:
38 raise BuildFailed
39
40
7caeb802 »
2012-03-27 Start the documentation
41 ROOT = os.path.dirname(__file__)
9d77739d »
2012-04-06 Fix install on ASCII locales.
42 with open(os.path.join(ROOT, 'tinycss', 'version.py')) as fd:
d2aba83e »
2012-02-18 Initial project structure.
43 VERSION = re.search("VERSION = '([^']+)'", fd.read()).group(1)
7caeb802 »
2012-03-27 Start the documentation
44
9d77739d »
2012-04-06 Fix install on ASCII locales.
45 with open(os.path.join(ROOT, 'README.rst'), 'rb') as fd:
46 README = fd.read().decode('utf8')
9505cc6f »
2012-03-12 Change setup.py to try without Cython and fallback on pure-python
47
48
49 def run_setup(with_extension):
50 if with_extension:
51 extension_path = os.path.join('tinycss', 'speedups')
52 if CYTHON_INSTALLED:
53 extension_path += '.pyx'
54 print('Building with Cython %s.' % Cython.Compiler.Version.version)
55 else:
56 extension_path += '.c'
57 if not os.path.exists(extension_path):
58 print ("WARNING: Trying to build without Cython, but "
59 "pre-generated '%s' does not seem to be available."
60 % extension_path)
61 else:
62 print ('Building without Cython.')
63 kwargs = dict(
64 cmdclass=dict(build_ext=ve_build_ext),
65 ext_modules=[Extension('tinycss.speedups',
66 sources=[extension_path])],
67 )
68 else:
69 kwargs = dict()
70
71 setup(
72 name='tinycss',
73 version=VERSION,
743eb3dd »
2012-03-28 Add classifiers for PyPI, set the project URL to docs
74 url='http://packages.python.org/tinycss/',
9505cc6f »
2012-03-12 Change setup.py to try without Cython and fallback on pure-python
75 license='BSD',
76 author='Simon Sapin',
77 author_email='simon.sapin@exyr.org',
7caeb802 »
2012-03-27 Start the documentation
78 description='tinycss is a complete yet simple CSS parser for Python.',
79 long_description=README,
743eb3dd »
2012-03-28 Add classifiers for PyPI, set the project URL to docs
80 classifiers=[
81 'Development Status :: 3 - Alpha',
82 'Intended Audience :: Developers',
83 'License :: OSI Approved :: BSD License',
84 'Programming Language :: Python :: 2',
85 'Programming Language :: Python :: 2.6',
86 'Programming Language :: Python :: 2.7',
87 'Programming Language :: Python :: 3',
88 'Programming Language :: Python :: 3.1',
89 'Programming Language :: Python :: 3.2',
90 ],
f900b30d »
2012-03-13 Do not depend on setuptools.
91 packages=['tinycss', 'tinycss.tests'],
9505cc6f »
2012-03-12 Change setup.py to try without Cython and fallback on pure-python
92 **kwargs
93 )
94
95
96 IS_PYPY = hasattr(sys, 'pypy_translation_info')
97 try:
98 run_setup(not IS_PYPY)
99 except BuildFailed:
100 BUILD_EXT_WARNING = ('WARNING: The extension could not be compiled, '
101 'speedups are not enabled.')
102 print('*' * 75)
103 print(BUILD_EXT_WARNING)
104 print('Failure information, if any, is above.')
105 print('Retrying the build without the Cython extension now.')
106 print('*' * 75)
d2aba83e »
2012-02-18 Initial project structure.
107
9505cc6f »
2012-03-12 Change setup.py to try without Cython and fallback on pure-python
108 run_setup(False)
d2aba83e »
2012-02-18 Initial project structure.
109
9505cc6f »
2012-03-12 Change setup.py to try without Cython and fallback on pure-python
110 print('*' * 75)
111 print(BUILD_EXT_WARNING)
112 print('Plain-Python installation succeeded.')
113 print('*' * 75)
Something went wrong with that request. Please try again.