Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
timkpaine committed Aug 2, 2023
1 parent 6689b5f commit ff6273b
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 26 deletions.
21 changes: 13 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ endif()
# Paths #
#########
# Custom CMake modules
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake/modules")
list(PREPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules")

# Base includes
include_directories ("${CMAKE_SOURCE_DIR}/src")
include_directories ("${PROJECT_SOURCE_DIR}/src")

###############################################################################################################
# Build Configuration #
Expand All @@ -65,6 +65,7 @@ option(BUILD_PYTHON "Build Python bindings" ON)
option(USE_CCACHE "Use CCache for build" OFF)
option(STATIC_PYTHON "Build against static python (no libraries)" OFF)
option(PYODIDE "Build against pyodide" OFF)
set(BUILD_SHARED_LIBS ON)

# CCache setup
if(USE_CCACHE)
Expand Down Expand Up @@ -170,6 +171,10 @@ endif()
###############################################################################################################
# Dependencies #
################
message("${Red}${CMAKE_MODULE_PATH}${ColorReset}")


# broken on mac
find_package(Arrow REQUIRED)

###############################################################################################################
Expand Down Expand Up @@ -229,7 +234,7 @@ set(
)

add_library(arrow-python-nocopy SHARED ${PROJECT_SRCS})
target_link_libraries(arrow-python-nocopy PRIVATE Arrow::arrow_shared)
target_link_libraries(arrow-python-nocopy PRIVATE ${Arrow_LIBRARY})
set_target_properties(arrow-python-nocopy PROPERTIES PUBLIC_HEADER "${PROJECT_HDRS}")

# export symbols
Expand Down Expand Up @@ -300,13 +305,13 @@ if(BUILD_PYTHON)
target_link_libraries(common PRIVATE arrow-python-nocopy)
target_link_libraries(pybind11extension PRIVATE common)
target_link_libraries(cpythonextension PRIVATE common)
set_property(TARGET common PROPERTY INSTALL_RPATH "${module_origin_path}:${module_origin_path}/lib")
set_property(TARGET pybind11extension PROPERTY INSTALL_RPATH "${module_origin_path}:${module_origin_path}/lib")
set_property(TARGET cpythonextension PROPERTY INSTALL_RPATH "${module_origin_path}:${module_origin_path}/lib")
set_property(TARGET common PROPERTY INSTALL_RPATH "${module_origin_path}")
set_property(TARGET pybind11extension PROPERTY INSTALL_RPATH "${module_origin_path}")
set_property(TARGET cpythonextension PROPERTY INSTALL_RPATH "${module_origin_path}")
set_property(TARGET cpythonextension PROPERTY PREFIX "")

# install in python module
install(TARGETS common EXPORT ArrowPythonNocopy LIBRARY DESTINATION lib PUBLIC_HEADER DESTINATION include/python)
install(TARGETS pybind11extension EXPORT ArrowPythonNocopy LIBRARY DESTINATION . PUBLIC_HEADER DESTINATION include/python)
install(TARGETS cpythonextension EXPORT ArrowPythonNocopy LIBRARY DESTINATION . PUBLIC_HEADER DESTINATION include/python)
install(TARGETS pybind11extension EXPORT ArrowPythonNocopy LIBRARY DESTINATION lib PUBLIC_HEADER DESTINATION include/python)
install(TARGETS cpythonextension EXPORT ArrowPythonNocopy LIBRARY DESTINATION lib PUBLIC_HEADER DESTINATION include/python)
endif()
19 changes: 13 additions & 6 deletions arrow_python_nocopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
import os.path
import pyarrow as pa
import pandas as pd
from .pybind11extension import array_info, create_array
from .pybind11extension import schema_info, create_schema
# from .pybind11extension import table_info, create_table
from .cpythonextension import array_info as array_info_cp, create_array as create_array_cp
from .cpythonextension import schema_info as schema_info_cp, create_schema as create_schema_cp
# from .pybind11extension import table_info as table_info_cp, create_table as create_table_cp
from .lib.pybind11extension import array_info, create_array
from .lib.pybind11extension import schema_info, create_schema

# from .lib.pybind11extension import table_info, create_table
from .lib.cpythonextension import array_info as array_info_cp, create_array as create_array_cp
from .lib.cpythonextension import schema_info as schema_info_cp, create_schema as create_schema_cp

# from .lib.cpythonextension import table_info as table_info_cp, create_table as create_table_cp


__version__ = "0.1.0"
Expand All @@ -24,17 +26,21 @@ def bin_path():
def lib_path():
return os.path.abspath(os.path.join(os.path.dirname(__file__), "lib"))


def _df():
return pd.DataFrame({"a": pd.Series([1, 2, 3], dtype='Int32'), "b": pd.Series([1.1, 2.2, 3.3], dtype='Float32'), "c": pd.Series(["abc", "def", "ghi"], dtype=str)})


def _table():
return pa.Table.from_pandas(_df())


def create_arrow_array_in_python():
table = _table()
array = table.columns['a']
print(array_info(array))


def create_arrow_array_in_cpp():
return create_array()

Expand All @@ -44,6 +50,7 @@ def create_arrow_schema_in_python():
schema = table.schema
print(schema_info(schema))


def create_arrow_schema_in_cpp():
return create_schema()

Expand Down
20 changes: 8 additions & 12 deletions arrow_python_nocopy/tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
import pyarrow as pa
from arrow_python_nocopy import array_info, create_array
from arrow_python_nocopy import schema_info, create_schema

# from arrow_python_nocopy import table_info, create_table
from arrow_python_nocopy import array_info_cp, create_array_cp
from arrow_python_nocopy import schema_info_cp, create_schema_cp

# from arrow_python_nocopy import table_info_cp, create_table_cp
from arrow_python_nocopy import _df, _table


class TestPybind:
def test_create_array_in_python(self):
table = _table()
Expand All @@ -20,15 +23,12 @@ def test_create_schema_in_python(self):

def test_create_array_in_cpp(self):
array = create_array()
assert (
str(array) == '[\n 1,\n 2,\n 3\n]'
)
assert str(array) == '[\n 1,\n 2,\n 3\n]'

def test_create_schema_in_cpp(self):
schema = create_schema()
assert (
str(schema) == 'a: int32\nb: float\nc: binary'
)
assert str(schema) == 'a: int32\nb: float\nc: binary'


class TestCPython:
def test_create_array_in_python(self):
Expand All @@ -50,12 +50,8 @@ def test_create_schema_in_python_bad_value(self):

def test_create_array_in_cpp(self):
array = create_array_cp()
assert (
str(array) == '[\n 1,\n 2,\n 3\n]'
)
assert str(array) == '[\n 1,\n 2,\n 3\n]'

def test_create_schema_in_cpp(self):
schema = create_schema_cp()
assert (
str(schema) == 'a: int32\nb: float\nc: binary'
)
assert str(schema) == 'a: int32\nb: float\nc: binary'
37 changes: 37 additions & 0 deletions cmake/modules/FindArrow.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Find Arrow
# This module defines:
# Arrow_INCLUDE_DIR
# Arrow_LIBRARY
# Arrow_LIB_DIR

find_path(Arrow_INCLUDE_DIR arrow/config.h
PATHS ${Arrow_ROOT}/include
HINTS /usr /usr/include /usr/local /usr/local/include /usr/local/Homebrew /usr/local/Homebrew/include ~/homebrew ~/homebrew/include /opt/homebrew /opt/homebrew/include
NO_CMAKE_SYSTEM_PATH
NO_SYSTEM_ENVIRONMENT_PATH)

find_path(Arrow_LIB_DIR
NAMES libarrow.a arrow.a libarrow.so arrow.so libarrow.dylib arrow.dylib
PATHS ${Arrow_ROOT}/lib
HINTS /usr /usr/lib /usr/local /usr/local/lib /usr/local/Homebrew /usr/local/Homebrew/lib ~/homebrew/ ~/homebrew/lib /opt/homebrew/ /opt/homebrew/lib
NO_CMAKE_SYSTEM_PATH
NO_SYSTEM_ENVIRONMENT_PATH)

if(BUILD_SHARED_LIBS)
find_file(Arrow_LIBRARY
NAMES libarrow.so arrow.so libarrow.dylib arrow.dylib
PATHS ${Arrow_ROOT}
HINTS /usr /usr/lib /usr/local /usr/local/lib /usr/local/Homebrew /usr/local/Homebrew/lib ~/homebrew/ ~/homebrew/lib /opt/homebrew/ /opt/homebrew/lib
NO_CMAKE_SYSTEM_PATH
NO_SYSTEM_ENVIRONMENT_PATH)
else()
find_file(Arrow_LIBRARY
NAMES libarrow.a arrow.a
PATHS ${Arrow_ROOT}
HINTS /usr /usr/lib /usr/local /usr/local/lib /usr/local/Homebrew /usr/local/Homebrew/lib ~/homebrew/ ~/homebrew/lib /opt/homebrew/ /opt/homebrew/lib
NO_CMAKE_SYSTEM_PATH
NO_SYSTEM_ENVIRONMENT_PATH)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Arrow REQUIRED_VARS Arrow_INCLUDE_DIR Arrow_LIB_DIR Arrow_LIBRARY)
40 changes: 40 additions & 0 deletions cmake/modules/FindThrift.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Find Thrift
# This module defines:
# Thrift_INCLUDE_DIR
# Thrift_LIBRARY
# Thrift_LIB_DIR

