Repository navigation
Expand file tree
/
Copy pathsetup.py
More file actions
102 lines (92 loc) · 3.55 KB
/
Copy pathsetup.py
File metadata and controls
102 lines (92 loc) · 3.55 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
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
# setup.py
import os
import re
import sys
import platform
import subprocess
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
class CMakeExtension(Extension):
"""
A setuptools.Extension for a CMake‐based build.
`name` must match the module name exposed via PYBIND11_MODULE in c++ code
`sourcedir` points to the directory containing top-level CMakeLists.txt.
"""
def __init__(self, name, sourcedir=""):
super().__init__(name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
class CMakeBuild(build_ext):
"""
Custom build_ext command that invokes CMake to configure & build the native extension.
"""
def run(self):
# 1) Verify CMake is installed
try:
subprocess.check_output(["cmake", "--version"])
except OSError:
raise RuntimeError("CMake must be installed to build the following extensions: " +
", ".join(e.name for e in self.extensions))
# 2) For each CMakeExtension, configure & build
for ext in self.extensions:
self.build_extension(ext)
def build_extension(self, ext):
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
cfg = "Debug" if self.debug else "Release"
# Make sure the extension directory exists
os.makedirs(extdir, exist_ok=True)
# Build directory for CMake out‐of‐source build
build_temp = os.path.join(self.build_temp, ext.name)
os.makedirs(build_temp, exist_ok=True)
# Common CMake arguments
cmake_args = [
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}",
f"-DPython_EXECUTABLE={sys.executable}",
"-DCHRONOGRAPH_BUILD_TESTS=OFF",
"-DCHRONOGRAPH_BUILD_EXAMPLES=OFF",
f"-DCMAKE_BUILD_TYPE={cfg}"
]
# On Windows, specify generator and architecture if needed
build_args = []
if platform.system() == "Windows":
# can override CMAKE_GENERATOR if desired (ninja, visual studio, etc)
cmake_args += [f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}"]
# Example: if you want 64‐bit MSVC: cmake_args += ['-A', 'x64']
build_args += ["--config", cfg]
else:
# On Unix‐like machines, prefer parallel jobs if possible
build_args += ["--", f"-j{os.cpu_count()}"]
# 1) Run CMake configure
subprocess.check_call(
["cmake", ext.sourcedir] + cmake_args,
cwd=build_temp
)
# 2) Run CMake build
subprocess.check_call(
["cmake", "--build", "."] + build_args,
cwd=build_temp
)
version = "0.1.0"
setup(
name="chronograph",
version=version,
author="Jun Simons",
author_email="jdsimons017@gmail.com",
description="ChronoGraph: a temporal & versioned C++ graph library with Git‐style repo support",
long_description="",
license="MIT",
classifiers=[
"Programming Language :: C++",
"Programming Language :: Python",
"License :: OSI Approved :: MIT License"
],
# no pure‐Python modules; extension itself is 'chronograph'
ext_modules=[CMakeExtension("chronograph", sourcedir=".")],
cmdclass={"build_ext": CMakeBuild},
zip_safe=False,
# pure‐Python subpackages would og here (or use packages=find_packages())
packages=[],
install_requires=[
# pure Python runtime dependencies, e.g. "graphviz>=0.20.1"
],
python_requires=">=3.8",
)