Skip to content

Commit 8c31d35

Browse files
committed
Notebook/Jupyter: Add example using JupySQL
1 parent bd0571f commit 8c31d35

File tree

10 files changed

+2926
-0
lines changed

10 files changed

+2926
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: pandas
2+
3+
on:
4+
pull_request:
5+
branches: ~
6+
paths:
7+
- '.github/workflows/notebook-jupyter.yml'
8+
- 'notebook/jupyter/**'
9+
- '/requirements.txt'
10+
push:
11+
branches: [ main ]
12+
paths:
13+
- '.github/workflows/notebook-jupyter.yml'
14+
- 'notebook/jupyter/**'
15+
- '/requirements.txt'
16+
17+
# Allow job to be triggered manually.
18+
workflow_dispatch:
19+
20+
# Run job each night after CrateDB nightly has been published.
21+
schedule:
22+
- cron: '0 3 * * *'
23+
24+
# Cancel in-progress jobs when pushing to the same branch.
25+
concurrency:
26+
cancel-in-progress: true
27+
group: ${{ github.workflow }}-${{ github.ref }}
28+
29+
jobs:
30+
test:
31+
name: "
32+
Python: ${{ matrix.python-version }}
33+
CrateDB: ${{ matrix.cratedb-version }}
34+
on ${{ matrix.os }}"
35+
runs-on: ${{ matrix.os }}
36+
strategy:
37+
fail-fast: false
38+
matrix:
39+
os: [ 'ubuntu-latest' ]
40+
python-version: [ '3.8', '3.13' ]
41+
cratedb-version: [ 'nightly' ]
42+
43+
env:
44+
OS_TYPE: ${{ matrix.os }}
45+
PYTHON_VERSION: ${{ matrix.python-version }}
46+
UV_SYSTEM_PYTHON: true
47+
48+
services:
49+
cratedb:
50+
image: crate/crate:${{ matrix.cratedb-version }}
51+
ports:
52+
- 4200:4200
53+
- 5432:5432
54+
env:
55+
CRATE_HEAP_SIZE: 4g
56+
57+
steps:
58+
59+
- name: Acquire sources
60+
uses: actions/checkout@v4
61+
62+
- name: Set up Python
63+
uses: actions/setup-python@v5
64+
with:
65+
python-version: ${{ matrix.python-version }}
66+
architecture: x64
67+
cache: 'pip'
68+
cache-dependency-path: |
69+
notebook/jupyter/pyproject.toml
70+
71+
- name: Set up uv
72+
uses: astral-sh/setup-uv@v5
73+
with:
74+
cache-dependency-glob: |
75+
notebook/jupyter/pyproject.toml
76+
cache-suffix: ${{ matrix.python-version }}
77+
enable-cache: true
78+
version: "latest"
79+
80+
- name: Install project
81+
run: |
82+
uv pip install notebook/jupyter[all]
83+
84+
- name: Validate notebook/jupyter
85+
run: |
86+
cd notebook/jupyter
87+
pytest
88+
89+
- name: Build docs for notebook/jupyter
90+
run: |
91+
cd notebook/jupyter
92+
poe check
93+
poe docs-html
94+
poe docs-linkcheck

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.idea
22
.venv*
33
__pycache__
4+
_build
45
.coverage*
56
.env
67
.DS_Store
@@ -14,3 +15,4 @@ logs.log
1415
*.tmp
1516
*.swp
1617
*.bak
18+
*.egg-info

notebook/jupyter/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# CrateDB Jupyter Examples
2+
3+
A few examples using CrateDB from Jupyter Notebooks.
4+
If you are here already, we recommend to check out the [JupySQL] examples
5+
at least.
6+
7+
8+
[JupySQL]: https://jupysql.ploomber.io/

notebook/jupyter/conftest.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os
2+
from pathlib import Path
3+
4+
import pytest
5+
import sqlalchemy as sa
6+
from pueblo.testing.notebook import generate_tests
7+
8+
9+
def pytest_generate_tests(metafunc):
10+
"""
11+
Generate pytest test case per Jupyter Notebook.
12+
"""
13+
here = Path(__file__).parent
14+
generate_tests(metafunc, path=here)
15+
16+
17+
@pytest.fixture(autouse=True)
18+
def reset_database_tables():
19+
"""
20+
Before running a test case, reset relevant tables in database.
21+
"""
22+
23+
connection_string = os.environ.get("CRATEDB_CONNECTION_STRING")
24+
25+
engine = sa.create_engine(connection_string, echo=os.environ.get("DEBUG"))
26+
connection = engine.connect()
27+
28+
reset_tables = []
29+
30+
for table in reset_tables:
31+
connection.execute(sa.text(f"DROP TABLE IF EXISTS {table};"))

notebook/jupyter/docs/conf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
project = "CrateDB Jupyter Examples"
2+
copyright = "2023-2025, The CrateDB Developers"
3+
author = "The CrateDB Developers"
4+
5+
html_theme = "furo"
6+
extensions = ["myst_nb"]

notebook/jupyter/docs/index.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# CrateDB Jupyter Examples
2+
3+
This is a little Sphinx documentation stub that includes Jupyter Notebooks,
4+
by using [MyST-NB].
5+
6+
```{toctree}
7+
:maxdepth: 2
8+
:glob:
9+
10+
*
11+
```
12+
13+
14+
[MyST-NB]: https://myst-nb.readthedocs.io/

notebook/jupyter/docs/jupysql.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../jupysql.ipynb

0 commit comments

Comments
 (0)