Repository: arrow
Updated Branches:
  refs/heads/master ca088dd19 -> d4148759a


ARROW-348: [Python] Add build-type command line option to setup.py, build CMake 
extensions in a build type subdirectory

This also resolves ARROW-230.

Author: Wes McKinney <wes.mckin...@twosigma.com>

Closes #187 from wesm/ARROW-348 and squashes the following commits:

3cdaeaf [Wes McKinney] Cast build_type to lowercase in case env variable is 
uppercase
74bfa71 [Wes McKinney] Pull default build type from environment variable
d0b3154 [Wes McKinney] Tweak readme
6017948 [Wes McKinney] Add built-type command line option to setup.py, build 
extensions in release type subdirectory to avoid conflicts with setuptools


Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/d4148759
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/d4148759
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/d4148759

Branch: refs/heads/master
Commit: d4148759a266d90dacd1ca2b7b7ff0df7e02578a
Parents: ca088dd
Author: Wes McKinney <wes.mckin...@twosigma.com>
Authored: Tue Nov 1 14:21:07 2016 -0400
Committer: Wes McKinney <wes.mckin...@twosigma.com>
Committed: Tue Nov 1 14:21:07 2016 -0400

----------------------------------------------------------------------
 python/CMakeLists.txt |  3 +--
 python/README.md      |  9 +++++++++
 python/setup.py       | 34 ++++++++++++++++------------------
 3 files changed, 26 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/d4148759/python/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
index b8be866..179f02f 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)

http://git-wip-us.apache.org/repos/asf/arrow/blob/d4148759/python/README.md
----------------------------------------------------------------------
diff --git a/python/README.md b/python/README.md
index e11f645..2a3e1ba 100644
--- a/python/README.md
+++ b/python/README.md
@@ -48,6 +48,15 @@ python setup.py build_ext --inplace
 py.test pyarrow
 ```
 
+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
 
 ```bash

http://git-wip-us.apache.org/repos/asf/arrow/blob/d4148759/python/setup.py
----------------------------------------------------------------------
diff --git a/python/setup.py b/python/setup.py
index cdfdc24..b3012e6 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -39,14 +39,6 @@ from distutils import sysconfig
 # 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 @@ class build_ext(_build_ext):
     # 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 = os.environ.get('PYARROW_BUILD_TYPE', 'debug').lower()
 
     CYTHON_MODULE_NAMES = [
         'array',
@@ -152,9 +145,12 @@ class build_ext(_build_ext):
         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 @@ class build_ext(_build_ext):
             # 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 @@ class build_ext(_build_ext):
 
             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 @@ class build_ext(_build_ext):
         # 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 @@ class build_ext(_build_ext):
         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

Reply via email to