-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.py
executable file
·141 lines (124 loc) · 4.55 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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
Python wrapper for SIR
"""
from distutils.ccompiler import CCompiler
from distutils.errors import DistutilsExecError, CompileError
from distutils.unixccompiler import UnixCCompiler
from setuptools import find_packages, setup
from setuptools.extension import Extension
import os
import platform
from subprocess import Popen, PIPE
import sys
import numpy
import glob
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
compiler_so = self.compiler_so
arch = platform.architecture()[0].lower()
if (ext == ".f" or ext == ".f90"):
if sys.platform == 'darwin' or sys.platform.startswith('linux'):
compiler_so = [os.environ['FC']]
if (ext == ".f90"):
cc_args = ["-O3", "-fPIC", "-c", "-ffree-form", "-ffree-line-length-none"]
if (ext == ".f"):
cc_args = ["-O3", "-fPIC", "-c", "-fno-automatic", "-ffixed-line-length-none"]
# Force architecture of shared library.
if arch == "32bit":
cc_args.append("-m32")
elif arch == "64bit":
cc_args.append("-m64")
else:
print("\nPlatform has architecture '%s' which is unknown to "
"the setup script. Proceed with caution\n" % arch)
try:
self.spawn(compiler_so + cc_args + [src, '-o', obj] +
extra_postargs)
except DistutilsExecError as msg:
raise CompileError(msg)
UnixCCompiler._compile = _compile
# Hack to prevent build_ext from trying to append "init" to the export symbols.
class finallist(list):
def append(self, object):
return
class MyExtension(Extension):
def __init__(self, *args, **kwargs):
Extension.__init__(self, *args, **kwargs)
self.export_symbols = finallist(self.export_symbols)
def get_libgfortran_dir():
"""
Helper function returning the library directory of libgfortran. Useful
on OSX where the C compiler oftentimes has no knowledge of the library
directories of the Fortran compiler. I don't think it can do any harm on
Linux.
"""
for ending in [".3.dylib", ".dylib", ".3.so", ".so"]:
try:
p = Popen(['gfortran', "-print-file-name=libgfortran" + ending],
stdout=PIPE, stderr=PIPE)
p.stderr.close()
line = p.stdout.readline().decode().strip()
p.stdout.close()
if os.path.exists(line):
return [os.path.dirname(line)]
except:
continue
return []
# Monkey patch the compilers to treat Fortran files like C files.
CCompiler.language_map['.f90'] = "c"
UnixCCompiler.src_extensions.append(".f90")
CCompiler.language_map['.f'] = "c"
UnixCCompiler.src_extensions.append(".f")
# with open("VERSION.txt", "rt") as fh:
# VERSION = fh.read().strip()
DOCSTRING = __doc__.strip().split("\n")
pathGlobal = "pysir/src/"
listFiles = glob.glob(pathGlobal+'*.f*')
listFiles.append(pathGlobal+'pysir.pyx')
libSIR = MyExtension('pysir.pysir',
libraries=["gfortran"],
library_dirs=get_libgfortran_dir(),
sources=listFiles,
include_dirs=[numpy.get_include()])
setup_config = dict(
name='pysir',
version='1.0',
description=DOCSTRING[0],
long_description="\n".join(DOCSTRING[2:]),
author=' A. Asensio Ramos',
author_email='aasensio@iac.es',
url='https://github.com/aasensio/pyiacsun',
license='GNU General Public License, version 3 (GPLv3)',
platforms='OS Independent',
install_requires=[
'numpy',
],
ext_modules=[libSIR],
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Console',
'Intended Audience :: Science/Research',
'Intended Audience :: Developers',
"Operating System :: Unix",
"Operating System :: POSIX",
"Operating System :: MacOS",
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Programming Language :: Python',
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: Implementation :: CPython",
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Physics',
],
keywords=['SIR', 'radiative transfer'],
packages=find_packages(),
zip_safe=False,
include_package_data=True,
package_data = {'pySIR': [os.path.join('data', '*')]}
)
if __name__ == "__main__":
setup(**setup_config)
try:
os.remove("sirmod.mod")
except:
pass