-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
55 lines (45 loc) · 1.75 KB
/
setup.py
File metadata and controls
55 lines (45 loc) · 1.75 KB
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
import os
import sys
import shutil
import glob
from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext
class CMakeExtension(Extension):
def __init__(self, name, sourcedir=""):
super().__init__(name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
class CMakeBuild(build_ext):
def build_extension(self, ext):
build_temp = os.path.abspath(self.build_temp)
build_lib = os.path.abspath(self.build_lib)
# Run CMake build
os.makedirs(build_temp, exist_ok=True)
self.spawn(["cmake", ext.sourcedir, "-B", build_temp])
self.spawn(["cmake", "--build", build_temp, "--target", "cxx_utils"])
# Dynamically find the compiled shared library
matches = glob.glob(
os.path.join(ext.sourcedir, "src", "pyclassify", "cxx_utils*.so")
)
if not matches:
raise RuntimeError(
"Could not find compiled cxx_utils shared library in expected location."
)
src_lib = os.path.abspath(matches[0])
dst_lib = os.path.join(build_lib, "pyclassify", os.path.basename(src_lib))
os.makedirs(os.path.dirname(dst_lib), exist_ok=True)
shutil.copy(src_lib, dst_lib)
setup(
name="pyclassify",
version="0.0.1",
author="Gaspare Li Causi, Lorenzo Tomada",
author_email="[email protected], [email protected]",
description="Final project",
long_description="Eigenvalue computation",
ext_modules=[CMakeExtension("pyclassify.cxx_utils")],
packages=find_packages(where="src/"),
package_dir={"": "src/"},
package_data={"pyclassify": ["cxx_utils*.so"]},
include_package_data=True,
cmdclass={"build_ext": CMakeBuild},
zip_safe=False,
)