-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
119 lines (99 loc) · 3.19 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
#! /usr/bin/env python
import contextlib
import os
import subprocess
import sys
import numpy as np
from numpy.distutils.fcompiler import new_fcompiler
from setuptools import Extension, find_packages, setup
from setuptools.command.build_ext import build_ext as _build_ext
common_flags = {
"include_dirs": [
np.get_include(),
os.path.join(sys.prefix, "include"),
],
"library_dirs": [],
"define_macros": [],
"undef_macros": [],
"extra_compile_args": [],
"language": "c",
}
libraries = []
# Locate directories under Windows %LIBRARY_PREFIX%.
if sys.platform.startswith("win"):
common_flags["include_dirs"].append(os.path.join(sys.prefix, "Library", "include"))
common_flags["library_dirs"].append(os.path.join(sys.prefix, "Library", "lib"))
ext_modules = [
Extension(
"pymt_prms_surface.lib.prmssurface",
["pymt_prms_surface/lib/prmssurface.pyx"],
libraries=libraries + ["bmiprmssurface"],
extra_objects=["pymt_prms_surface/lib/bmi_interoperability.o"],
**common_flags
),
]
entry_points = {
"pymt.plugins": [
"PRMSSurface=pymt_prms_surface.bmi:PRMSSurface",
]
}
@contextlib.contextmanager
def as_cwd(path):
prev_cwd = os.getcwd()
os.chdir(path)
yield
os.chdir(prev_cwd)
def build_interoperability():
compiler = new_fcompiler()
compiler.customize()
cmd = []
cmd.append(compiler.compiler_f90[0])
cmd.append(compiler.compile_switch)
if sys.platform.startswith("win") is False:
cmd.append("-fPIC")
for include_dir in common_flags["include_dirs"]:
if os.path.isabs(include_dir) is False:
include_dir = os.path.join(sys.prefix, "include", include_dir)
cmd.append("-I{}".format(include_dir))
cmd.append("bmi_interoperability.f90")
try:
subprocess.check_call(cmd)
except subprocess.CalledProcessError:
raise
class build_ext(_build_ext):
def run(self):
with as_cwd("pymt_prms_surface/lib"):
build_interoperability()
_build_ext.run(self)
def read(filename):
with open(filename, "r", encoding="utf-8") as fp:
return fp.read()
long_description = u"\n\n".join(
[read("README.rst"), read("CREDITS.rst"), read("CHANGES.rst")]
)
setup(
name="pymt_prms_surface",
author="Community Surface Dynamics Modeling System",
author_email="csdms@colorado.edu",
description="PyMT plugin for prms_surface",
long_description=long_description,
version="0.2.2.dev0",
url="https://github.com/pymt-lab/pymt_prms_surface",
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Operating System :: MacOS :: MacOS X",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
],
keywords=["bmi", "pymt"],
install_requires=open("requirements.txt", "r").read().splitlines(),
setup_requires=["cython"],
ext_modules=ext_modules,
cmdclass=dict(build_ext=build_ext),
packages=find_packages(),
entry_points=entry_points,
include_package_data=True,
)