forked from Kozea/tinycss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
113 lines (97 loc) · 3.53 KB
/
setup.py
File metadata and controls
113 lines (97 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import re
import sys
import os.path
from setuptools import setup, Extension
from distutils.errors import (
CCompilerError, DistutilsExecError, DistutilsPlatformError)
try:
from Cython.Distutils import build_ext
import Cython.Compiler.Version
CYTHON_INSTALLED = True
except ImportError:
from distutils.command.build_ext import build_ext
CYTHON_INSTALLED = False
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,)
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
ROOT = os.path.dirname(__file__)
with open(os.path.join(ROOT, 'tinycss', 'version.py')) as fd:
VERSION = re.search("VERSION = '([^']+)'", fd.read()).group(1)
with open(os.path.join(ROOT, 'README.rst'), 'rb') as fd:
README = fd.read().decode('utf8')
def run_setup(with_extension):
if with_extension:
extension_path = os.path.join('tinycss', 'speedups')
if CYTHON_INSTALLED:
extension_path += '.pyx'
print('Building with Cython %s.' % Cython.Compiler.Version.version)
else:
extension_path += '.c'
if not os.path.exists(extension_path):
print ("WARNING: Trying to build without Cython, but "
"pre-generated '%s' does not seem to be available."
% extension_path)
else:
print ('Building without Cython.')
kwargs = dict(
cmdclass=dict(build_ext=ve_build_ext),
ext_modules=[Extension('tinycss.speedups',
sources=[extension_path])],
)
else:
kwargs = dict()
setup(
name='tinycss',
version=VERSION,
url='http://packages.python.org/tinycss/',
license='BSD',
author='Simon Sapin',
author_email='simon.sapin@exyr.org',
description='tinycss is a complete yet simple CSS parser for Python.',
long_description=README,
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.1',
'Programming Language :: Python :: 3.2',
],
packages=['tinycss', 'tinycss.tests'],
**kwargs
)
IS_PYPY = hasattr(sys, 'pypy_translation_info')
try:
run_setup(not IS_PYPY)
except BuildFailed:
BUILD_EXT_WARNING = ('WARNING: The extension could not be compiled, '
'speedups are not enabled.')
print('*' * 75)
print(BUILD_EXT_WARNING)
print('Failure information, if any, is above.')
print('Retrying the build without the Cython extension now.')
print('*' * 75)
run_setup(False)
print('*' * 75)
print(BUILD_EXT_WARNING)
print('Plain-Python installation succeeded.')
print('*' * 75)