mirror of
https://github.com/apache/arrow.git
synced 2026-10-29 00:56:31 +08:00
setup.py for plasma
This commit is contained in:
1 parent
066d0ea533
commit
cba92c1059
1 file changed
+85
-25
+85
-25
@@ -17,38 +17,98 @@
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
from setuptools import setup, find_packages, Distribution
|
||||
import setuptools.command.build_ext as _build_ext
|
||||
from distutils import sysconfig
|
||||
|
||||
class build_ext(_build_ext.build_ext):
|
||||
def run(self):
|
||||
# Ideally, we could include these files by putting them in a MANIFEST.in or
|
||||
# using the package_data argument to setup, but the MANIFEST.in gets
|
||||
# applied at the very beginning when setup.py runs before these files have
|
||||
# been created, so we have to move the files manually.
|
||||
for filename in files_to_include:
|
||||
self.move_file(filename)
|
||||
def run(self):
|
||||
self._run_cmake()
|
||||
|
||||
def move_file(self, filename):
|
||||
# TODO(rkn): This feels very brittle. It may not handle all cases. See
|
||||
# https://github.com/apache/arrow/blob/master/python/setup.py for an
|
||||
# example.
|
||||
source = filename
|
||||
destination = os.path.join(self.build_lib, "plasma.cpython-36m-x86_64-linux-gnu.so")
|
||||
print("XXX build_lib is ", self.build_lib)
|
||||
# Create the target directory if it doesn't already exist.
|
||||
parent_directory = os.path.dirname(destination)
|
||||
if not os.path.exists(parent_directory):
|
||||
os.makedirs(parent_directory)
|
||||
print("Copying {} to {}.".format(source, destination))
|
||||
# shutil.copy(source, destination)
|
||||
shutil.copy("../../../python/arrow-build-3.6/debug/plasma.cpython-36m-x86_64-linux-gnu.so", destination)
|
||||
def _run_cmake(self):
|
||||
self.build_type = os.environ.get('PYARROW_BUILD_TYPE', 'debug').lower()
|
||||
|
||||
files_to_include = [
|
||||
# "../../../python/arrow-build-3.6/debug/plasma.cpython-36m-x86_64-linux-gnu.so"
|
||||
"../../../cpp/build/debug/plasma.cpython-35m-x86_64-linux-gnu.so"
|
||||
]
|
||||
# The directory containing this setup.py
|
||||
source = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../")
|
||||
|
||||
# The staging directory for the module being built
|
||||
build_temp = os.path.join(os.getcwd(), self.build_temp)
|
||||
build_lib = os.path.join(os.getcwd(), self.build_lib)
|
||||
|
||||
# Change to the build directory
|
||||
saved_cwd = os.getcwd()
|
||||
if not os.path.isdir(self.build_temp):
|
||||
self.mkpath(self.build_temp)
|
||||
os.chdir(self.build_temp)
|
||||
|
||||
static_lib_option = ''
|
||||
|
||||
cmake_options = [
|
||||
'-DPYTHON_EXECUTABLE=%s' % sys.executable,
|
||||
'-DARROW_PLASMA=on',
|
||||
'-DPLASMA_PYTHON=on',
|
||||
static_lib_option,
|
||||
]
|
||||
|
||||
cmake_command = (['cmake'] + cmake_options + [source])
|
||||
|
||||
print("-- Runnning cmake for plasma")
|
||||
self.spawn(cmake_command)
|
||||
print("-- Finished cmake for plasma")
|
||||
|
||||
args = ['make']
|
||||
print("-- Running make for plasma")
|
||||
self.spawn(args)
|
||||
print("-- Finished make for plasma")
|
||||
|
||||
self._found_names = []
|
||||
for name in ["plasma"]:
|
||||
built_path = self.get_ext_built(name)
|
||||
if not os.path.exists(built_path):
|
||||
raise RuntimeError('pyarrow C-extension failed to build:',
|
||||
os.path.abspath(built_path))
|
||||
|
||||
ext_path = os.path.join(build_lib, self._get_cmake_ext_path(name))
|
||||
if os.path.exists(ext_path):
|
||||
os.remove(ext_path)
|
||||
self.mkpath(os.path.dirname(ext_path))
|
||||
print('Moving built C-extension', built_path,
|
||||
'to build path', ext_path)
|
||||
shutil.move(self.get_ext_built(name), ext_path)
|
||||
self._found_names.append(name)
|
||||
|
||||
os.chdir(saved_cwd)
|
||||
|
||||
def _get_cmake_ext_path(self, name):
|
||||
# Get the package directory from build_py
|
||||
build_py = self.get_finalized_command('build_py')
|
||||
package_dir = build_py.get_package_dir('plasma')
|
||||
# This is the name of the arrow C-extension
|
||||
suffix = sysconfig.get_config_var('EXT_SUFFIX')
|
||||
if suffix is None:
|
||||
suffix = sysconfig.get_config_var('SO')
|
||||
filename = name + suffix
|
||||
return os.path.join(package_dir, filename)
|
||||
|
||||
def get_ext_built(self, name):
|
||||
if sys.platform == 'win32':
|
||||
head, tail = os.path.split(name)
|
||||
suffix = sysconfig.get_config_var('SO')
|
||||
return os.path.join(head, self.build_type, tail + suffix)
|
||||
else:
|
||||
suffix = sysconfig.get_config_var('SO')
|
||||
return os.path.join(self.build_type, name + suffix)
|
||||
|
||||
def get_names(self):
|
||||
return self._found_names
|
||||
|
||||
def get_outputs(self):
|
||||
# Just the C extensions
|
||||
# regular_exts = _build_ext.get_outputs(self)
|
||||
return [self._get_cmake_ext_path(name)
|
||||
for name in self.get_names()]
|
||||
|
||||
class BinaryDistribution(Distribution):
|
||||
def has_ext_modules(self):
|
||||
|
||||
Reference in new issue
Block a user