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
161 changes: 161 additions & 0 deletions ci/scripts/python_wheel_check_cloudfs_split.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# 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 base64
import hashlib
import os
import subprocess
import sys
import tempfile
import zipfile

from pyarrow.lib import ArrowInvalid

# (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"),
]

MISMATCHED_VERSION = "0.0.1"


def write_empty_cloudfs_wheel(directory, version):
"""Write an empty pyarrow-cloudfs wheel, without needing a build backend."""
dist_info = f"pyarrow_cloudfs-{version}.dist-info"
files = {
"pyarrow_cloudfs/__init__.py": b"",
f"{dist_info}/METADATA": (
"Metadata-Version: 2.1\n"
"Name: pyarrow-cloudfs\n"
f"Version: {version}\n"
).encode(),
f"{dist_info}/WHEEL": (
"Wheel-Version: 1.0\n"
"Generator: arrow-ci\n"
"Root-Is-Purelib: true\n"
"Tag: py3-none-any\n"
).encode(),
}
record = []
for path, content in files.items():
digest = base64.urlsafe_b64encode(
hashlib.sha256(content).digest()).rstrip(b"=").decode()
record.append(f"{path},sha256={digest},{len(content)}")
record.append(f"{dist_info}/RECORD,,")
files[f"{dist_info}/RECORD"] = ("\n".join(record) + "\n").encode()

wheel_path = os.path.join(
directory, f"pyarrow_cloudfs-{version}-py3-none-any.whl")
with zipfile.ZipFile(wheel_path, "w") as wheel:
for path, content in files.items():
wheel.writestr(path, content)
return wheel_path


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_cloudfs_wheel(directory, 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]}")
12 changes: 12 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,15 @@ 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
21 changes: 17 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,16 @@ 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
fi

if [ "${CHECK_IMPORTS}" == "ON" ]; then
Expand All @@ -74,11 +82,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
3 changes: 2 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,8 @@ 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 sits 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
27 changes: 27 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,35 @@ 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.
%PYTHON_CMD% -m delvewheel repair -vv ^
--ignore-existing --with-mangle ^
--exclude "arrow_s3.dll;arrow_gcs.dll;arrow_azure.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

popd
14 changes: 11 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,20 @@ 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 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
27 changes: 26 additions & 1 deletion ci/scripts/python_wheel_xlinux_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,31 @@ popd

rm -rf dist/temp-fix-wheel

build_cloudfs=OFF
if [ "${ARROW_S3}" == "ON" ] || [ "${ARROW_GCS}" == "ON" ] || [ "${ARROW_AZURE}" == "ON" ]; then
build_cloudfs=ON
fi

if [ "${build_cloudfs}" == "ON" ]; then
echo "=== (${PYTHON_VERSION}) Building pyarrow-cloudfs wheel ==="
# CMake pulls libarrow_s3, libarrow_gcs and libarrow_azure from
# /tmp/arrow-dist via CMAKE_PREFIX_PATH.
python -m build --wheel --no-isolation --outdir dist \
-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
fi

