-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
93 lines (76 loc) · 3.23 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
import os
import sys
import subprocess
import multiprocessing
from pathlib import Path
from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext
__version__ = "0.0.19"
HERE = Path(__file__).resolve().parent
# A CMakeExtension needs a sourcedir instead of a file list.
# The name must be the _single_ output extension from the CMake build.
# If you need multiple extensions, see scikit-build.
class CMakeExtension(Extension):
def __init__(self, name, sourcedir=""):
Extension.__init__(self, name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
class CMakeBuild(build_ext):
def build_extension(self, ext):
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
# required for auto-detection of auxiliary "native" libs
if not extdir.endswith(os.path.sep):
extdir += os.path.sep
build_type = "Debug" if os.environ.get('PYWL_DEBUG_BUILD') else "Release"
print("Pywl build type:", build_type)
temp_directory = Path.cwd() / self.build_temp
# Create the temporary build directory, if it does not already exist
os.makedirs(temp_directory, exist_ok=True)
# Build dependencies
subprocess.run(
["cmake", "-S", f"{ext.sourcedir}/dependencies", "-B", f"{str(temp_directory)}/dependencies/build", f"-DCMAKE_INSTALL_PREFIX={str(temp_directory)}/dependencies/installs"], cwd=str(temp_directory), check=True
)
subprocess.run(
["cmake", "--build", f"{str(temp_directory)}/dependencies/build", f"-j{multiprocessing.cpu_count()}"]
)
# Build dlplan
cmake_args = [
"-DBUILD_PYKWL=On",
f"-DWL_VERSION_INFO={__version__}",
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}",
f"-DPYTHON_EXECUTABLE={sys.executable}",
f"-DCMAKE_BUILD_TYPE={build_type}", # not used on MSVC, but no harm
f"-DCMAKE_PREFIX_PATH={str(temp_directory)}/dependencies/installs"
]
build_args = []
build_args += ["--target", ext.name]
subprocess.run(
["cmake", "-S", ext.sourcedir, "-B", f"{str(temp_directory)}/build"] + cmake_args, cwd=str(temp_directory), check=True
)
subprocess.run(
["cmake", "--build", f"{str(temp_directory)}/build", f"-j{multiprocessing.cpu_count()}"] + build_args, cwd=str(temp_directory), check=True
)
# The information here can also be placed in setup.cfg - better separation of
# logic and declaration, and simpler if you include description/version in a file.
setup(
name="pykwl",
version=__version__,
author="Simon Stahlberg, Dominik Drexler",
author_email="[email protected],[email protected]",
url="https://github.com/drexlerd/Weisfeiler-Leman",
description="Weisfeiler-Leman library",
long_description="",
install_requires=["cmake>=3.21"],
packages=find_packages(where="python/src"),
package_dir={"": "python/src"},
package_data={
"": ["*.pyi"],
},
ext_modules=[CMakeExtension("_pykwl")],
cmdclass={"build_ext": CMakeBuild},
zip_safe=False,
extras_require={
'test': [
'pytest',
],
}
)