-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
159 lines (132 loc) · 5.31 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
# -*- coding: utf-8 -*-
# This file is part of pypolsys, A python wrapper to `POLSYS_PLP`
# fortran90 package from Layne T. Watson, Steven M. Wise,
# Andrew J. Sommese, August, 1998.
# pypolsys is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# pypolsys is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with pypolsys. If not, see <https://www.gnu.org/licenses/>.
"""
# pypolsys setup.
Define the fortran extension and its dependancies.
pypolsys can be either:
- linked to lapack/blas (default on linux)
- build with `POLSYS_PLP` lapack sources (default on windows)
The behavior can be specified with the install/developp flag `--buildLapack`
"""
import setuptools
import platform
import sys
import os
# Usefull to build f90 files
from numpy.distutils.core import Extension, setup
# To setup user options
from setuptools.command.install import install
from setuptools.command.develop import develop
# Use standard lib distutils for sdist (see numpy issues 7127)
from distutils.command.sdist import sdist
class UserOptionCommand(object):
""" Mixin class to add user option support.
based on https://stackoverflow.com/questions/18725137/how-to-obtain-arguments-passed-to-setup-py-from-pip-with-install-option
"""
# Other options may be added here
user_options = [
('buildLapack', None, 'Provide the required lapack/blas sources and build it.')]
def initialize_options(self):
"""Initialize default options."""
super().initialize_options()
self.buildLapack = None
def finalize_options(self):
"""Validate options."""
# Nothing to do here
super().finalize_options()
def run(self):
"""Use options."""
print('> Building with lapackBuild =', buildLapack)
super().run()
# Update setuptool classes
class InstallCommand(UserOptionCommand, install):
user_options = getattr(install, 'user_options', []) + UserOptionCommand.user_options
class DevelopCommand(UserOptionCommand, develop):
user_options = getattr(develop, 'user_options', []) + UserOptionCommand.user_options
def ext_wrapper(buildLapack):
""" Configure the fortran POLSYS_PLP extension.
"""
# Base files
sources = ['pypolsys/src/polsys.pyf',
'pypolsys/801/polsys_plp.f90',
'pypolsys/src/wrapper.f90']
# Configure the POLSYS_PLP Extension building
if buildLapack == 1:
# Add lapack_plp to sources
sources.append('pypolsys/801/lapack_plp.f')
extra_link_args = []
else:
# Link to system lapack/blas
extra_link_args = ['-llapack', '-lblas']
return Extension(name='pypolsys.polsys',
sources=sources,
extra_compile_args=['-O3',
'-ffast-math',
'-funroll-loops'], # "-fopenmp"
extra_link_args=extra_link_args) # "-lgomp")
# Load README
with open("README.md", "r") as fh:
long_description = fh.read()
# Load version
def version():
""" Get version from version.py."""
v = None
with open(os.path.join('./pypolsys', 'version.py')) as f:
for line in f:
if line.lstrip().startswith('__version__'):
v = line.split('=')[-1].strip().replace("'", "").replace('"', "")
break
return v
# Check platerform and options
buildLapack = None
if '--buildLapack' in sys.argv:
buildLapack = 1
# On windows, by default, we used the lapack version shipped with POLSYS_PLP
this_os = platform.system().lower()
if this_os == 'windows':
buildLapack = 1
print('> Building plateform =', this_os)
print('> Building with lapackBuild =', buildLapack)
# Fill setuptools
setup(
name="pypolsys",
version=version(),
author="B. Nennig",
author_email="[email protected]",
description=r"A python wrapper to `POLSYS_PLP` fortran90 package from Layne T. Watson,\
Steven M. Wise, Andrew J. Sommese, August, 1998.",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/nennigb/pypolsys",
# Use find_packages() to automatically discover all packages and subpackages
packages=setuptools.find_packages(),
include_package_data=True,
package_data={'pypolsys': ['examples/data/*.npz']},
# build f90 module
ext_modules=[ext_wrapper(buildLapack)],
install_requires=['numpy', 'scipy', 'sympy', 'setuptools'],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: OS Independent"],
# tested with python 3.5 may works with previous py3 version...
python_requires='>=3.5',
# pass modified install and develop class to support user options
cmdclass={
'install': InstallCommand,
'develop': DevelopCommand,
'sdist': sdist,
}
)