Skip to content

Commit 5f2f608

Browse files
committed
fix up c++ cookbook
1 parent c8d2930 commit 5f2f608

File tree

9 files changed

+50
-17
lines changed

9 files changed

+50
-17
lines changed

.github/workflows/native-unix.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,17 @@ jobs:
710710
- name: Test Recipes (C++)
711711
run: |
712712
./ci/scripts/cpp_recipe.sh $(pwd) ~/local build/recipe
713+
- name: Ensure recipes are up to date
714+
run: |
715+
pip install -e ./docs/source/ext/sphinx_recipe
716+
# Exits 1 if any recipes were updated
717+
python -m sphinx_recipe.update_output \
718+
docs/source/cpp/recipe/*.cc \
719+
docs/source/cpp/recipe_driver/driver_example.py \
720+
docs/source/python/recipe/*.py
713721
- name: Test Recipes (Python)
714722
run: |
715723
docker compose up --detach --wait dremio dremio-init flightsql-sqlite-test postgres-test
724+
# Needed for the combined C++/Python driver example
725+
export LD_LIBRARY_PATH=~/local/lib
716726
pytest -vvs docs/source/tests/

ci/scripts/cpp_recipe.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ test_recipe() {
3333
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${install_dir}/lib"
3434
export GOEXPERIMENT=cgocheck2
3535

36+
rm -rf "${build_dir}"
3637
mkdir -p "${build_dir}"
3738
pushd "${build_dir}"
3839

@@ -41,11 +42,12 @@ test_recipe() {
4142
${ADBC_CMAKE_ARGS} \
4243
-DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \
4344
-DCMAKE_INSTALL_LIBDIR=lib \
45+
-DCMAKE_INSTALL_PREFIX="${install_dir}" \
4446
-DCMAKE_PREFIX_PATH="${install_dir}" \
4547
-DADBC_DRIVER_EXAMPLE_BUILD_TESTS=ON
4648
set +x
4749

48-
cmake --build . -j
50+
cmake --build . --target install -j
4951
ctest \
5052
--output-on-failure \
5153
--no-tests=error

docs/source/cpp/recipe/CMakeLists.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ find_package(AdbcDriverManager REQUIRED)
3131
fetchcontent_declare(nanoarrow
3232
GIT_REPOSITORY https://github.com/apache/arrow-nanoarrow.git
3333
GIT_TAG apache-arrow-nanoarrow-0.2.0
34-
GIT_SHALLOW TRUE)
34+
GIT_SHALLOW TRUE
35+
EXCLUDE_FROM_ALL)
3536
fetchcontent_makeavailable(nanoarrow)
3637

37-
add_executable(quickstart quickstart.cc)
38-
target_include_directories(quickstart SYSTEM PRIVATE ${nanoarrow_SOURCE_DIR}/dist)
39-
target_link_libraries(quickstart PRIVATE AdbcDriverManager::adbc_driver_manager_shared
40-
nanoarrow)
41-
add_test(NAME quickstart COMMAND quickstart)
38+
add_executable(recipe-quickstart quickstart.cc)
39+
target_include_directories(recipe-quickstart SYSTEM PRIVATE ${nanoarrow_SOURCE_DIR}/dist)
40+
target_link_libraries(recipe-quickstart
41+
PRIVATE AdbcDriverManager::adbc_driver_manager_shared nanoarrow)
42+
add_test(NAME quickstart COMMAND recipe-quickstart)
43+
install(TARGETS recipe-quickstart)

docs/source/cpp/recipe/quickstart.stdout.txt

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/source/cpp/recipe_driver/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ target_include_directories(driver_example PRIVATE ../../../../c ../../../../c/in
4949
target_link_libraries(driver_example PRIVATE adbc_driver_framework
5050
nanoarrow::nanoarrow_ipc)
5151

52+
install(TARGETS driver_example)
53+
5254
if(ADBC_DRIVER_EXAMPLE_BUILD_TESTS)
5355
fetchcontent_declare(googletest
5456
URL https://github.com/google/googletest/archive/refs/tags/v1.15.1.tar.gz

docs/source/cpp/recipe_driver/driver_example.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def connect(uri: str):
4545
driver=str(driver_lib.resolve()), db_kwargs={"uri": uri}
4646
)
4747

48-
raise RuntimeError("Can't find driver shared object")
48+
# Try to find it on the dynamic loader path
49+
return dbapi.connect(driver="driver_example", db_kwargs={"uri": uri})
4950

5051

5152
#: Next, we can give our driver a go! The two pieces we implemented in the driver
@@ -63,5 +64,6 @@ def connect(uri: str):
6364
with con.cursor() as cur:
6465
cur.execute("SELECT * FROM example.arrows")
6566
print(cur.fetchall())
67+
# Output: [(1,), (2,), (3,)]
6668

6769
os.unlink(Path(__file__).parent / "example.arrows")

docs/source/cpp/recipe_driver/driver_example.stdout.txt

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/source/ext/sphinx_recipe/sphinx_recipe/update_output.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
"""Regenerate .stdout.txt files from recipes for the test harness."""
19+
1820
import argparse
1921
import sys
2022
from pathlib import Path
2123

2224
from . import parser as recipe_parser
2325

2426

25-
def main():
27+
def main() -> int:
2628
parser = argparse.ArgumentParser()
2729
parser.add_argument("recipes", nargs="+", type=Path, help="Recipe files to update")
2830

@@ -46,11 +48,18 @@ def main():
4648
continue
4749

4850
with target.open("w") as sink:
49-
sink.writelines(stdout)
51+
for line in stdout:
52+
sink.write(line)
53+
sink.write("\n")
5054
print(path, "updated")
5155
updated = True
5256

53-
return 1 if updated else 0
57+
if updated:
58+
print("----------------------------------------")
59+
print("Some .stdout.txt files were updated.")
60+
print("Please commit the result.")
61+
return 1
62+
return 0
5463

5564

5665
if __name__ == "__main__":

docs/source/tests/test_cookbook.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@
2222

2323

2424
def pytest_generate_tests(metafunc) -> None:
25-
root = (Path(__file__).parent.parent / "python/recipe/").resolve()
26-
recipes = root.rglob("*.py")
27-
metafunc.parametrize(
28-
"recipe", [pytest.param(path, id=path.stem) for path in recipes]
29-
)
25+
params = []
26+
for root in (
27+
(Path(__file__).parent.parent / "cpp/recipe_driver/").resolve(),
28+
(Path(__file__).parent.parent / "python/recipe/").resolve(),
29+
):
30+
recipes = root.rglob("*.py")
31+
params.extend(pytest.param(path, id=path.stem) for path in recipes)
32+
metafunc.parametrize("recipe", params)
3033

3134

3235
def test_cookbook_recipe(recipe: Path, capsys: pytest.CaptureFixture) -> None:
33-
spec = importlib.util.spec_from_file_location(f"cookbook.{recipe.stem}", recipe)
36+
spec = importlib.util.spec_from_file_location("__main__", recipe)
3437
mod = importlib.util.module_from_spec(spec)
3538
spec.loader.exec_module(mod)
3639

0 commit comments

Comments
 (0)