Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions ci/scripts/python_wheel_check_cloudfs_split.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# 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.

# Check S3, GCS and Azure against the pyarrow-cloudfs split.
#
# Usage: python_wheel_check_cloudfs_split.py missing|mismatch|installed
#
# missing: run with pyarrow installed but not pyarrow-cloudfs. Each enabled
# filesystem must fail with a message pointing at pyarrow-cloudfs, both
# from pyarrow.fs and from FileSystem.from_uri.
# mismatch: run with pyarrow installed but not pyarrow-cloudfs. Installs an
# empty pyarrow-cloudfs of another version, as 'pip install -U pyarrow'
# leaves behind after upgrading from a placeholder release, checks that each
# enabled filesystem fails with the command to install the matching
# version, then uninstalls it again.
# installed: run with both installed. FileSystem.from_uri must resolve each
# enabled filesystem even if pyarrow.fs was never imported.
#
# A filesystem is checked when its PYARROW_TEST_<NAME> variable is ON.

import os
import subprocess
import sys
import tempfile

from pyarrow.lib import ArrowInvalid

from python_wheel_empty_wheel import MISMATCHED_VERSION, write_empty_wheel

# (PYARROW_TEST_ variable, pyarrow.fs name, URI, FileSystem.type_name)
FILESYSTEMS = [
("PYARROW_TEST_S3", "S3FileSystem",
"s3://bucket/key?region=us-east-1", "s3"),
("PYARROW_TEST_GCS", "GcsFileSystem",
"gs://anonymous@bucket/key", "gcs"),
("PYARROW_TEST_AZURE", "AzureFileSystem",
"abfs://container@account.dfs.core.windows.net/key"
"?credential_kind=anonymous", "abfs"),
]

mode = sys.argv[1]
enabled = [fs for fs in FILESYSTEMS if os.environ.get(fs[0]) == "ON"]

if mode == "mismatch":
pip = [sys.executable, "-m", "pip"]
with tempfile.TemporaryDirectory() as directory:
wheel_path = write_empty_wheel(directory, "pyarrow-cloudfs",
MISMATCHED_VERSION)
subprocess.run(pip + ["install", "--no-deps", wheel_path], check=True)
try:
# A fresh interpreter, so pyarrow.fs runs its check at import time.
subprocess.run([sys.executable, __file__, "mismatch-check"], check=True)
finally:
subprocess.run(pip + ["uninstall", "--yes", "pyarrow-cloudfs"],
check=True)
print(f"Checked mismatch: {[name for _, name, _, _ in enabled]}")
sys.exit(0)

if mode == "mismatch-check":
import pyarrow
expected = f"pyarrow-cloudfs=={pyarrow.__version__}"

for _, name, uri, type_name in enabled:
if mode == "mismatch-check":
from pyarrow._fs import FileSystem
try:
FileSystem.from_uri(uri)
except ArrowInvalid as e:
assert expected in str(e), e
else:
raise AssertionError(f"from_uri resolved {uri} with a mismatched "
"pyarrow-cloudfs")

import pyarrow.fs as fs
try:
getattr(fs, name)
except ImportError as e:
assert expected in str(e), e
else:
raise AssertionError(f"{name} available with a mismatched "
"pyarrow-cloudfs")
elif mode == "missing":
try:
from pyarrow._fs import FileSystem
FileSystem.from_uri(uri)
except ArrowInvalid as e:
assert "pyarrow-cloudfs" in str(e), e
else:
raise AssertionError(f"from_uri resolved {uri} without pyarrow-cloudfs")

import pyarrow.fs as fs
try:
getattr(fs, name)
except ImportError as e:
assert "pyarrow-cloudfs" in str(e), e
else:
raise AssertionError(f"{name} available without pyarrow-cloudfs")
elif mode == "installed":
from pyarrow._fs import FileSystem
filesystem, _ = FileSystem.from_uri(uri)
assert filesystem.type_name == type_name, filesystem.type_name
else:
raise ValueError(f"unknown mode: {mode}")

if mode == "mismatch-check":
# The extensions must not have been imported: their RPATH would let the
# loader pick up the mismatched libraries.
for module in ("pyarrow._s3fs", "pyarrow._gcsfs", "pyarrow._azurefs"):
assert module not in sys.modules, module

print(f"Checked {mode}: {[name for _, name, _, _ in enabled]}")
79 changes: 79 additions & 0 deletions ci/scripts/python_wheel_check_flight_split.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# 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.

