Skip to content

Commit 34880c0

Browse files
authored
GH-49473: [Python] Fix get_include and get_library_dirs to work with both editable and non-editable builds (#49476)
### Rationale for this change With `scikit-build-core` our Cython tests fail to find PyArrow C++ headers due to get_include returning a non-existent directory. ### What changes are included in this PR? Editable builds location of libraries and headers are located at `` Previous to this change: ``` $ python -c "import pyarrow as pa; print(pa.get_include())" /home/raulcd/code/arrow/python/pyarrow/include $ ls /home/raulcd/code/arrow/python/pyarrow/include ls: cannot access '/home/raulcd/code/arrow/python/pyarrow/include': No such file or directory ``` with this change: ``` $ python -c "import pyarrow as pa; print(pa.get_include())" /home/raulcd/code/pyarrow-dev/lib/python3.13/site-packages/pyarrow/include $ ls /home/raulcd/code/pyarrow-dev/lib/python3.13/site-packages/pyarrow/include arrow ``` ### Are these changes tested? Yes, locally for editable installs and on CI for non-editable. ### Are there any user-facing changes? The only change is that headers, generated Cython cpp files and built shared libraries are installed on the virtualenv. * GitHub Issue: #49473 Authored-by: Raúl Cumplido <raulcumplido@gmail.com> Signed-off-by: Raúl Cumplido <raulcumplido@gmail.com>
1 parent 9577ca4 commit 34880c0

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

python/pyarrow/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,11 @@ def get_include():
305305
Return absolute path to directory containing Arrow C++ include
306306
headers. Similar to numpy.get_include
307307
"""
308-
return _os.path.join(_os.path.dirname(__file__), 'include')
308+
# Use pyarrow.lib location instead of just __file__. That works
309+
# for both editable and non-editable builds as it points
310+
# to the actual location of the compiled C++ extension.
311+
from pyarrow import lib as _lib
312+
return _os.path.join(_os.path.dirname(_lib.__file__), 'include')
309313

310314

311315
def _get_pkg_config_executable():
@@ -388,7 +392,11 @@ def get_library_dirs():
388392
Return lists of directories likely to contain Arrow C++ libraries for
389393
linking C or Cython extensions using pyarrow
390394
"""
391-
package_cwd = _os.path.dirname(__file__)
395+
# Use pyarrow.lib location instead of just __file__. That works
396+
# for both editable and non-editable builds as it points
397+
# to the actual location of the compiled C++ extension.
398+
from pyarrow import lib as _lib
399+
package_cwd = _os.path.dirname(_lib.__file__)
392400
library_dirs = [package_cwd]
393401

394402
def append_library_dir(library_dir):

0 commit comments

Comments
 (0)