From 601794832d66b0c619ee689c8a176ecd27a15ba6 Mon Sep 17 00:00:00 2001 From: Wes McKinney Date: Fri, 28 Oct 2016 21:34:27 -0400 Subject: [PATCH 1/4] Add built-type command line option to setup.py, build extensions in release type subdirectory to avoid conflicts with setuptools Change-Id: I61190a2a23a6720018a715ae2a306f05c625bfca --- python/CMakeLists.txt | 3 +-- python/README.md | 2 ++ python/setup.py | 34 ++++++++++++++++------------------ 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index b8be8665af0..179f02fbc9d 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -203,8 +203,7 @@ if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR}) EXECUTE_PROCESS(COMMAND ln ${MORE_ARGS} -sf ${BUILD_OUTPUT_ROOT_DIRECTORY} ${CMAKE_CURRENT_BINARY_DIR}/build/latest) else() - set(BUILD_OUTPUT_ROOT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") - # set(BUILD_OUTPUT_ROOT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${BUILD_SUBDIR_NAME}/") + set(BUILD_OUTPUT_ROOT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${BUILD_SUBDIR_NAME}/") endif() # where to put generated archives (.a files) diff --git a/python/README.md b/python/README.md index e11f6456455..17f9f551950 100644 --- a/python/README.md +++ b/python/README.md @@ -48,6 +48,8 @@ python setup.py build_ext --inplace py.test pyarrow ``` +To set CMake build options, set the environment variable `$PYARROW_CMAKE_OPTIONS`: + #### Build the documentation ```bash diff --git a/python/setup.py b/python/setup.py index 99049777514..ed287eafc39 100644 --- a/python/setup.py +++ b/python/setup.py @@ -39,14 +39,6 @@ # Check if we're running 64-bit Python is_64_bit = sys.maxsize > 2**32 -# Check if this is a debug build of Python. -# if hasattr(sys, 'gettotalrefcount'): -# build_type = 'Debug' -# else: -# build_type = 'Release' - -build_type = 'Debug' - if Cython.__version__ < '0.19.1': raise Exception('Please upgrade to Cython 0.19.1 or newer') @@ -104,13 +96,14 @@ def run(self): # github.com/libdynd/dynd-python description = "Build the C-extensions for arrow" - user_options = ([('extra-cmake-args=', None, - 'extra arguments for CMake')] + - _build_ext.user_options) + user_options = ([('extra-cmake-args=', None, 'extra arguments for CMake'), + ('build-type=', None, 'build type (debug or release)')] + + _build_ext.user_options) def initialize_options(self): _build_ext.initialize_options(self) self.extra_cmake_args = os.environ.get('PYARROW_CMAKE_OPTIONS', '') + self.build_type = 'debug' CYTHON_MODULE_NAMES = [ 'array', @@ -152,9 +145,12 @@ def _run_cmake(self): static_lib_option = '' build_tests_option = '' + build_type_option = '-DCMAKE_BUILD_TYPE={0}'.format(self.build_type) + if sys.platform != 'win32': cmake_command = ['cmake', self.extra_cmake_args, pyexe_option, build_tests_option, + build_type_option, static_lib_option, source] self.spawn(cmake_command) @@ -170,7 +166,8 @@ def _run_cmake(self): # Generate the build files extra_cmake_args = shlex.split(self.extra_cmake_args) cmake_command = (['cmake'] + extra_cmake_args + - [source, pyexe_option, + [source, + pyexe_option, static_lib_option, build_tests_option, '-G', cmake_generator]) @@ -179,7 +176,7 @@ def _run_cmake(self): self.spawn(cmake_command) # Do the build - self.spawn(['cmake', '--build', '.', '--config', build_type]) + self.spawn(['cmake', '--build', '.', '--config', self.build_type]) if self.inplace: # a bit hacky @@ -188,14 +185,15 @@ def _run_cmake(self): # Move the built libpyarrow library to the place expected by the Python # build if sys.platform != 'win32': - name, = glob.glob('libpyarrow.*') + name, = glob.glob(pjoin(self.build_type, 'libpyarrow.*')) try: os.makedirs(pjoin(build_lib, 'pyarrow')) except OSError: pass - shutil.move(name, pjoin(build_lib, 'pyarrow', name)) + shutil.move(name, + pjoin(build_lib, 'pyarrow', os.path.split(name)[1])) else: - shutil.move(pjoin(build_type, 'pyarrow.dll'), + shutil.move(pjoin(self.build_type, 'pyarrow.dll'), pjoin(build_lib, 'pyarrow', 'pyarrow.dll')) # Move the built C-extension to the place expected by the Python build @@ -239,10 +237,10 @@ def get_ext_built(self, name): if sys.platform == 'win32': head, tail = os.path.split(name) suffix = sysconfig.get_config_var('SO') - return pjoin(head, build_type, tail + suffix) + return pjoin(head, self.build_type, tail + suffix) else: suffix = sysconfig.get_config_var('SO') - return name + suffix + return pjoin(self.build_type, name + suffix) def get_names(self): return self._found_names From d0b315407d4fada399128f51d1884c60c86f0b08 Mon Sep 17 00:00:00 2001 From: Wes McKinney Date: Fri, 28 Oct 2016 21:37:34 -0400 Subject: [PATCH 2/4] Tweak readme Change-Id: Id0ae8e11093c7e116019c70a35c098b52311c2de --- python/README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/python/README.md b/python/README.md index 17f9f551950..2a3e1ba9542 100644 --- a/python/README.md +++ b/python/README.md @@ -48,7 +48,14 @@ python setup.py build_ext --inplace py.test pyarrow ``` -To set CMake build options, set the environment variable `$PYARROW_CMAKE_OPTIONS`: +To change the build type, use the `--build-type` option: + +```bash +python setup.py build_ext --build-type=release --inplace +``` + +To pass through other build options to CMake, set the environment variable +`$PYARROW_CMAKE_OPTIONS`. #### Build the documentation From 74bfa7187caa212dbe49ca4cb1e33c02882fe974 Mon Sep 17 00:00:00 2001 From: Wes McKinney Date: Mon, 31 Oct 2016 21:15:03 -0400 Subject: [PATCH 3/4] Pull default build type from environment variable Change-Id: I42eadd763a4211f72e1f12257b6d0a174f6b9684 --- python/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/setup.py b/python/setup.py index ed287eafc39..c6def0ed929 100644 --- a/python/setup.py +++ b/python/setup.py @@ -103,7 +103,7 @@ def run(self): def initialize_options(self): _build_ext.initialize_options(self) self.extra_cmake_args = os.environ.get('PYARROW_CMAKE_OPTIONS', '') - self.build_type = 'debug' + self.build_type = os.environ.get('PYARROW_BUILD_TYPE', 'debug') CYTHON_MODULE_NAMES = [ 'array', From 3cdaeaf4ce6406c2b6744a276e0748d40427fcfb Mon Sep 17 00:00:00 2001 From: Wes McKinney Date: Tue, 1 Nov 2016 14:19:09 -0400 Subject: [PATCH 4/4] Cast build_type to lowercase in case env variable is uppercase Change-Id: I0b0a7dcaa686dab97ca34a2b6dee3532bc36145b --- python/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/setup.py b/python/setup.py index c6def0ed929..b6ad4a5f9a9 100644 --- a/python/setup.py +++ b/python/setup.py @@ -103,7 +103,7 @@ def run(self): def initialize_options(self): _build_ext.initialize_options(self) self.extra_cmake_args = os.environ.get('PYARROW_CMAKE_OPTIONS', '') - self.build_type = os.environ.get('PYARROW_BUILD_TYPE', 'debug') + self.build_type = os.environ.get('PYARROW_BUILD_TYPE', 'debug').lower() CYTHON_MODULE_NAMES = [ 'array',