forked from lab-cosmo/mops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
82 lines (67 loc) · 2.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
import os
import subprocess
import sys
from setuptools import Extension, setup
from setuptools.command.bdist_egg import bdist_egg
from setuptools.command.build_ext import build_ext
ROOT = os.path.realpath(os.path.dirname(__file__))
class cmake_ext(build_ext):
"""Build the native library using cmake"""
def run(self):
source_dir = os.path.join(ROOT, "mops")
build_dir = os.path.join(ROOT, "build", "python")
install_dir = os.path.join(os.path.realpath(self.build_lib), "mops")
os.makedirs(build_dir, exist_ok=True)
cmake_options = [
"-DCMAKE_BUILD_TYPE=Release",
"-DBUILD_SHARED_LIBS=ON",
f"-DCMAKE_INSTALL_PREFIX={install_dir}",
]
subprocess.run(
["cmake", source_dir, *cmake_options],
cwd=build_dir,
check=True,
)
subprocess.run(
[
"cmake",
"--build",
build_dir,
"--config",
"Release",
"--target",
"install",
],
check=True,
)
class bdist_egg_disabled(bdist_egg):
"""Disabled version of bdist_egg
Prevents setup.py install performing setuptools' default easy_install,
which it should never ever do.
"""
def run(self):
sys.exit(
"Aborting implicit building of eggs.\nUse `pip install .` or "
"`python -m build --wheel . && pip install dist/mops-*.whl` "
"to install from source."
)
if __name__ == "__main__":
with open(os.path.join(ROOT, "mops", "VERSION")) as fd:
version = fd.read().strip()
setup(
version=version,
ext_modules=[
Extension(name="mops", sources=[]),
],
cmdclass={
"build_ext": cmake_ext,
"bdist_egg": bdist_egg if "bdist_egg" in sys.argv else bdist_egg_disabled,
},
package_data={
"mops": [
"mops/bin/*",
"mops/lib/*",
"mops/include/*",
]
},
)