-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.py
executable file
·165 lines (156 loc) · 6.88 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
from distutils.cmd import Command
from numpy.distutils.core import setup, Extension
import glob
import os
import sys
# ----------------------------------------------------------------------------------------
# Definitions
# ----------------------------------------------------------------------------------------
VERSION = '1.1.0'
# ----------------------------------------------------------------------------------------
# Define Fortran compiler options for supported compilers
# ----------------------------------------------------------------------------------------
gnu_f77_flags = ["-O3",
"-g",
"-fbacktrace",
"-fd-lines-as-comments",
"-ffixed-form",
"-fautomatic",
"-finit-integer=0",
"-finit-real=zero",
"-finit-logical=false"]
gnu_f90_flags = ["-O3",
"-g",
"-fbacktrace",
"-fautomatic",
"-finit-integer=0",
"-finit-real=zero",
"-finit-logical=false"]
intel_f77_flags = ["-O3",
"-g",
"-traceback",
"-nofree",
"-integer-size","32",
"-real-size","32",
"-auto",
"-fpscomp","logicals",
"-fp-model=strict",
"-assume","byterecl",
"-xHost",
"-align","array64byte",
"-assume","buffered_io"]
intel_f90_flags = ["-O3",
"-g",
"-traceback",
"-integer-size","32",
"-real-size","32",
"-auto",
"-fpscomp","logicals",
"-fp-model=strict",
"-assume","byterecl",
"-xHost",
"-align","array64byte",
"-assume","buffered_io"]
# ----------------------------------------------------------------------------------------
# Write version info
# ----------------------------------------------------------------------------------------
def write_version_file(filename='pytdlpack/version.py'):
cnt = """
# THIS FILE IS GENERATED FROM PYTDLPACK SETUP.PY
version = '%(version)s'
"""
a = open(filename,'w')
try:
a.write(cnt % {'version': VERSION})
finally:
a.close()
# ----------------------------------------------------------------------------------------
# Define Fortran compiler flags for GNU and Intel Fortran
# ----------------------------------------------------------------------------------------
f77_flags = gnu_f77_flags
f90_flags = gnu_f90_flags
try:
if 'gfortran' in os.environ['FC']:
f77_flags = gnu_f77_flags
f90_flags = gnu_f90_flags
elif 'ifort' in os.environ['FC']:
f77_flags = intel_f77_flags
f90_flags = intel_f90_flags
except(KeyError):
pass # Default to GNU Fortran
if "build" in sys.argv:
if "--fcompiler=gnu95" in sys.argv:
f77_flags = gnu_f77_flags
f90_flags = gnu_f90_flags
elif "--fcompiler=intelem" in sys.argv:
f77_flags = intel_f77_flags
f90_flags = intel_f90_flags
# ----------------------------------------------------------------------------------------
# Define Extension object. For Fortran 77 source files, use "extra_f77_compile_args".
# For Fortran 90+ source files, use "extra_f90_compile_args".
# ----------------------------------------------------------------------------------------
f77_sources = glob.glob("tdlpack/*.f")
f90_sources = glob.glob("tdlpack/*.f90")
all_sources = ["tdlpack/tdlpack.pyf"]+f77_sources+f90_sources
ext = Extension(name = 'tdlpack',
sources = all_sources,
extra_f77_compile_args = f77_flags,
extra_f90_compile_args = f90_flags
)
# ----------------------------------------------------------------------------------------
# Define testing class
# ----------------------------------------------------------------------------------------
class TestCommand(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import sys, subprocess
for f in os.listdir('./test/'):
raise SystemExit(subprocess.call([sys.executable,'./test/'+f]))
# ----------------------------------------------------------------------------------------
# Rewrite the version file everytime
# ----------------------------------------------------------------------------------------
write_version_file()
# ----------------------------------------------------------------------------------------
# Import README.md as PyPi long_description
# ----------------------------------------------------------------------------------------
this_directory = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(this_directory, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
# ----------------------------------------------------------------------------------------
# Run setup
# ----------------------------------------------------------------------------------------
setup(name = 'pytdlpack',
author = "Eric Engle",
author_email = "[email protected]",
url = "https://github.com/eengl/pytdlpack",
download_url = "https://github.com/eengl/pytdlpack/releases",
version = VERSION,
description = "Python interface for reading and writing TDLPACK data",
license = 'GPL-3.0',
ext_modules = [ext],
py_modules = ['TdlpackIO','TdlpackBackend'],
entry_points = {'xarray.backends': 'tdlpack = TdlpackBackend:TdlpackBackendEntrypoint'},
packages = ['pytdlpack'],
cmdclass = {'test':TestCommand},
classifiers = ['Development Status :: 5 - Production/Stable',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Environment :: Console',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Atmospheric Science',
'Intended Audience :: Science/Research',
'Operating System :: OS Independent',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)'],
install_requires = ['numpy>=1.12'],
python_requires = '>=3.6',
long_description = long_description,
long_description_content_type = 'text/markdown'
)