Skip to content
This repository was archived by the owner on Dec 21, 2023. It is now read-only.

Commit 75b7d8b

Browse files
author
Hoyt Koepke
committed
Got python package to build correctly using only setuputils.py'
1 parent 222ba5b commit 75b7d8b

31 files changed

+121
-30
lines changed

CMakeLists.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -500,22 +500,28 @@ FILE(GLOB_RECURSE _tc_core_files
500500
list(FILTER _tc_core_files EXCLUDE REGEX ".*/model_server/extensions/.*")
501501

502502

503-
add_library(Core SHARED ${_tc_core_files})
504-
target_link_libraries(Core ${TC_DEPENDENCIES} ${TC_EXTERNAL_DEPENDENCIES})
505-
add_dependencies(Core external_dependencies ${TC_EXTERNAL_DEPENDENCIES})
506-
# set_property(TARGET Core APPEND_STRING PROPERTY LINK_FLAGS " -undefined dynamic_lookup")
503+
add_library(TuriCore SHARED ${_tc_core_files})
504+
target_link_libraries(TuriCore ${TC_DEPENDENCIES} ${TC_EXTERNAL_DEPENDENCIES})
505+
add_dependencies(TuriCore external_dependencies ${TC_EXTERNAL_DEPENDENCIES})
506+
# set_property(TARGET TuriCore APPEND_STRING PROPERTY LINK_FLAGS " -undefined dynamic_lookup")
507507
source_group(TREE ${CMAKE_SOURCE_DIR} FILES ${_tc_core_files})
508508

509509
set(TC_TARGET_DIR "${CMAKE_SOURCE_DIR}/targets/")
510510

511-
INSTALL(TARGETS Core
511+
INSTALL(TARGETS TuriCore
512512
LIBRARY DESTINATION ${TC_TARGET_DIR}/lib/)
513513
INSTALL(DIRECTORY src/
514514
DESTINATION ${TC_TARGET_DIR}/include/
515515
MESSAGE_NEVER
516-
FILES_MATCHING REGEX "^.*\.((h)|(hpp))$")
516+
FILES_MATCHING REGEX "^.*\.((h)|(hpp)|(ipp)|(sparsehash/.*))$")
517+
517518
INSTALL(CODE "execute_process( \
518519
COMMAND ${CMAKE_COMMAND} -E create_symlink \
519520
${TC_TARGET_DIR}/include/external/boost/boost_1_68_0/boost \
520521
${TC_TARGET_DIR}/include/boost)")
521522

523+
INSTALL(CODE "execute_process( \
524+
COMMAND ${CMAKE_COMMAND} -E create_symlink \
525+
${TC_TARGET_DIR}/include/external/sparsehash/ \
526+
${TC_TARGET_DIR}/include/sparsehash)")
527+

src/python/setup.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,8 @@
1111
from setuptools import setup, find_packages, Extension
1212
from setuptools.dist import Distribution
1313
from setuptools.command.install import install
14-
15-
extensions = [
16-
Extension("primes", ["primes.pyx"],
17-
include_dirs=[...],
18-
libraries=[...],
19-
library_dirs=[...]),
20-
# Everything but primes.pyx is included here.
21-
Extension("*", ["*.pyx"],
22-
include_dirs=[...],
23-
libraries=[...],
24-
library_dirs=[...]),
25-
]
26-
setup(
27-
name="My hello app",
28-
ext_modules=cythonize(extensions),
29-
)
14+
from Cython.Build import cythonize
15+
from distutils.extension import Extension
3016

3117
PACKAGE_NAME="turicreate"
3218
VERSION='6.0'#{{VERSION_STRING}}
@@ -92,6 +78,7 @@ def run(self):
9278

9379

9480
if __name__ == '__main__':
81+
9582
from distutils.util import get_platform
9683
classifiers=[
9784
"Development Status :: 5 - Production/Stable",
@@ -111,7 +98,13 @@ def run(self):
11198
"Topic :: Scientific/Engineering",
11299
"Topic :: Scientific/Engineering :: Information Analysis",
113100
]
101+
102+
# Get the include directories.
103+
include_dirs = os.environ.get('CPATH', '').split(';')
104+
library_dirs = os.environ.get('LD_LIBRARY_PATH', '').split(';')
105+
114106
cur_platform = get_platform()
107+
115108
if cur_platform.startswith("macosx"):
116109
classifiers.append("Operating System :: MacOS :: MacOS X")
117110
elif cur_platform.startswith('linux'):
@@ -149,15 +142,20 @@ def run(self):
149142
name="turicreate",
150143
version=VERSION,
151144

152-
# This distribution contains platform-specific C++ libraries, but they are not
153-
# built with distutils. So we must create a dummy Extension object so when we
154-
# create a binary file it knows to make it platform-specific.
155-
ext_modules=[Extension('turicreate.__dummy', sources = ['dummy.c'])],
156-
157145
author='Apple Inc.',
158146
author_email='[email protected]',
159147
cmdclass=dict(install = InstallEngine),
160148
distclass=BinaryDistribution,
149+
150+
ext_modules = cythonize([
151+
# Everything but primes.pyx is included here.
152+
Extension("*", ["turicreate/_cython/*.pyx"],
153+
include_dirs=include_dirs,
154+
libraries=['TuriCore'],
155+
library_dirs=library_dirs,
156+
extra_compile_args=['-O3', '-DNDEBUG', '-std=c++11', '-w']),
157+
]),
158+
161159
package_data={
162160
'turicreate': [
163161

src/python/turicreate/_cython/cy_callback.pxd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#
44
# Use of this source code is governed by a BSD-3-clause license that can
55
# be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
6+
7+
# distutils: language = c++
8+
69
"""
710
Provides a translation layer for easing the use of callback
811
functions between cython and the c++ layer.

src/python/turicreate/_cython/cy_callback.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#
44
# Use of this source code is governed by a BSD-3-clause license that can
55
# be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
6+
7+
# distutils: language = c++
8+
69
from libcpp.string cimport string
710
import traceback
811

src/python/turicreate/_cython/cy_cpp_utils.pxd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#
44
# Use of this source code is governed by a BSD-3-clause license that can
55
# be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
6+
7+
# distutils: language = c++
8+
69
from libcpp.string cimport string
710
from libcpp.vector cimport vector
811
from libcpp.map cimport map

src/python/turicreate/_cython/cy_cpp_utils.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# Use of this source code is governed by a BSD-3-clause license that can
55
# be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
66

7+
# distutils: language = c++
8+
9+
710
from libcpp.string cimport string
811
from cpython.version cimport PY_MAJOR_VERSION
912

src/python/turicreate/_cython/cy_dataframe.pxd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#
44
# Use of this source code is governed by a BSD-3-clause license that can
55
# be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
6+
7+
# distutils: language = c++
8+
69
from libcpp.vector cimport vector
710
from libcpp.string cimport string
811
from libcpp.map cimport map

src/python/turicreate/_cython/cy_dataframe.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#
44
# Use of this source code is governed by a BSD-3-clause license that can
55
# be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
6+
7+
# distutils: language = c++
8+
69
from .cy_flexible_type cimport common_typed_flex_list_from_iterable
710
from .cy_flexible_type cimport pylist_from_flex_list
811
from .cy_flexible_type cimport pytype_from_flex_type_enum

src/python/turicreate/_cython/cy_flexible_type.pxd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# Use of this source code is governed by a BSD-3-clause license that can
55
# be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
66

7+
# distutils: language = c++
8+
9+
710
#cython libcpp types
811
from libcpp.vector cimport vector
912
from libcpp.string cimport string

src/python/turicreate/_cython/cy_flexible_type.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#
44
# Use of this source code is governed by a BSD-3-clause license that can
55
# be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
6+
7+
# distutils: language = c++
8+
69
'''
710
There are essentially three tasks that need to be done in flexible_type translation;
811
each of these are implemented in this file.

0 commit comments

Comments
 (0)