-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsetup.py
131 lines (101 loc) · 3.66 KB
/
setup.py
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# -*- coding: utf-8 -*-
import os
import sys
from setuptools import find_packages
from distutils.command.build_ext import build_ext
from distutils.core import setup
from distutils.extension import Extension
from distutils.version import StrictVersion
from distutils.errors import (CCompilerError, DistutilsExecError,
DistutilsPlatformError)
here = os.path.abspath(os.path.dirname(__file__))
def get_version():
with open(os.path.join(here, 'backpack/version.py')) as f:
variables = {}
exec(f.read(), variables)
version = variables.get('VERSION')
if version:
return version
raise RuntimeError('No version info found.')
__version__ = get_version()
with open('%s/requirements.txt' % here) as f:
requirements = f.readlines()
# Optional C extensions
if sys.platform == 'win32':
build_ext_errors = (CCompilerError, DistutilsExecError,
DistutilsPlatformError, IOError)
else:
build_ext_errors = (CCompilerError, DistutilsExecError,
DistutilsPlatformError)
class BuildExtFailed(Exception):
pass
with_extensions = os.environ.get('BACKPACK_EXTENSIONS', None)
if with_extensions:
if with_extensions.lower() == 'true':
with_extensions = True
elif with_extensions.lower() == 'false':
with_extensions = False
else:
with_extensions = None
if hasattr(sys, 'pypy_version_info'):
with_extensions = False
extensions = (
('backpack.collections._collection', ('backpack/collections/_collection.pyx',
'backpack/collections/_collection.c')),
('backpack._utils._helpers', ('backpack/_utils/_helpers.pyx',
'backpack/_utils/_helpers.c')),
)
ext_modules = None
if with_extensions is True or with_extensions is None:
cython_min = '0.22.1'
try:
from Cython.Distutils import build_ext
from Cython import __version__ as cython_ver
except ImportError:
cython_installed = False
else:
cython_installed = StrictVersion(cython_ver) >= StrictVersion(cython_min)
ext_modules = [Extension(module, [pyx if cython_installed else c], extra_compile_args=['-Wno-unused-function'])
for module, (pyx, c) in extensions]
class optional_build_ext(build_ext):
def run(self):
try:
build_ext.run(self)
except DistutilsPlatformError:
raise BuildExtFailed()
def build_extension(self, ext):
try:
build_ext.build_extension(self, ext)
except build_ext_errors:
raise BuildExtFailed()
setup_kwargs = dict(
name='backpack',
license='MIT',
version=__version__,
description='Useful utilities for Python.',
long_description=open('README.rst').read(),
author='Sébastien Eustace',
author_email='sebastien@eustace.io',
url='https://github.com/sdispater/backpack',
download_url='https://github.com/sdispater/backpack/archive/%s.tar.gz' % __version__,
packages=find_packages(exclude=['tests']),
install_requires=requirements,
tests_require=['pytest'],
test_suite='nose.collector',
classifiers=[
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Software Development :: Libraries :: Python Modules',
],
)
def run_setup(ext_modules=None):
setup_kwargs_tmp = dict(setup_kwargs)
if ext_modules:
setup_kwargs_tmp['ext_modules'] = ext_modules
setup_kwargs_tmp['cmdclass'] = {'build_ext': optional_build_ext}
setup(**setup_kwargs_tmp)
try:
run_setup(ext_modules)
except BuildExtFailed:
run_setup()