-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathsetup.py.in
More file actions
executable file
·105 lines (89 loc) · 3.06 KB
/
Copy pathsetup.py.in
File metadata and controls
executable file
·105 lines (89 loc) · 3.06 KB
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
import numpy
import os
import shutil
import glob
from setuptools import setup, Extension
from setuptools.command.build_py import build_py as _build_py
include_dirs = [numpy.get_include(),"include","include/cdTime"]
library_dirs = [ os.path.join("@prefix@","lib") ,'.']
include_dirs.append(os.path.join("@prefix@","include"))
libraries = []
link_args = []
for st in ["@NCLDFLAGS@", "@NCCFLAGS@",
"@UDUNITS2FLAGS@", "@UDUNITS2LDFLAGS@",
"@JSONCFLAGS@", "@JSONCLDFLAGS@",
"@UUIDFLAGS@", "@UUIDLDFLAGS@"]:
sp = st.strip().split()
for s in sp:
if s[:2]=='-L':
library_dirs.append(s[2:])
if s[:2]=='-l':
libraries.append(s[2:])
if s[:2]=='-I':
include_dirs.append(s[2:])
if s[:4]=='-Wl,':
link_args.append(s)
srcfiles = "@LIBSOURCES@".split()
macros=[]
for m in "@MACROS@".split():
macros.append((m[2:],None))
ld =[]
for p in library_dirs:
if os.path.exists(p):
ld.append(p)
library_dirs=ld
ld =[]
for p in include_dirs:
if os.path.exists(p):
ld.append(p)
include_dirs=ld
print('Setting up python module with:')
print('libraries:',libraries)
print('libdir:',library_dirs)
print('incdir',include_dirs)
print('src:',srcfiles)
print('macros:',macros)
class build_py(_build_py):
def run(self):
self._cmor_udunits_output = []
super().run()
xml_source = os.environ.get("CMOR_UDUNITS2_XML")
if not xml_source:
return
if not os.path.isfile(xml_source):
raise RuntimeError(f"CMOR_UDUNITS2_XML does not exist: {xml_source}")
target_dir = os.path.join(self.build_lib, "cmor", "data")
os.makedirs(target_dir, exist_ok=True)
for source_path in sorted(glob.glob(os.path.join(os.path.dirname(xml_source), "udunits2*.xml"))):
target_path = os.path.join(target_dir, os.path.basename(source_path))
shutil.copy2(source_path, target_path)
self._cmor_udunits_output.append(target_path)
def get_outputs(self, include_bytecode=1):
outputs = super().get_outputs(include_bytecode=include_bytecode)
xml_outputs = getattr(self, "_cmor_udunits_output", [])
outputs.extend(xml_outputs)
return outputs
setup (name = "CMOR",
version='@CMOR_PYTHON_PACKAGE_VERSION@',
author='Chris Mauzey, LLNL',
description = "Python Interface to CMOR output library",
url = "https://cmor.llnl.gov/",
zip_safe=False,
install_requires = ['numpy'],
packages = ['cmor', 'cmor.Test'],
package_dir = {'cmor': 'Lib', 'cmor.Test':'Test'},
package_data = {'cmor': ['data/*.xml']},
cmdclass = {'build_py': build_py},
# scripts=['scripts/PrePARE.py' ],
ext_modules = [
Extension('cmor._cmor',
srcfiles,
include_dirs = include_dirs,
library_dirs = library_dirs,
libraries = libraries,
define_macros = macros,
extra_compile_args = [ "-DgFortran"],
extra_link_args = link_args
),
]
)