# Check Flight against the pyarrow-flight split.
#
# Usage: python_wheel_check_flight_split.py missing|mismatch|installed
#
# missing: run with pyarrow installed but not pyarrow-flight. Importing
# pyarrow.flight must fail with a message pointing at pyarrow-flight.
# mismatch: run with pyarrow installed but not pyarrow-flight. Installs an
# empty pyarrow-flight of another version, checks that importing
# pyarrow.flight fails with the command to install the matching version
# without importing pyarrow._flight, then uninstalls it again.
# installed: run with both installed. pyarrow.flight must import and a server
# must start, which needs libarrow_flight and the gRPC it bundles.

import subprocess
import sys
import tempfile

from python_wheel_empty_wheel import MISMATCHED_VERSION, write_empty_wheel

mode = sys.argv[1]

if mode == "mismatch":
pip = [sys.executable, "-m", "pip"]
with tempfile.TemporaryDirectory() as directory:
wheel_path = write_empty_wheel(directory, "pyarrow-flight",
MISMATCHED_VERSION)
subprocess.run(pip + ["install", "--no-deps", wheel_path], check=True)
try:
# A fresh interpreter, so pyarrow.flight runs its check at import.
subprocess.run([sys.executable, __file__, "mismatch-check"], check=True)
finally:
subprocess.run(pip + ["uninstall", "--yes", "pyarrow-flight"],
check=True)
elif mode == "mismatch-check":
import pyarrow
expected = f"pyarrow-flight=={pyarrow.__version__}"
try:
import pyarrow.flight # noqa: F401
except ImportError as e:
assert expected in str(e), e
else:
raise AssertionError("pyarrow.flight available with a mismatched "
"pyarrow-flight")
# The extension must not have been imported: its RPATH would let the
# loader pick up the mismatched library.
assert "pyarrow._flight" not in sys.modules
elif mode == "missing":
try:
import pyarrow.flight # noqa: F401
except ImportError as e:
assert "pyarrow-flight" in str(e), e
else:
raise AssertionError("pyarrow.flight available without pyarrow-flight")
elif mode == "installed":
import pyarrow.flight as flight
server = flight.FlightServerBase("grpc://localhost:0")
assert server.port > 0, server.port
server.shutdown()
else:
raise ValueError(f"unknown mode: {mode}")

