in setup.py [0:0]
def build_extension(self, ext):
source_path = pathlib.Path(__file__).parent.resolve()
output_path = (
pathlib.Path(self.get_ext_fullpath(ext.name))
.parent.joinpath("libtorchbeast")
.resolve()
)
os.makedirs(self.build_temp, exist_ok=True)
build_type = "Debug" if self.debug else "Release"
generator = "Ninja" if spawn.find_executable("ninja") else "Unix Makefiles"
cmake_cmd = [
"cmake",
str(source_path),
"-G%s" % generator,
"-DPYTHON_SRC_PARENT=%s" % source_path,
"-DPYTHON_EXECUTABLE=%s" % sys.executable,
"-DPYTHON_INCLUDE_DIR=%s" % sysconfig.get_python_inc(),
"-DPYTHON_LIBRARY=%s" % sysconfig.get_config_var("LIBDIR"),
"-DCMAKE_BUILD_TYPE=%s" % build_type,
"-DCMAKE_INSTALL_PREFIX=%s" % sys.base_prefix,
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=%s" % output_path,
]
build_cmd = ["cmake", "--build", ".", "--parallel"]
install_cmd = build_cmd + ["--target", "install"]
try:
subprocess.check_call(cmake_cmd, cwd=self.build_temp)
subprocess.check_call(build_cmd, cwd=self.build_temp)
subprocess.check_call(install_cmd, cwd=self.build_temp)
except subprocess.CalledProcessError:
# Don't obscure the error with a setuptools backtrace.
sys.exit(1)