-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·99 lines (83 loc) · 3.16 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
'''
Copyright (c) Pyaisa 2015 - Alberto Lorenzo (alorenzo.md@gmail.com)
Distributed under the MIT License.
(See accompanying file "copying" or copy at
http://opensource.org/licenses/MIT)
'''
from distutils.core import setup, Extension
from distutils.command.build import build
from distutils.command.build_ext import build_ext
import os
import re
import requests
import numpy
version = '0.8.5'
base_name = 'pyaisa'
# Compiler flags
copt = {'mingw32': ['-fopenmp', '-O3'],
'mingw64': ['-fopenmp', '-O3'],
'cygwin': ['-fopenmp', '-O3'],
'msvc': ['/openmp', '/Ox'],
'unix': ['-fopenmp', '-O3']}
lopt = {'mingw32': ['-lgomp'],
'mingw64': ['-lgomp'],
'cygwin': ['-lgomp'],
'unix': ['-lgomp']}
# Download numpy.i file
np_version = re.compile(r'(?P<MAJOR>[0-9]+)\.'
'(?P<MINOR>[0-9]+)') \
.search(numpy.__version__)
np_version_string = np_version.group()
np_version_info = {key: int(value)
for key, value in np_version.groupdict().items()}
np_file_name = 'numpy.i'
np_file_url = 'https://raw.githubusercontent.com/numpy/numpy/maintenance/' + \
np_version_string + '.x/tools/swig/' + np_file_name
if(np_version_info['MAJOR'] == 1 and np_version_info['MINOR'] < 9):
np_file_url = np_file_url.replace('tools', 'doc')
chunk_size = 8196
with open(np_file_name, 'wb') as file:
for chunk in requests.get(np_file_url,
stream=True).iter_content(chunk_size):
file.write(chunk)
# Build steps must be reordered to include python generated files in the
# final package
class build_subclass(build):
sub_commands = [
('build_ext', build.has_ext_modules),
('build_py', build.has_pure_modules),
('build_clib', build.has_c_libraries),
('build_scripts', build.has_scripts),
]
class build_ext_subclass(build_ext):
def build_extensions(self):
c = self.compiler.compiler_type
if c in copt:
for e in self.extensions:
e.extra_compile_args = copt[c]
if c in lopt:
for e in self.extensions:
e.extra_link_args = lopt[c]
build_ext.build_extensions(self)
# Set up
ext_name = 'isacpp'
ext_folder = os.path.join(base_name, ext_name)
extension = Extension(base_name + '.' + ext_name + '._' + ext_name,
language='c++',
sources=[os.path.join(ext_folder, ext_name + '.i'),
os.path.join(ext_folder, ext_name + '.cpp'),
os.path.join(ext_folder, 'cstmath.cpp')],
swig_opts=['-c++', '-py3', '-I .'],
include_dirs=[numpy.get_include()],)
setup(name=base_name,
version=version,
author='Alberto Lorenzo',
author_email='alorenzo.md@gmail.com',
home_page='https://github.com/newlawrence/Pysapp',
license='MIT',
description='ISA Model computed in C++',
ext_modules=[extension],
cmdclass={'build': build_subclass,
'build_ext': build_ext_subclass},
packages=[base_name, base_name + '.' + ext_name,
base_name + '.' + 'test'])