Skip to content

Commit 9ed6a53

Browse files
committed
review feedback
1 parent 716c642 commit 9ed6a53

File tree

5 files changed

+54
-43
lines changed

5 files changed

+54
-43
lines changed

ci/scripts/python_test_type_annotations.sh

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,20 @@
2020
set -ex
2121
pyarrow_dir=${1}
2222

23-
if [ "${PYARROW_TEST_ANNOTATIONS}" == "ON" ]; then
24-
if [ -n "${ARROW_PYTHON_VENV:-}" ]; then
25-
# shellcheck source=/dev/null
26-
. "${ARROW_PYTHON_VENV}/bin/activate"
27-
fi
23+
if [ -n "${ARROW_PYTHON_VENV:-}" ]; then
24+
# shellcheck source=/dev/null
25+
. "${ARROW_PYTHON_VENV}/bin/activate"
26+
fi
2827

29-
# Install library stubs. Note some libraries contain their own type hints so they need to be installed.
30-
pip install fsspec pandas-stubs scipy-stubs types-cffi types-psutil types-requests types-python-dateutil
28+
# Install library stubs. Note some libraries contain their own type hints so they need to be installed.
29+
pip install fsspec pandas-stubs scipy-stubs types-cffi types-psutil types-requests types-python-dateutil
3130

32-
# Install type checkers
33-
pip install mypy pyright ty
31+
# Install type checkers
32+
pip install mypy pyright ty
3433

35-
# Run type checkers
36-
pushd "${pyarrow_dir}"
37-
mypy
38-
pyright
39-
ty check
40-
popd
41-
else
42-
echo "Skipping type annotation tests"
43-
fi
34+
# Run type checkers
35+
pushd "${pyarrow_dir}"
36+
mypy
37+
pyright
38+
ty check
39+
popd

python/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ exclude = [
113113
# TODO: Enable type checking once stubs are merged
114114
[tool.pyright]
115115
pythonPlatform = "All"
116-
pythonVersion = "3.10"
117116
include = ["pyarrow-stubs"]
118117
exclude = [
119118
"pyarrow",

python/requirements-wheel-build.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
build
22
cython>=3.1
3+
# Needed for build-time stub docstring extraction
4+
libcst>=1.8.6
35
numpy>=2.0.0
46
setuptools_scm
57
setuptools>=77
Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@
1919
Extract docstrings from pyarrow runtime and insert them into stub files.
2020
2121
Usage (from python/ directory with pyarrow built):
22-
python ../dev/update_stub_docstrings.py pyarrow-stubs
22+
python scripts/update_stub_docstrings.py pyarrow-stubs
2323
"""
2424

2525
import argparse
2626
import importlib
2727
import inspect
28-
import shutil
2928
import sys
3029
from pathlib import Path
3130
from textwrap import indent
@@ -199,27 +198,19 @@ def add_docstrings_to_stubs(stubs_dir):
199198
stub_file.write_text(modified.code)
200199

201200

202-
def copy_stubs(src_dir, dest_dir):
203-
"""Copy .pyi files from src_dir to dest_dir."""
204-
src_dir, dest_dir = Path(src_dir), Path(dest_dir)
205-
if not src_dir.exists():
206-
return
201+
def add_docstrings_from_build(stubs_dir, build_lib):
202+
"""
203+
Entry point for setup.py: update docstrings using pyarrow from build directory.
207204
208-
print(f"Copying stubs: {src_dir} -> {dest_dir}")
209-
for src in src_dir.rglob('*.pyi'):
210-
dest = dest_dir / src.relative_to(src_dir)
211-
dest.parent.mkdir(parents=True, exist_ok=True)
212-
shutil.copy2(src, dest)
213-
214-
215-
def update_stubs_for_build(stubs_dir, build_lib):
216-
"""Entry point for setup.py: update docstrings and copy stubs to build dir."""
205+
During the build process, pyarrow is not installed in the system Python.
206+
We need to temporarily add the build directory to sys.path so we can
207+
import pyarrow and extract docstrings from it.
208+
"""
217209
stubs_dir, build_lib = Path(stubs_dir), Path(build_lib)
218210

219211
sys.path.insert(0, str(build_lib))
220212
try:
221213
add_docstrings_to_stubs(stubs_dir)
222-
copy_stubs(stubs_dir / "pyarrow", build_lib / "pyarrow")
223214
finally:
224215
sys.path.pop(0)
225216

@@ -229,5 +220,9 @@ def update_stubs_for_build(stubs_dir, build_lib):
229220
parser.add_argument("stubs_dir", type=Path, help="Path to pyarrow-stubs folder")
230221
args = parser.parse_args()
231222

232-
sys.path.insert(0, ".")
223+
# Add the directory containing this script's parent (python/) to sys.path
224+
# so pyarrow can be imported when running from the python/ directory
225+
script_dir = Path(__file__).resolve().parent
226+
python_dir = script_dir.parent
227+
sys.path.insert(0, str(python_dir))
233228
add_docstrings_to_stubs(args.stubs_dir.resolve())

python/setup.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,35 @@ def _update_stubs(self):
133133
build_cmd = self.get_finalized_command('build')
134134
build_lib = os.path.abspath(build_cmd.build_lib)
135135

136-
# Import here to avoid hard dependency on the dev script
137-
sys.path.insert(0, pjoin(setup_dir, '..', 'dev'))
136+
# Import the stub docstring updater from python/scripts
137+
sys.path.insert(0, pjoin(setup_dir, 'scripts'))
138138
try:
139-
from update_stub_docstrings import update_stubs_for_build
140-
update_stubs_for_build(stubs_dir, build_lib)
141-
except ImportError:
142-
print("-- Skipping stubs (update_stub_docstrings.py not found)")
139+
from update_stub_docstrings import add_docstrings_from_build
140+
add_docstrings_from_build(stubs_dir, build_lib)
143141
finally:
144142
sys.path.pop(0)
145143

144+
# Copy stub files to build directory
145+
self._copy_stubs(stubs_dir, build_lib)
146+
147+
def _copy_stubs(self, stubs_dir, build_lib):
148+
"""Copy .pyi stub files to the build directory."""
149+
src_dir = pjoin(stubs_dir, 'pyarrow')
150+
dest_dir = pjoin(build_lib, 'pyarrow')
151+
152+
if not os.path.exists(src_dir):
153+
return
154+
155+
print(f"-- Copying stubs: {src_dir} -> {dest_dir}")
156+
for root, dirs, files in os.walk(src_dir):
157+
for fname in files:
158+
if fname.endswith('.pyi'):
159+
src = pjoin(root, fname)
160+
rel_path = os.path.relpath(src, src_dir)
161+
dest = pjoin(dest_dir, rel_path)
162+
os.makedirs(os.path.dirname(dest), exist_ok=True)
163+
shutil.copy2(src, dest)
164+
146165
# adapted from cmake_build_ext in dynd-python
147166
# github.com/libdynd/dynd-python
148167

0 commit comments

Comments
 (0)