-
Notifications
You must be signed in to change notification settings - Fork 75
/
setup.py
125 lines (105 loc) · 3.77 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
import glob
import os
import sys
import netgen.version
from skbuild import setup
import skbuild.cmaker
from subprocess import check_output
from distutils.sysconfig import get_python_lib
from urllib.request import urlopen
import json
setup_requires = ['pybind11-stubgen==2.5']
def install_filter(cmake_manifest):
return cmake_manifest
def _patched_parse_manifests(self):
paths = \
glob.glob(os.path.join(skbuild.cmaker.CMAKE_BUILD_DIR(), "ngsolve", "install_manifest*.txt"))
try:
return [self._parse_manifest(path) for path in paths][0]
except IndexError:
return []
# we are using the ngsolve superbuild (to download and build some dependencies)
# patch the parse_manifests function to point to the actual ngsolve cmake project within the superbuild
skbuild.cmaker.CMaker._parse_manifests = _patched_parse_manifests
version = check_output([sys.executable,'tests/get_python_version_string_from_git.py'], cwd='.').decode('utf-8').strip()
# check if release alread exists on pypi
try:
python_version = f"cp{sys.version_info.major}{sys.version_info.minor}"
platform = sys.platform
if platform == 'darwin':
platform = 'macosx'
url = f"https://pypi.org/pypi/ngsolve/{version}/json"
data = json.loads(urlopen(url).read())
for url in data['urls']:
if platform in url['filename'] and url['python_version'] == python_version:
print("version already exists on pypi, skip build")
sys.exit()
except:
pass
py_install_dir = get_python_lib(1,0,'').replace('\\','/')
netgen_name = netgen.config.NETGEN_PYTHON_PACKAGE_NAME
name = netgen_name.replace("netgen-mesher", "ngsolve") # keep -avx2 suffix
netgen_version = netgen.config.NETGEN_VERSION_PYTHON
root_dir = os.path.abspath(os.path.join(netgen.__file__, '../'*(len(py_install_dir.split('/'))+2)))
if netgen.config.NG_INSTALL_DIR_CMAKE.startswith('netgen'):
netgen_dir = os.path.abspath(os.path.join(os.path.dirname(netgen.__file__), 'cmake'))
else:
netgen_dir = root_dir
install_requires = [
f'{netgen_name} == {netgen_version}',
]
use_umfpack = 'ON' if 'darwin' in sys.platform else 'OFF'
_cmake_args = [
f'-DNETGEN_DIR={netgen_dir}',
'-DUSE_SUPERBUILD:BOOL=ON',
'-DCMAKE_BUILD_TYPE=Release',
'-DBUILD_FOR_CONDA=ON',
f'-DUSE_UMFPACK={use_umfpack}',
f'-DNGSOLVE_VERSION_PYTHON={version}',
]
if 'NETGEN_CCACHE' in os.environ:
_cmake_args += ['-DUSE_CCACHE=ON']
packages=['netgen', 'ngsolve']
if 'darwin' in sys.platform:
_cmake_args += [
'-DBUILD_STUB_FILES=ON',
]
elif 'linux' in sys.platform:
_cmake_args += [
'-DUSE_MKL:BOOL=ON',
f'-DMKL_ROOT:PATH={root_dir}',
f'-DMKL_LIBRARY:PATH={root_dir}/lib/libmkl_rt.so.2',
f'-DMKL_INCLUDE_DIR:PATH={root_dir}/include',
'-DUSE_CUDA=ON',
'-DCMAKE_CUDA_ARCHITECTURES=all',
'-DBUILD_STUB_FILES=ON',
]
install_requires.append('mkl')
packages = []
elif 'win' in sys.platform:
_cmake_args += [
'-DUSE_MKL:BOOL=ON',
f'-DMKL_ROOT:PATH={root_dir}',
f'-DMKL_LIBRARY:PATH={root_dir}/Library/lib/mkl_rt.lib',
f'-DMKL_INCLUDE_DIR:PATH={root_dir}/Library/include',
f'-DNGSOLVE_INSTALL_DIR_TCL:PATH=Scripts',
'-DBUILD_STUB_FILES=OFF',
]
install_requires.append('mkl')
if 'PYDIR' in os.environ:
_cmake_args += [f'-DCMAKE_PREFIX_PATH={os.environ["PYDIR"]}']
setup(
name=name,
version=version,
description="NGSolve",
author='The NGSolve team',
license="LGPL2.1",
packages=packages,
# package_dir={'ngsolve': 'python'},
install_requires=install_requires,
tests_require=['pytest','scipy','numpy'],
# include_package_data=True,
cmake_process_manifest_hook=install_filter,
cmake_args=_cmake_args,
setup_requires=setup_requires
)