forked from VVionnet/Windmapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
98 lines (80 loc) · 2.98 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
import os
import subprocess
from setuptools import find_packages
import packaging.version
# replace disutils as it is deprecated
#https://github.com/drgarcia1986/simple-settings/pull/281/commits/41a0584d693a17400a1922821533260750be40fa
_MAP = {
'y': True,
'yes': True,
't': True,
'true': True,
'on': True,
'1': True,
'n': False,
'no': False,
'f': False,
'false': False,
'off': False,
'0': False
}
def strtobool(value):
try:
return _MAP[str(value).lower()]
except KeyError:
raise ValueError('"{}" is not a valid bool value'.format(value))
build_wn = True
try:
build_wn = strtobool(os.environ['BUILD_WINDNINJA'])
except:
build_wn = True
print(f'Build WindNinja? {build_wn}')
def gdal_dependency():
try:
version = subprocess.run(["gdal-config", "--version"], stdout=subprocess.PIPE).stdout.decode()
version = version.replace('\n', '')
gdal_depends = ''
if packaging.version.parse(version) >= packaging.version.parse("3.5.0"):
# >= 3.5 required for this type of gdal python binding install
gdal_depends = f'GDAL[numpy]=={version}.*'
else:
gdal_depends = f'pygdal=={version}.*'
return gdal_depends
except FileNotFoundError as e:
raise(""" ERROR: Could not find the system install of GDAL.
Please install it via your package manage of choice.
""")
setup_requires = []
if build_wn:
from skbuild import setup
from skbuild.exceptions import SKBuildError
from skbuild.cmaker import get_cmake_version
try:
# Add CMake as a build requirement if cmake is not installed or is too low a version
# https://scikit-build.readthedocs.io/en/latest/usage.html#adding-cmake-as-building-requirement-only-if-not-installed-or-too-low-a-version
if packaging.version.parse(get_cmake_version()) < packaging.version.parse("3.16"):
setup_requires.append('cmake')
except SKBuildError:
setup_requires.append('cmake')
else:
from setuptools import setup
args = {'name': 'windmapper',
'version': '2.1.17',
'description': 'Windfield library generation',
'long_description': "Generates windfields",
'author': 'Chris Marsh',
'author_email': 'chris.marsh@usask.ca',
'url': "https://github.com/Chrismarsh/Windmapper",
'include_package_data': True,
'packages': find_packages(where="pysrc"),
'package_dir': {
'': 'pysrc',
},
'scripts': ["windmapper.py", 'scripts/rio_merge.py', "cfg/cli_massSolver.cfg"],
'install_requires': ['numpy', 'scipy', 'elevation', 'pyproj', 'tqdm', 'rasterio', 'mpi4py', 'cloudpickle',
gdal_dependency()],
'setup_requires': setup_requires,
'python_requires': '>=3.6'}
if build_wn:
args['cmake_args'] = ['-DCMAKE_BUILD_TYPE=Release']
setup(**args)