forked from serge-sans-paille/pythran
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
183 lines (152 loc) · 6.26 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
from __future__ import print_function
# Preliminary checks that cannot be done by setuptools
# like... the setuptools dependency itself!
try:
import setuptools
except ImportError:
print()
print("*****************************************************")
print("* Setuptools must be installed before running setup *")
print("*****************************************************")
print()
raise
from setuptools.command.build_py import build_py
from setuptools.command.develop import develop
from setuptools import setup
from distutils import ccompiler
from distutils.errors import CompileError, LinkError
import logging
import glob
import os
import re
import shutil
from tempfile import NamedTemporaryFile
import sys
# It appears old versions of setuptools are not supported, see
# https://github.com/serge-sans-paille/pythran/issues/489
from distutils.version import LooseVersion
MinimalSetuptoolsVersion = LooseVersion("12.0.5")
if LooseVersion(setuptools.__version__) < MinimalSetuptoolsVersion:
msg = "Setuptools version is {}, but must be at least {}".format(
setuptools.__version__,
MinimalSetuptoolsVersion)
print()
print("*" * (len(msg) + 4))
print("*", msg, "*")
print("*" * (len(msg) + 4))
print()
raise ImportError("setuptools")
if sys.version_info.major < 3:
print()
print("************************************************")
print("* Python 2 is getting closer to end-of-support *")
print("************************************************")
print("* *")
print("* Pythran follows https://python3statement.org *")
print("* *")
print("************************************************")
print()
logger = logging.getLogger("pythran")
logger.addHandler(logging.StreamHandler())
versionfile = os.path.join('pythran', 'version.py')
exec(open(versionfile).read())
class BuildWithThirdParty(build_py):
"""
Set up Pythran dependencies.
* install boost dependencies
* install xsimd dependencies
"""
third_parties = 'boost', 'xsimd'
user_options = build_py.user_options + [
('no-{}'.format(pkg), None, 'Do not distribute {} headers'.format(pkg))
for pkg in third_parties
]
def initialize_options(self):
build_py.initialize_options(self)
for pkg in BuildWithThirdParty.third_parties:
setattr(self, 'no_' + pkg, None)
def copy_pkg(self, pkg, src_only=False):
"Install boost deps from the third_party directory"
if getattr(self, 'no_' + pkg) is None:
print('Copying', pkg, 'dependencies')
to_copy = pkg,
else:
return
src = os.path.join('third_party', *to_copy)
# copy to the build tree
if not src_only:
target = os.path.join(self.build_lib, 'pythran', *to_copy)
shutil.rmtree(target, True)
shutil.copytree(src, target)
# copy them to the source tree too, needed for sdist
target = os.path.join('pythran', *to_copy)
shutil.rmtree(target, True)
shutil.copytree(src, target)
def run(self, *args, **kwargs):
# regular build done by parent class
build_py.run(self, *args, **kwargs)
if not self.dry_run: # compatibility with the parent options
for pkg in BuildWithThirdParty.third_parties:
self.copy_pkg(pkg)
class DevelopWithThirdParty(develop, BuildWithThirdParty):
def initialize_options(self):
develop.initialize_options(self)
BuildWithThirdParty.initialize_options(self)
def run(self, *args, **kwargs):
if not self.dry_run: # compatibility with the parent options
for pkg in BuildWithThirdParty.third_parties:
self.copy_pkg(pkg, src_only=True)
develop.run(self, *args, **kwargs)
# Cannot use glob here, as the files may not be generated yet
boost_headers = ['boost/' + '*/' * i + '*.hpp' for i in range(1, 20)]
xsimd_headers = ['xsimd/' + '*/' * i + '*.hpp' for i in range(1, 20)]
pythonic_headers = ['*/' * i + '*.hpp' for i in range(9)] + ['patch/*']
sfmt_headers = ['sfmt/*.h', 'sfmt/*.c']
# read longdescr from README
def longdescr(readme_path):
with open(readme_path) as readme:
lines = list(readme)
start_index = lines.index('What is it?\n')
stop_index = lines.index('Installation\n')
long_description = "".join(lines[start_index + 2: stop_index])
return long_description
setup(name='pythran',
version=__version__,
description=__descr__,
long_description=longdescr("README.rst"),
author='Serge Guelton',
author_email='[email protected]',
url=__url__,
packages=['pythran', 'pythran.analyses', 'pythran.transformations',
'pythran.optimizations', 'omp', 'pythran/pythonic',
'pythran.types'],
package_data={'pythran': ['pythran*.cfg'] + boost_headers + xsimd_headers + sfmt_headers,
'pythran/pythonic': pythonic_headers},
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Operating System :: MacOS',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: C++',
'Topic :: Software Development :: Compilers',
'Topic :: Software Development :: Code Generators'
],
license="BSD 3-Clause",
install_requires=open('requirements.txt').read().splitlines(),
entry_points={'console_scripts':
['pythran = pythran.run:run',
'pythran-config = pythran.config:run']},
setup_requires=["pytest-runner"],
tests_require=['pytest', 'flake8'],
extras_require={
'doc': open('docs/requirements.txt').read().splitlines(),
},
test_suite="pythran.tests.test_cases",
cmdclass={'build_py': BuildWithThirdParty,
'develop': DevelopWithThirdParty})