Skip to content

Commit 03e9e65

Browse files
committed
Add ci for python tests
1 parent eb0bd86 commit 03e9e65

5 files changed

Lines changed: 139 additions & 10 deletions

File tree

.github/workflows/python-test.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Python Tests
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
paths:
8+
- python/**
9+
- rust/lance-graph/**
10+
- .github/workflows/python-test.yml
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
14+
cancel-in-progress: true
15+
16+
env:
17+
CARGO_TERM_COLOR: always
18+
RUSTFLAGS: "-C debuginfo=1"
19+
20+
jobs:
21+
test:
22+
runs-on: ubuntu-24.04
23+
timeout-minutes: 30
24+
strategy:
25+
matrix:
26+
python-version: ["3.11"]
27+
steps:
28+
- uses: actions/checkout@v4
29+
- name: Set up Python ${{ matrix.python-version }}
30+
uses: actions/setup-python@v4
31+
with:
32+
python-version: ${{ matrix.python-version }}
33+
- name: Setup Rust
34+
uses: actions-rust-lang/setup-rust-toolchain@v1
35+
- uses: Swatinem/rust-cache@v2
36+
with:
37+
workspaces: python
38+
- name: Install dependencies
39+
run: |
40+
sudo apt update
41+
sudo apt install -y protobuf-compiler
42+
- name: Install uv
43+
uses: astral-sh/setup-uv@v3
44+
- name: Create virtual environment and install dependencies
45+
working-directory: python
46+
run: |
47+
uv venv
48+
source .venv/bin/activate
49+
uv pip install maturin[patchelf]
50+
uv pip install -e .[tests]
51+
- name: Build Python extension
52+
working-directory: python
53+
run: |
54+
source .venv/bin/activate
55+
maturin develop
56+
- name: Run tests
57+
working-directory: python
58+
run: |
59+
source .venv/bin/activate
60+
pytest python/tests/ -v
61+
- name: Run doctests
62+
working-directory: python
63+
run: |
64+
source .venv/bin/activate
65+
if [ -f python/lance_graph/__init__.py ]; then
66+
python -m doctest python/lance_graph/__init__.py || echo "No doctests found"
67+
fi
68+
69+
lint:
70+
runs-on: ubuntu-24.04
71+
timeout-minutes: 15
72+
steps:
73+
- uses: actions/checkout@v4
74+
- name: Set up Python
75+
uses: actions/setup-python@v4
76+
with:
77+
python-version: "3.11"
78+
- name: Install uv
79+
uses: astral-sh/setup-uv@v3
80+
- name: Install dependencies
81+
working-directory: python
82+
run: |
83+
uv venv
84+
source .venv/bin/activate
85+
uv pip install -e .[dev]
86+
- name: Run ruff format check
87+
working-directory: python
88+
run: |
89+
source .venv/bin/activate
90+
ruff format --check python/
91+
- name: Run ruff lint
92+
working-directory: python
93+
run: |
94+
source .venv/bin/activate
95+
ruff check python/
96+
- name: Run pyright type check
97+
working-directory: python
98+
run: |
99+
source .venv/bin/activate
100+
pyright

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ cargo test
2626
```bash
2727
cd python
2828
uv venv --python 3.11 .venv # create the local virtualenv
29+
source .venv/bin/activate # activate the virtual environment
30+
uv pip install maturin[patchelf] # install build tool
2931
uv pip install -e '.[tests]' # editable install with test extras
30-
uv run --extra tests pytest python/python/tests/test_graph.py
32+
maturin develop # build and install the Rust extension
33+
pytest python/tests/ -v # run the test suite
3134
```
3235

3336
> If another virtual environment is already active, run `deactivate` (or
@@ -59,11 +62,19 @@ result = query.execute({"Person": people})
5962
print(result.to_pydict()) # {'name': ['Bob', 'David'], 'age': [34, 42]}
6063
```
6164

62-
Optional linters and type checks:
65+
### Development workflow
66+
67+
For linting and type checks:
6368

6469
```bash
65-
uv run --extra dev ruff check python
66-
uv run --extra dev pyright
70+
# Install dev dependencies and run linters
71+
uv pip install -e '.[dev]'
72+
ruff format python/ # format code
73+
ruff check python/ # lint code
74+
pyright # type check
75+
76+
# Or run individual tests
77+
pytest python/tests/test_graph.py::test_basic_node_selection -v
6778
```
6879

6980
The Python README (`python/README.md`) contains additional details if you are

python/README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,31 @@ to manage dependencies inside a project-local `.venv`.
99
```bash
1010
cd python
1111
uv venv --python 3.11 .venv
12+
source .venv/bin/activate
13+
uv pip install maturin[patchelf]
1214
uv pip install -e '.[tests]'
13-
uv run --extra tests pytest python/python/tests/test_graph.py
15+
maturin develop
16+
pytest python/tests/ -v
1417
```
1518

16-
For linting and type checks install the optional `dev` extra:
19+
## Development workflow
20+
21+
For linting and type checks:
1722

1823
```bash
19-
uv run --extra dev ruff check python
20-
uv run --extra dev pyright
24+
# Install dev dependencies
25+
uv pip install -e '.[dev]'
26+
27+
# Run linters and type checker
28+
ruff format python/ # format code
29+
ruff check python/ # lint code
30+
pyright # type check
31+
32+
# Run specific tests
33+
pytest python/tests/test_graph.py::test_basic_node_selection -v
34+
35+
# Rebuild extension after Rust changes
36+
maturin develop
2137
```
2238

2339
> If another virtual environment is already active, run `deactivate` (or

python/python/lance_graph/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import importlib.util
66
import sys
77
from pathlib import Path
8-
from types import ModuleType
8+
from typing import TYPE_CHECKING
9+
10+
if TYPE_CHECKING:
11+
from types import ModuleType
912

1013

1114
def _load_bindings() -> ModuleType:

python/python/tests/test_graph.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import pyarrow as pa
55
import pytest
6-
76
from lance_graph import CypherQuery, GraphConfig
87

98

0 commit comments

Comments
 (0)