find_path(Thrift_INCLUDE_DIR thrift/Thrift.h
PATHS ${Thrift_ROOT}/include
HINTS /usr /usr/include /usr/local /usr/local/include /usr/local/Homebrew /usr/local/Homebrew/include ~/homebrew ~/homebrew/include /opt/homebrew /opt/homebrew/include
NO_CMAKE_SYSTEM_PATH
NO_SYSTEM_ENVIRONMENT_PATH)

find_path(Thrift_LIB_DIR
NAMES libthrift.a libthrift.so libthrift.dylib
PATHS ${Thrift_ROOT}/lib
HINTS /usr /usr/lib /usr/local /usr/local/lib /usr/local/Homebrew /usr/local/Homebrew/lib ~/homebrew/ ~/homebrew/lib /opt/homebrew/ /opt/homebrew/lib
NO_CMAKE_SYSTEM_PATH
NO_SYSTEM_ENVIRONMENT_PATH)

if(BUILD_SHARED_LIBS)
find_file(Thrift_LIBRARY
NAMES libthrift.so thrift.so libthrift.dylib thrift.dylib
PATHS ${Thrift_ROOT}
HINTS /usr /usr/lib /usr/local /usr/local/lib /usr/local/Homebrew /usr/local/Homebrew/lib ~/homebrew/ ~/homebrew/lib /opt/homebrew/ /opt/homebrew/lib
NO_CMAKE_SYSTEM_PATH
NO_SYSTEM_ENVIRONMENT_PATH)
else()
find_file(Thrift_LIBRARY
NAMES libthrift.a thrift.a
PATHS ${Thrift_ROOT}
HINTS /usr /usr/lib /usr/local /usr/local/lib /usr/local/Homebrew /usr/local/Homebrew/lib ~/homebrew/ ~/homebrew/lib /opt/homebrew/ /opt/homebrew/lib
NO_CMAKE_SYSTEM_PATH
NO_SYSTEM_ENVIRONMENT_PATH)
endif()

# For apache arrow
set(ThriftAlt_LIB ${Thrift_LIBRARY})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Thrift REQUIRED_VARS Thrift_INCLUDE_DIR Thrift_LIB_DIR Thrift_LIBRARY)

0 comments on commit ff6273b

Please sign in to comment.