echo "=== (${PYTHON_VERSION}) Tag the wheel with ${LINUX_WHEEL_KIND}${LINUX_WHEEL_VERSION} ==="
auditwheel repair dist/pyarrow-*.whl -w repaired_wheels
# libarrow ships in pyarrow, and libarrow_s3, libarrow_gcs and libarrow_azure
# in pyarrow-cloudfs: neither wheel may graft the other's libraries.
auditwheel repair \
--exclude 'libarrow_s3.so.*' \
--exclude 'libarrow_gcs.so.*' \
--exclude 'libarrow_azure.so.*' \
dist/pyarrow-*.whl -w repaired_wheels
if [ "${build_cloudfs}" == "ON" ]; then
auditwheel repair --exclude 'libarrow.so.*' dist/pyarrow_cloudfs-*.whl -w repaired_wheels
fi
popd
44 changes: 24 additions & 20 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ if(UNIX AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
# loaded properly
if(APPLE)
set(CMAKE_INSTALL_NAME_DIR "@rpath")
set(CMAKE_INSTALL_RPATH "@loader_path/")
set(PYARROW_RPATH_ORIGIN "@loader_path")
else()
set(CMAKE_INSTALL_RPATH "\$ORIGIN")
set(PYARROW_RPATH_ORIGIN "\$ORIGIN")
endif()
set(CMAKE_INSTALL_RPATH "${PYARROW_RPATH_ORIGIN}/")
endif()

find_program(CCACHE_FOUND ccache)
Expand Down Expand Up @@ -731,12 +732,8 @@ if(PYARROW_BUILD_AZURE)
endif()
find_package(ArrowAzure REQUIRED)
if(ARROW_BUILD_SHARED)
if(PYARROW_BUNDLE_ARROW_CPP)
bundle_arrow_lib(${ARROW_AZURE_SHARED_LIB} SO_VERSION ${ARROW_SO_VERSION})
if(MSVC)
bundle_arrow_import_lib(${ARROW_AZURE_IMPORT_LIB})
endif()
endif()
# Not bundled in the PyArrow wheel: it ships in the separate
# pyarrow-cloudfs wheel (python/pyarrow-cloudfs).
set(AZURE_LINK_LIBS ArrowAzure::arrow_azure_shared)
else()
set(AZURE_LINK_LIBS ArrowAzure::arrow_azure_static)
Expand All @@ -751,12 +748,8 @@ if(PYARROW_BUILD_GCS)
endif()
find_package(ArrowGcs REQUIRED)
if(ARROW_BUILD_SHARED)
if(PYARROW_BUNDLE_ARROW_CPP)
bundle_arrow_lib(${ARROW_GCS_SHARED_LIB} SO_VERSION ${ARROW_SO_VERSION})
if(MSVC)
bundle_arrow_import_lib(${ARROW_GCS_IMPORT_LIB})
endif()
endif()
# Not bundled in the PyArrow wheel: it ships in the separate
# pyarrow-cloudfs wheel (python/pyarrow-cloudfs).
set(GCS_LINK_LIBS ArrowGcs::arrow_gcs_shared)
else()
set(GCS_LINK_LIBS ArrowGcs::arrow_gcs_static)
Expand All @@ -771,12 +764,8 @@ if(PYARROW_BUILD_S3)
endif()
find_package(ArrowS3 REQUIRED)
if(ARROW_BUILD_SHARED)
if(PYARROW_BUNDLE_ARROW_CPP)
bundle_arrow_lib(${ARROW_S3_SHARED_LIB} SO_VERSION ${ARROW_SO_VERSION})
if(MSVC)
bundle_arrow_import_lib(${ARROW_S3_IMPORT_LIB})
endif()
endif()
# Not bundled in the PyArrow wheel: it ships in the separate
# pyarrow-cloudfs wheel (python/pyarrow-cloudfs).
set(S3_LINK_LIBS ArrowS3::arrow_s3_shared)
else()
set(S3_LINK_LIBS ArrowS3::arrow_s3_static)
Expand Down Expand Up @@ -1089,6 +1078,21 @@ if(PYARROW_BUILD_S3)
target_link_libraries(_s3fs PRIVATE ${S3_LINK_LIBS})
endif()

if(PYARROW_BUNDLE_ARROW_CPP AND UNIX)
# libarrow_s3, libarrow_gcs and libarrow_azure ship in the sibling
# pyarrow-cloudfs wheel, so they are not in any directory these extensions
# already search. Preloading them from pyarrow_cloudfs/__init__.py is not
# enough: musl's loader does not match a DT_NEEDED entry against a library
# that was opened by an explicit path.
foreach(cloudfs_extension _azurefs _gcsfs _s3fs)
if(TARGET ${cloudfs_extension})
set_property(TARGET ${cloudfs_extension}
APPEND
PROPERTY INSTALL_RPATH "${PYARROW_RPATH_ORIGIN}/../pyarrow_cloudfs")
endif()
endforeach()
endif()

#
# Type stubs with docstring injection
#
Expand Down
Loading
Loading