Skip to content

Commit d414875

Browse files
committed
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.mckinney@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
1 parent ca088dd commit d414875

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

python/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
203203
EXECUTE_PROCESS(COMMAND ln ${MORE_ARGS} -sf ${BUILD_OUTPUT_ROOT_DIRECTORY}
204204
${CMAKE_CURRENT_BINARY_DIR}/build/latest)
205205
else()
206-
set(BUILD_OUTPUT_ROOT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
207-
# set(BUILD_OUTPUT_ROOT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${BUILD_SUBDIR_NAME}/")
206+
set(BUILD_OUTPUT_ROOT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${BUILD_SUBDIR_NAME}/")
208207
endif()
209208

210209
# where to put generated archives (.a files)

python/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ python setup.py build_ext --inplace
4848
py.test pyarrow
4949
```
5050

51+
To change the build type, use the `--build-type` option:
52+
53+
```bash
54+
python setup.py build_ext --build-type=release --inplace
55+
```
56+
57+
To pass through other build options to CMake, set the environment variable
58+
`$PYARROW_CMAKE_OPTIONS`.
59+
5160
#### Build the documentation
5261

5362
```bash

python/setup.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@
3939
# Check if we're running 64-bit Python
4040
is_64_bit = sys.maxsize > 2**32
4141

42-
# Check if this is a debug build of Python.
43-
# if hasattr(sys, 'gettotalrefcount'):
44-
# build_type = 'Debug'
45-
# else:
46-
# build_type = 'Release'
47-
48-
build_type = 'Debug'
49-
5042
if Cython.__version__ < '0.19.1':
5143
raise Exception('Please upgrade to Cython 0.19.1 or newer')
5244

@@ -104,13 +96,14 @@ def run(self):
10496
# github.com/libdynd/dynd-python
10597

10698
description = "Build the C-extensions for arrow"
107-
user_options = ([('extra-cmake-args=', None,
108-
'extra arguments for CMake')] +
109-
_build_ext.user_options)
99+
user_options = ([('extra-cmake-args=', None, 'extra arguments for CMake'),
100+
('build-type=', None, 'build type (debug or release)')]
101+
+ _build_ext.user_options)
110102

111103
def initialize_options(self):
112104
_build_ext.initialize_options(self)
113105
self.extra_cmake_args = os.environ.get('PYARROW_CMAKE_OPTIONS', '')
106+
self.build_type = os.environ.get('PYARROW_BUILD_TYPE', 'debug').lower()
114107

115108
CYTHON_MODULE_NAMES = [
116109
'array',
@@ -152,9 +145,12 @@ def _run_cmake(self):
152145
static_lib_option = ''
153146
build_tests_option = ''
154147

148+
build_type_option = '-DCMAKE_BUILD_TYPE={0}'.format(self.build_type)
149+
155150
if sys.platform != 'win32':
156151
cmake_command = ['cmake', self.extra_cmake_args, pyexe_option,
157152
build_tests_option,
153+
build_type_option,
158154
static_lib_option, source]
159155

160156
self.spawn(cmake_command)
@@ -170,7 +166,8 @@ def _run_cmake(self):
170166
# Generate the build files
171167
extra_cmake_args = shlex.split(self.extra_cmake_args)
172168
cmake_command = (['cmake'] + extra_cmake_args +
173-
[source, pyexe_option,
169+
[source,
170+
pyexe_option,
174171
static_lib_option,
175172
build_tests_option,
176173
'-G', cmake_generator])
@@ -179,7 +176,7 @@ def _run_cmake(self):
179176

180177
self.spawn(cmake_command)
181178
# Do the build
182-
self.spawn(['cmake', '--build', '.', '--config', build_type])
179+
self.spawn(['cmake', '--build', '.', '--config', self.build_type])
183180

184181
if self.inplace:
185182
# a bit hacky
@@ -188,14 +185,15 @@ def _run_cmake(self):
188185
# Move the built libpyarrow library to the place expected by the Python
189186
# build
190187
if sys.platform != 'win32':
191-
name, = glob.glob('libpyarrow.*')
188+
name, = glob.glob(pjoin(self.build_type, 'libpyarrow.*'))
192189
try:
193190
os.makedirs(pjoin(build_lib, 'pyarrow'))
194191
except OSError:
195192
pass
196-
shutil.move(name, pjoin(build_lib, 'pyarrow', name))
193+
shutil.move(name,
194+
pjoin(build_lib, 'pyarrow', os.path.split(name)[1]))
197195
else:
198-
shutil.move(pjoin(build_type, 'pyarrow.dll'),
196+
shutil.move(pjoin(self.build_type, 'pyarrow.dll'),
199197
pjoin(build_lib, 'pyarrow', 'pyarrow.dll'))
200198

201199
# Move the built C-extension to the place expected by the Python build
@@ -239,10 +237,10 @@ def get_ext_built(self, name):
239237
if sys.platform == 'win32':
240238
head, tail = os.path.split(name)
241239
suffix = sysconfig.get_config_var('SO')
242-
return pjoin(head, build_type, tail + suffix)
240+
return pjoin(head, self.build_type, tail + suffix)
243241
else:
244242
suffix = sysconfig.get_config_var('SO')
245-
return name + suffix
243+
return pjoin(self.build_type, name + suffix)
246244

247245
def get_names(self):
248246
return self._found_names

0 commit comments

Comments
 (0)