Skip to content

Commit 23c5bb2

Browse files
authored
fix(python/adbc_driver_manager): load manifests from venv path (apache#3490)
Closes apache#3479.
1 parent eaf4e07 commit 23c5bb2

File tree

4 files changed

+86
-1
lines changed

4 files changed

+86
-1
lines changed

.github/workflows/native-unix.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,13 @@ jobs:
648648
- name: Typecheck Python
649649
run: |
650650
./ci/scripts/python_typecheck.sh "$(pwd)"
651+
- name: Run Python Docker-based integration tests
652+
if: runner.os == 'Linux'
653+
run: |
654+
# Self-contained tests using docker-compose
655+
656+
# Test that the driver manager can load manifests installed into a venv
657+
docker compose run python-venv
651658
652659
python-docs:
653660
name: "Documentation ${{ matrix.python }} (Conda/${{ matrix.os }})"

ci/scripts/python_venv_test.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
set -euo pipefail
21+
22+
main() {
23+
local -r source_root="${1}"
24+
local -r scratch="${2}"
25+
local -r sqlite_driver="${3}"
26+
27+
mkdir -p "${scratch}"
28+
python -m venv "${scratch}/.venv"
29+
source "${scratch}/.venv/bin/activate"
30+
31+
"${scratch}"/.venv/bin/python -m pip install "${source_root}"/python/adbc_driver_manager
32+
"${scratch}"/.venv/bin/python -m pip install pyarrow
33+
34+
mkdir -p "${scratch}/.venv/etc/adbc/drivers/"
35+
cat >"${scratch}/.venv/etc/adbc/drivers/sqlite.toml" <<EOF
36+
name = "SQLite"
37+
[Driver]
38+
shared = "${sqlite_driver}"
39+
EOF
40+
41+
cat >"${scratch}/test.py" <<EOF
42+
import adbc_driver_manager.dbapi
43+
44+
with adbc_driver_manager.dbapi.connect(driver="sqlite") as con:
45+
with con.cursor() as cur:
46+
cur.execute("SELECT 1")
47+
assert cur.fetchall() == [(1,)]
48+
EOF
49+
50+
"${scratch}"/.venv/bin/python "${scratch}/test.py"
51+
echo "PASSED: find manifest"
52+
53+
cat >"${scratch}/test2.py" <<EOF
54+
import adbc_driver_manager.dbapi
55+
56+
try:
57+
with adbc_driver_manager.dbapi.connect(driver="notfound") as con:
58+
pass
59+
except adbc_driver_manager.dbapi.Error as e:
60+
print(e)
61+
assert ".venv/etc/adbc/drivers" in str(e)
62+
else:
63+
assert False, "Expected exception"
64+
EOF
65+
66+
"${scratch}"/.venv/bin/python "${scratch}/test2.py"
67+
echo "PASSED: failed manifest contains the proper path in the exception"
68+
}
69+
70+
main "$@"

compose.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ services:
102102
- .:/adbc:delegated
103103
command: "/bin/bash -c 'env CMAKE_BUILD_TYPE=Release /adbc/ci/scripts/java_jni_build.sh /adbc /adbc/dist /adbc/local'"
104104

105+
############################### Python #####################################
106+
107+
python-venv:
108+
image: ${ARCH}/python:${PYTHON}
109+
volumes:
110+
- .:/adbc:delegated
111+
command: "/bin/bash -c 'apt update && apt install -y libsqlite3-dev build-essential cmake git && git config --global --add safe.directory /adbc && env BUILD_ALL=0 BUILD_DRIVER_SQLITE=1 ADBC_BUILD_TESTS=OFF ADBC_USE_ASAN=OFF ADBC_USE_UBSAN=OFF /adbc/ci/scripts/cpp_build.sh /adbc /adbc/build/venv && /adbc/ci/scripts/python_venv_test.sh /adbc /adbc/build/venv-test /adbc/build/venv/driver/sqlite/libadbc_driver_sqlite.so'"
112+
105113
############################ Python conda ##################################
106114

107115
# Must be run as docker compose run -e HOST_USER_ID=$(id -u) python-conda

python/adbc_driver_manager/adbc_driver_manager/_lib.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ cdef class AdbcDatabase(_AdbcHandle):
572572
if sys.prefix != sys.base_prefix:
573573
# if we're in a venv, add the venv prefix to the search path list
574574
status = AdbcDriverManagerDatabaseSetAdditionalSearchPathList(
575-
&self.database, _to_bytes(os.path.join(sys.prefix, 'etc/adbc'),
575+
&self.database, _to_bytes(os.path.join(sys.prefix, "etc/adbc/drivers"),
576576
"sys.prefix"),
577577
&c_error)
578578
check_error(status, &c_error)

0 commit comments

Comments
 (0)