You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2017/10/23 01:37:55 UTC

[arrow] branch master updated: ARROW-1087: [Python] Add pyarrow.get_include function. Bundle includes in all builds

This is an automated email from the ASF dual-hosted git repository.

wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 53dd0c8  ARROW-1087: [Python] Add pyarrow.get_include function. Bundle includes in all builds
53dd0c8 is described below

commit 53dd0c85718112b274ecd266b6b524f627d16474
Author: Wes McKinney <we...@twosigma.com>
AuthorDate: Sun Oct 22 21:37:49 2017 -0400

    ARROW-1087: [Python] Add pyarrow.get_include function. Bundle includes in all builds
    
    Author: Wes McKinney <we...@twosigma.com>
    
    Closes #1219 from wesm/ARROW-1087 and squashes the following commits:
    
    5444b82e [Wes McKinney] Use more stable include
    6cc855de [Wes McKinney] Add stub rst file about C extensions with pyarrow
---
 python/.gitignore                 |  4 ++++
 python/CMakeLists.txt             |  4 +++-
 python/doc/source/extending.rst   | 33 +++++++++++++++++++++++++++++++++
 python/doc/source/index.rst       |  1 +
 python/pyarrow/__init__.py        | 12 ++++++++++++
 python/pyarrow/tests/test_misc.py | 25 +++++++++++++++++++++++++
 python/setup.py                   | 12 +++++++-----
 7 files changed, 85 insertions(+), 6 deletions(-)

diff --git a/python/.gitignore b/python/.gitignore
index 1bf20c4..6a63e5a 100644
--- a/python/.gitignore
+++ b/python/.gitignore
@@ -17,6 +17,10 @@ Testing/
 *.cpp
 pyarrow/version.py
 pyarrow/*_api.h
+
+# Bundled headers
+pyarrow/include
+
 # Python files
 
 # setup.py working directory
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
index 169e7ad..8c73482 100644
--- a/python/CMakeLists.txt
+++ b/python/CMakeLists.txt
@@ -226,9 +226,11 @@ function(bundle_arrow_implib library_path)
       COPYONLY)
 endfunction(bundle_arrow_implib)
 
+# Always bundle includes
+file(COPY ${ARROW_INCLUDE_DIR}/arrow DESTINATION ${BUILD_OUTPUT_ROOT_DIRECTORY}/include)
+
 if (PYARROW_BUNDLE_ARROW_CPP)
   # arrow
-  file(COPY ${ARROW_INCLUDE_DIR}/arrow DESTINATION ${BUILD_OUTPUT_ROOT_DIRECTORY}/include)
   bundle_arrow_lib(ARROW_SHARED_LIB
     ABI_VERSION ${ARROW_ABI_VERSION}
     SO_VERSION ${ARROW_SO_VERSION})
diff --git a/python/doc/source/extending.rst b/python/doc/source/extending.rst
new file mode 100644
index 0000000..2d6caed
--- /dev/null
+++ b/python/doc/source/extending.rst
@@ -0,0 +1,33 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+.. currentmodule:: pyarrow
+.. _extending:
+
+Building C++ and Cython Extensions using pyarrow
+================================================
+
+pyarrow features both a Cython and C++ API. We intend to fully document the
+details of how to do this.
+
+The Arrow C++ header files are bundled with a pyarrow installation. To get the
+absolute path to this directory (like ``numpy.get_include()``), use:
+
+.. code-block:: python
+
+   import pyarrow as pa
+   pa.get_include()
diff --git a/python/doc/source/index.rst b/python/doc/source/index.rst
index c2ae769..b933d23 100644
--- a/python/doc/source/index.rst
+++ b/python/doc/source/index.rst
@@ -43,5 +43,6 @@ structures.
    plasma
    pandas
    parquet
+   extending
    api
    getting_involved
diff --git a/python/pyarrow/__init__.py b/python/pyarrow/__init__.py
index ffc833a..1215c82 100644
--- a/python/pyarrow/__init__.py
+++ b/python/pyarrow/__init__.py
@@ -147,3 +147,15 @@ def _plasma_store_entry_point():
 # Deprecations
 
 from pyarrow.util import _deprecate_class  # noqa
+
+# ----------------------------------------------------------------------
+# Returning absolute path to the pyarrow include directory (if bundled, e.g. in
+# wheels)
+
+def get_include():
+    """
+    Return absolute path to directory containing Arrow C++ include
+    headers. Similar to numpy.get_include
+    """
+    import os
+    return os.path.join(os.path.dirname(__file__), 'include')
diff --git a/python/pyarrow/tests/test_misc.py b/python/pyarrow/tests/test_misc.py
new file mode 100644
index 0000000..55787f1
--- /dev/null
+++ b/python/pyarrow/tests/test_misc.py
@@ -0,0 +1,25 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import os
+
+import pyarrow as pa
+
+
+def test_get_include():
+    include_dir = pa.get_include()
+    assert os.path.exists(os.path.join(include_dir, 'arrow', 'api.h'))
diff --git a/python/setup.py b/python/setup.py
index edcf397..ccab8fb 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -220,11 +220,7 @@ class build_ext(_build_ext):
             build_prefix = self.build_type
 
         if self.bundle_arrow_cpp:
-            print(pjoin(build_prefix, 'include'), pjoin(build_lib, 'pyarrow'))
-            if os.path.exists(pjoin(build_lib, 'pyarrow', 'include')):
-                shutil.rmtree(pjoin(build_lib, 'pyarrow', 'include'))
-            shutil.move(pjoin(build_prefix, 'include'),
-                        pjoin(build_lib, 'pyarrow'))
+            print(pjoin(build_lib, 'pyarrow'))
             move_shared_libs(build_prefix, build_lib, "arrow")
             move_shared_libs(build_prefix, build_lib, "arrow_python")
             if self.with_plasma:
@@ -232,6 +228,12 @@ class build_ext(_build_ext):
             if self.with_parquet:
                 move_shared_libs(build_prefix, build_lib, "parquet")
 
+        print('Bundling includes: ' + pjoin(build_prefix, 'include'))
+        if os.path.exists(pjoin(build_lib, 'pyarrow', 'include')):
+            shutil.rmtree(pjoin(build_lib, 'pyarrow', 'include'))
+        shutil.move(pjoin(build_prefix, 'include'),
+                    pjoin(build_lib, 'pyarrow'))
+
         # Move the built C-extension to the place expected by the Python build
         self._found_names = []
         for name in self.CYTHON_MODULE_NAMES:

-- 
To stop receiving notification emails like this one, please contact
['"commits@arrow.apache.org" <co...@arrow.apache.org>'].