forked from felixmatt/shyft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
112 lines (96 loc) · 4.09 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
import glob
import os
import platform
import shutil
import subprocess
from os import path
import sys
from setuptools import setup, find_packages
print('Building Shyft')
# VERSION should be set in a previous build step (ex: TeamCity)
if path.exists('VERSION'):
VERSION = open('VERSION').read().strip()
# Create the version.py file
open('shyft/version.py', 'w').write('__version__ = "%s"\n'%VERSION)
else:
from shyft.version import __version__
VERSION = __version__
ext_s = '.pyd' if 'Windows' in platform.platform() else '.so'
ext_names = ['shyft/api/_api' + ext_s,
'shyft/api/pt_gs_k/_pt_gs_k' + ext_s,
'shyft/api/pt_hs_k/_pt_hs_k' + ext_s,
'shyft/api/pt_hps_k/_pt_hps_k' + ext_s,
'shyft/api/pt_ss_k/_pt_ss_k' + ext_s,
'shyft/api/hbv_stack/_hbv_stack' + ext_s]
needs_build_ext = not all([path.exists(ext_name) for ext_name in ext_names])
if needs_build_ext:
print('One or more extension modules needs build, attempting auto build')
if "Windows" in platform.platform():
msbuild_2017 = r'C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\amd64\MSBuild.exe' if 'MSBUILD_2017_PATH' not in os.environ else \
os.environ['MSBUILD_2017_PATH']
if path.exists(msbuild_2017):
msbuild = msbuild_2017
cmd = [msbuild, '/p:Configuration=Release', '/p:Platform=x64', '/p:PlatformToolset=v141', '/p:WindowsTargetPlatformVersion=10.0.16299.0', '/m']
else:
print("Sorry, but this setup only supports ms c++ installed to standard locations")
print(" you can set MSBUILD_2017_PATH specific to your installation and restart.")
exit()
if '--rebuild' in sys.argv:
cmd.append('/t:Rebuild')
sys.argv.remove('--rebuild')
p = subprocess.Popen(cmd,
universal_newlines=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
for line in iter(p.stdout.readline, ''):
print(line.rstrip())
p.wait()
if p.returncode != 0:
print('\nMSBuild FAILED.')
exit()
elif "Linux" in platform.platform():
try:
# For Linux, use the cmake approach for compiling the extensions
print(subprocess.check_output("sh build_api_cmake.sh", shell=True))
except:
print("Problems compiling shyft, try building with the build_api.sh "
"or build_api_cmake.sh (Linux only) script manually...")
exit()
else:
print("Only windows and Linux supported")
exit()
else:
print('Extension modules are already built in place')
# Copy libraries needed to run Shyft
if "Windows" in platform.platform():
lib_dir = os.getenv('SHYFT_DEPENDENCIES', '../shyft_dependencies')
boost_dll = path.join(lib_dir, 'lib', '*.dll')
files = glob.glob(boost_dll)
files = [f for f in files if '-gd-' not in path.basename(f)]
dest_dir = path.join(path.dirname(path.realpath(__file__)), 'shyft', 'lib')
if not path.isdir(dest_dir):
os.mkdir(dest_dir)
for f in files:
shutil.copy2(f, path.join(dest_dir, path.basename(f)))
setup(
name='shyft',
version=VERSION,
author='Statkraft',
author_email='[email protected]',
url='https://github.com/statkraft/shyft',
description='An OpenSource hydrological toolbox',
license='LGPL v3',
packages=find_packages(),
package_data={'shyft': ['api/*.so', 'api/*.pyd', 'api/pt_gs_k/*.pyd', 'api/pt_gs_k/*.so', 'api/pt_hs_k/*.pyd',
'api/pt_hs_k/*.so', 'api/pt_hps_k/*.so', 'api/pt_hps_k/*.pyd', 'api/pt_ss_k/*.pyd', 'api/pt_ss_k/*.so', 'api/hbv_stack/*.pyd', 'api/hbv_stack/*.so',
'tests/netcdf/*', 'lib/*.dll', 'lib/*.so.*']},
entry_points={},
requires=["numpy"],
install_requires=["numpy"],
tests_require=['nose'],
zip_safe=False,
extras_require={
'repositories': ['netcdf4', 'shapely', 'pyyaml', 'six', 'pyproj'],
'notebooks': ['jupyter']
}
)