print(f"Checked {mode}: Flight")
20 changes: 20 additions & 0 deletions ci/scripts/python_wheel_macos_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,23 @@ fi
# Move the verified wheels
mkdir -p "${source_dir}/python/repaired_wheels"
mv "${source_dir}"/python/dist/*.whl "${source_dir}"/python/repaired_wheels/

if [ "${ARROW_S3}" == "ON" ] || [ "${ARROW_GCS}" == "ON" ] || [ "${ARROW_AZURE}" == "ON" ]; then
echo "=== (${PYTHON_VERSION}) Building pyarrow-cloudfs wheel ==="
# CMake pulls libarrow_s3, libarrow_gcs and libarrow_azure from the Arrow
# install via CMAKE_PREFIX_PATH.
python -m build --wheel --no-isolation \
--outdir "${source_dir}/python/repaired_wheels" \
-C cmake.define.PYARROW_CLOUDFS_S3="${ARROW_S3}" \
-C cmake.define.PYARROW_CLOUDFS_GCS="${ARROW_GCS}" \
-C cmake.define.PYARROW_CLOUDFS_AZURE="${ARROW_AZURE}" \
"${source_dir}/python/pyarrow-cloudfs"
fi

if [ "${ARROW_FLIGHT}" == "ON" ]; then
echo "=== (${PYTHON_VERSION}) Building pyarrow-flight wheel ==="
# CMake pulls libarrow_flight from the Arrow install via CMAKE_PREFIX_PATH.
python -m build --wheel --no-isolation \
--outdir "${source_dir}/python/repaired_wheels" \
"${source_dir}/python/pyarrow-flight"
fi
28 changes: 24 additions & 4 deletions ci/scripts/python_wheel_unix_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,23 @@ export ARROW_TEST_DATA=${source_dir}/testing/data
export PARQUET_TEST_DATA=${source_dir}/cpp/submodules/parquet-testing/data

if [ "${INSTALL_PYARROW}" == "ON" ]; then
# Install the built wheels
python -m pip install "${source_dir}"/python/repaired_wheels/*.whl
# Install the core wheel alone first: S3, GCS and Azure ship in the
# separate pyarrow-cloudfs wheel, so check that they fail with an
# actionable message without it.
python -m pip install "${source_dir}"/python/repaired_wheels/pyarrow-*.whl
if [ "${PYARROW_TEST_S3}" == "ON" ] || [ "${PYARROW_TEST_GCS}" == "ON" ] || [ "${PYARROW_TEST_AZURE}" == "ON" ]; then
python "${source_dir}/ci/scripts/python_wheel_check_cloudfs_split.py" missing
python "${source_dir}/ci/scripts/python_wheel_check_cloudfs_split.py" mismatch
python -m pip install "${source_dir}"/python/repaired_wheels/pyarrow_cloudfs-*.whl
python "${source_dir}/ci/scripts/python_wheel_check_cloudfs_split.py" installed
fi
# Flight ships in the separate pyarrow-flight wheel.
if [ "${PYARROW_TEST_FLIGHT}" == "ON" ]; then
python "${source_dir}/ci/scripts/python_wheel_check_flight_split.py" missing
python "${source_dir}/ci/scripts/python_wheel_check_flight_split.py" mismatch
python -m pip install "${source_dir}"/python/repaired_wheels/pyarrow_flight-*.whl
python "${source_dir}/ci/scripts/python_wheel_check_flight_split.py" installed
fi
fi

if [ "${CHECK_IMPORTS}" == "ON" ]; then
Expand All @@ -74,11 +89,16 @@ import pyarrow.json
import pyarrow.orc
import pyarrow.parquet
"
# S3, GCS and Azure ship in the separate pyarrow-cloudfs wheel, which
# pyarrow.fs loads, so import them through pyarrow.fs.
if [ "${PYARROW_TEST_AZURE}" == "ON" ]; then
python -c "import pyarrow.fs; pyarrow.fs.AzureFileSystem"
fi
if [ "${PYARROW_TEST_GCS}" == "ON" ]; then
python -c "import pyarrow._gcsfs"
python -c "import pyarrow.fs; pyarrow.fs.GcsFileSystem"
fi
if [ "${PYARROW_TEST_S3}" == "ON" ]; then
python -c "import pyarrow._s3fs"
python -c "import pyarrow.fs; pyarrow.fs.S3FileSystem"
fi
if [ "${PYARROW_TEST_FLIGHT}" == "ON" ]; then
python -c "import pyarrow.flight"
Expand Down
4 changes: 3 additions & 1 deletion ci/scripts/python_wheel_validate_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def _count_docstrings(source):
# TODO(GH-48970): Check stubs ARE present once annotations are complete
def validate_wheel(path):
p = Path(path)
wheels = list(p.glob('*.whl'))
# Only the core pyarrow wheel; pyarrow_cloudfs-*.whl and
# pyarrow_flight-*.whl sit alongside it.
wheels = list(p.glob('pyarrow-*.whl'))
error_msg = f"{len(wheels)} wheels found but only 1 expected ({wheels})"
assert len(wheels) == 1, error_msg
with zipfile.ZipFile(wheels[0]) as wheel_zip:
Expand Down
43 changes: 43 additions & 0 deletions ci/scripts/python_wheel_windows_build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,51 @@ pushd C:\arrow\python
for /f %%i in ('dir dist\pyarrow-*.whl /B') do (set WHEEL_NAME=%cd%\dist\%%i) || exit /B 1
echo "Wheel name: %WHEEL_NAME%"

@REM arrow_s3.dll, arrow_gcs.dll and arrow_azure.dll ship in the separate
@REM pyarrow-cloudfs wheel, arrow_flight.dll in the pyarrow-flight wheel.
%PYTHON_CMD% -m delvewheel repair -vv ^
--ignore-existing --with-mangle ^
--exclude "arrow_s3.dll;arrow_gcs.dll;arrow_azure.dll;arrow_flight.dll" ^
-w repaired_wheels %WHEEL_NAME% || exit /B 1

set BUILD_CLOUDFS=OFF
if "%ARROW_S3%"=="ON" set BUILD_CLOUDFS=ON
if "%ARROW_GCS%"=="ON" set BUILD_CLOUDFS=ON
if "%ARROW_AZURE%"=="ON" set BUILD_CLOUDFS=ON
if not "%BUILD_CLOUDFS%"=="ON" goto :skip_pyarrow_cloudfs

@REM Build pyarrow-cloudfs: CMake pulls arrow_s3.dll, arrow_gcs.dll and
@REM arrow_azure.dll from C:\arrow-dist via CMAKE_PREFIX_PATH.
%PYTHON_CMD% -m build --wheel --no-isolation --outdir dist-cloudfs ^
-C cmake.define.PYARROW_CLOUDFS_S3=%ARROW_S3% ^
-C cmake.define.PYARROW_CLOUDFS_GCS=%ARROW_GCS% ^
-C cmake.define.PYARROW_CLOUDFS_AZURE=%ARROW_AZURE% ^
pyarrow-cloudfs || exit /B 1

for /f %%i in ('dir dist-cloudfs\pyarrow_cloudfs-*.whl /B') do (set CLOUDFS_WHEEL_NAME=%cd%\dist-cloudfs\%%i) || exit /B 1
echo "pyarrow-cloudfs wheel name: %CLOUDFS_WHEEL_NAME%"

@REM arrow.dll ships in the pyarrow wheel.
%PYTHON_CMD% -m delvewheel repair -vv ^
--ignore-existing --analyze-existing --with-mangle --exclude arrow.dll ^
-w repaired_wheels %CLOUDFS_WHEEL_NAME% || exit /B 1

:skip_pyarrow_cloudfs

if not "%ARROW_FLIGHT%"=="ON" goto :skip_pyarrow_flight

@REM Build pyarrow-flight: CMake pulls arrow_flight.dll from C:\arrow-dist via
@REM CMAKE_PREFIX_PATH.
%PYTHON_CMD% -m build --wheel --no-isolation --outdir dist-flight pyarrow-flight || exit /B 1

for /f %%i in ('dir dist-flight\pyarrow_flight-*.whl /B') do (set FLIGHT_WHEEL_NAME=%cd%\dist-flight\%%i) || exit /B 1
echo "pyarrow-flight wheel name: %FLIGHT_WHEEL_NAME%"

@REM arrow.dll ships in the pyarrow wheel.
%PYTHON_CMD% -m delvewheel repair -vv ^
--ignore-existing --analyze-existing --with-mangle --exclude arrow.dll ^
-w repaired_wheels %FLIGHT_WHEEL_NAME% || exit /B 1

:skip_pyarrow_flight

popd
20 changes: 17 additions & 3 deletions ci/scripts/python_wheel_windows_test.bat
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,26 @@ py -0p
@REM Install the built wheels
%PYTHON_CMD% -m pip install --no-index --find-links=C:\arrow\python\repaired_wheels pyarrow || exit /B 1

@REM S3, GCS and Azure ship in the separate pyarrow-cloudfs wheel: with only
@REM pyarrow installed, check that they fail with an actionable message, then
@REM install it and check that they work.
%PYTHON_CMD% C:\arrow\ci\scripts\python_wheel_check_cloudfs_split.py missing || exit /B 1
%PYTHON_CMD% C:\arrow\ci\scripts\python_wheel_check_cloudfs_split.py mismatch || exit /B 1
%PYTHON_CMD% -m pip install --no-index --find-links=C:\arrow\python\repaired_wheels pyarrow-cloudfs || exit /B 1
%PYTHON_CMD% C:\arrow\ci\scripts\python_wheel_check_cloudfs_split.py installed || exit /B 1

@REM Flight ships in the separate pyarrow-flight wheel.
%PYTHON_CMD% C:\arrow\ci\scripts\python_wheel_check_flight_split.py missing || exit /B 1
%PYTHON_CMD% C:\arrow\ci\scripts\python_wheel_check_flight_split.py mismatch || exit /B 1
%PYTHON_CMD% -m pip install --no-index --find-links=C:\arrow\python\repaired_wheels pyarrow-flight || exit /B 1
%PYTHON_CMD% C:\arrow\ci\scripts\python_wheel_check_flight_split.py installed || exit /B 1

@REM Test that the modules are importable
%PYTHON_CMD% -c "import pyarrow" || exit /B 1
%PYTHON_CMD% -c "import pyarrow._azurefs" || exit /B 1
%PYTHON_CMD% -c "import pyarrow._gcsfs" || exit /B 1
%PYTHON_CMD% -c "import pyarrow.fs; pyarrow.fs.AzureFileSystem" || exit /B 1
%PYTHON_CMD% -c "import pyarrow.fs; pyarrow.fs.GcsFileSystem" || exit /B 1
%PYTHON_CMD% -c "import pyarrow._hdfs" || exit /B 1
%PYTHON_CMD% -c "import pyarrow._s3fs" || exit /B 1
%PYTHON_CMD% -c "import pyarrow.fs; pyarrow.fs.S3FileSystem" || exit /B 1
%PYTHON_CMD% -c "import pyarrow.csv" || exit /B 1
%PYTHON_CMD% -c "import pyarrow.dataset" || exit /B 1
%PYTHON_CMD% -c "import pyarrow.flight" || exit /B 1
Expand Down
Loading
Loading