Skip to content

Commit 03bdf10

Browse files
committed
package stubs into wheels and test for presence
1 parent 42135f3 commit 03bdf10

9 files changed

Lines changed: 54 additions & 4 deletions

‎.github/workflows/python.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ jobs:
126126
run: |
127127
source ci/scripts/util_enable_core_dumps.sh
128128
archery docker run ${{ matrix.image }}
129-
130129
- name: Docker Push
131130
if: >-
132131
success() &&

‎ci/scripts/python_wheel_macos_build.sh‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ export CMAKE_PREFIX_PATH=${build_dir}/install
175175
export SETUPTOOLS_SCM_PRETEND_VERSION=${PYARROW_VERSION}
176176

177177
pushd ${source_dir}/python
178+
# We first populate stub docstrings and then build the wheel
179+
python setup.py build_ext --inplace
180+
python -m pip install griffe libcst
181+
python ../dev/update_stub_docstrings.py pyarrow-stubs
182+
178183
python setup.py bdist_wheel
179184
popd
180185

‎ci/scripts/python_wheel_validate_contents.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def validate_wheel(path):
3535
assert not outliers, f"Unexpected contents in wheel: {sorted(outliers)}"
3636
print(f"The wheel: {wheels[0]} seems valid.")
3737

38+
candidates = [info for info in f.filelist if info.filename.endswith('compute.pyi')]
39+
assert candidates, "compute.pyi not found in wheel"
40+
content = f.read(candidates[0]).decode('utf-8', errors='replace')
41+
assert '"""' in content, "compute.pyi missing docstrings (no triple quotes found)"
42+
3843

3944
def main():
4045
parser = argparse.ArgumentParser()

‎ci/scripts/python_wheel_windows_build.bat‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ pushd C:\arrow\python
135135
@REM Build wheel
136136
%PYTHON_CMD% setup.py bdist_wheel || exit /B 1
137137

138+
@REM We first populate stub docstrings and then build the wheel
139+
%PYTHON_CMD% setup.py build_ext --inplace
140+
%PYTHON_CMD% -m pip install griffe libcst
141+
%PYTHON_CMD% ..\dev\update_stub_docstrings.py pyarrow-stubs
142+
138143
@REM Repair the wheel with delvewheel
139144
@REM
140145
@REM Since we bundled the Arrow C++ libraries ourselves, we only need to

‎ci/scripts/python_wheel_xlinux_build.sh‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ export ARROW_HOME=/tmp/arrow-dist
167167
export CMAKE_PREFIX_PATH=/tmp/arrow-dist
168168

169169
pushd /arrow/python
170+
# We first populate stub docstrings and then build the wheel
171+
python setup.py build_ext --inplace
172+
python -m pip install griffe libcst
173+
python ../dev/update_stub_docstrings.py pyarrow-stubs
174+
170175
python setup.py bdist_wheel
171176

172177
echo "=== Strip symbols from wheel ==="

‎dev/update_stub_docstrings.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# Usage
2222
# =====
2323
#
24-
# python ./dev/update_stub_docstrings.py -f ./python/pyarrow-stubs
24+
# python ../dev/update_stub_docstrings.py pyarrow-stubs
2525

2626

2727
from pathlib import Path
@@ -178,7 +178,7 @@ def leave_FunctionDef(self, original_node, updated_node):
178178

179179

180180
@click.command()
181-
@click.option('--pyarrow_folder', '-f', type=click.Path(resolve_path=True))
181+
@click.argument('pyarrow_folder', type=click.Path(resolve_path=True))
182182
def add_docs_to_stub_files(pyarrow_folder):
183183
print("Updating docstrings of stub files in:", pyarrow_folder)
184184
package = griffe.load("pyarrow", try_relative_path=True,

‎python/MANIFEST.in‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ include ../NOTICE.txt
44

55
global-include CMakeLists.txt
66
graft pyarrow
7+
graft pyarrow-stubs
78
graft cmake_modules
89

910
global-exclude *.so

‎python/pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ zip-safe=false
8181
include-package-data=true
8282

8383
[tool.setuptools.packages.find]
84-
include = ["pyarrow"]
84+
include = ["pyarrow", "pyarrow.*"]
8585
namespaces = false
8686

8787
[tool.setuptools.package-data]

‎python/setup.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from os.path import join as pjoin
2424
import re
2525
import shlex
26+
import shutil
2627
import sys
2728
import warnings
2829

@@ -119,8 +120,37 @@ def build_extensions(self):
119120

120121
def run(self):
121122
self._run_cmake()
123+
self._copy_stubs()
122124
_build_ext.run(self)
123125

126+
def _copy_stubs(self):
127+
"""Copy .pyi stub files from pyarrow-stubs to the build directory."""
128+
build_cmd = self.get_finalized_command('build')
129+
build_lib = os.path.abspath(build_cmd.build_lib)
130+
131+
stubs_src = pjoin(setup_dir, 'pyarrow-stubs', 'pyarrow')
132+
stubs_dest = pjoin(build_lib, 'pyarrow')
133+
134+
if os.path.exists(stubs_src):
135+
print(f"-- Copying stub files from {stubs_src} to {stubs_dest}")
136+
for root, dirs, files in os.walk(stubs_src):
137+
# Calculate relative path from stubs_src
138+
rel_dir = os.path.relpath(root, stubs_src)
139+
dest_dir = pjoin(stubs_dest, rel_dir) if rel_dir != '.' else stubs_dest
140+
141+
# Create destination directory if needed
142+
if not os.path.exists(dest_dir):
143+
os.makedirs(dest_dir)
144+
145+
# Copy .pyi files
146+
for file in files:
147+
if file.endswith('.pyi'):
148+
src_file = pjoin(root, file)
149+
dest_file = pjoin(dest_dir, file)
150+
shutil.copy2(src_file, dest_file)
151+
print(f" Copied {file} to {os.path.relpath(dest_file, build_lib)}")
152+
153+
124154
# adapted from cmake_build_ext in dynd-python
125155
# github.com/libdynd/dynd-python
126156

0 commit comments

Comments
 (0)