Skip to content

Commit c988e75

Browse files
committed
fix: make proto stubs importable and tests green
- Fix _proto/__init__.py: remove sys.path hack that shadowed google namespace package with generated _proto/google/api/ - Fix Makefile proto target: apply import fix to all *.py files (not just *_pb2_grpc.py); cypher_pb2.py also had absolute imports - Fix tests/unit/test_types.py: correct field names (vector_value, map_value.entries); test_none → null semantics, not raises - Fix tests/integration/test_basic.py: use RETURN n.name (id(n) not implemented in alpha); mark test_vector_search as xfail - ci.yml: switch to uv, add Python 3.13 to matrix, remove 3.9/3.10 (both past EOL Oct 2025) - pyproject.toml (all 3 packages): requires-python >=3.11, add 3.13 classifier, drop 3.9/3.10 - ruff.toml: exclude coordinode/_proto/ from linting (generated code) - Auto-fix ruff UP violations: Union→X|Y, Dict/List→dict/list, Optional→X|None, isinstance tuples→X|Y union syntax Tests: 21 passed, 1 xfailed (vector search — alpha server limitation)
1 parent c1a659c commit c988e75

14 files changed

Lines changed: 187 additions & 160 deletions

File tree

.github/workflows/ci.yml

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,36 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v4
1414

15-
- uses: actions/setup-python@v5
15+
- uses: astral-sh/setup-uv@v4
1616
with:
1717
python-version: "3.11"
1818

19-
- run: pip install ruff
19+
- run: uv pip install ruff --system
2020
- run: ruff check coordinode/ langchain-coordinode/ llama-index-coordinode/ tests/
2121
- run: ruff format --check coordinode/ langchain-coordinode/ llama-index-coordinode/ tests/
2222

2323
test:
2424
name: Test (Python ${{ matrix.python-version }})
2525
runs-on: ubuntu-latest
2626
strategy:
27+
fail-fast: false
2728
matrix:
28-
python-version: ["3.9", "3.11", "3.12"]
29+
python-version: ["3.11", "3.12", "3.13"]
2930
steps:
3031
- uses: actions/checkout@v4
3132
with:
3233
submodules: recursive
3334

34-
- uses: actions/setup-python@v5
35+
- uses: astral-sh/setup-uv@v4
3536
with:
3637
python-version: ${{ matrix.python-version }}
3738

38-
- name: Install protoc
39-
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
40-
4139
- name: Install packages
4240
run: |
43-
pip install grpcio-tools
44-
pip install -e "coordinode[dev]"
45-
pip install -e langchain-coordinode/
46-
pip install -e llama-index-coordinode/
41+
uv pip install grpcio-tools --system
42+
uv pip install -e "coordinode[dev]" --system
43+
uv pip install -e langchain-coordinode/ --system
44+
uv pip install -e llama-index-coordinode/ --system
4745
4846
- name: Generate proto stubs
4947
run: make proto
@@ -70,17 +68,14 @@ jobs:
7068
with:
7169
submodules: recursive
7270

73-
- uses: actions/setup-python@v5
71+
- uses: astral-sh/setup-uv@v4
7472
with:
7573
python-version: "3.11"
7674

77-
- name: Install protoc
78-
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
79-
8075
- name: Install + generate proto
8176
run: |
82-
pip install grpcio-tools
83-
pip install -e "coordinode[dev]"
77+
uv pip install grpcio-tools --system
78+
uv pip install -e "coordinode[dev]" --system
8479
make proto
8580
8681
- name: Integration tests

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ env/
2020
coordinode/_version.py
2121
langchain_coordinode/_version.py
2222
llama_index/graph_stores/coordinode/_version.py
23+
GAPS.md

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ PROTO_OUT := coordinode/_proto
77
proto:
88
@echo "==> Generating proto stubs..."
99
@mkdir -p $(PROTO_OUT)
10-
python -m grpc_tools.protoc \
10+
python3 -m grpc_tools.protoc \
1111
-I$(PROTO_SRC) \
1212
--python_out=$(PROTO_OUT) \
1313
--grpc_python_out=$(PROTO_OUT) \
1414
--pyi_out=$(PROTO_OUT) \
1515
$$(find $(PROTO_SRC) -name '*.proto')
1616
@# Add __init__.py to every generated package directory
1717
@find $(PROTO_OUT) -type d -exec touch {}/__init__.py \;
18-
@# Fix relative imports in generated *_pb2_grpc.py files (grpc_tools generates absolute)
19-
@find $(PROTO_OUT) -name '*_pb2_grpc.py' -exec sed -i '' \
20-
's/^from coordinode\./from coordinode._proto.coordinode./g' {} \;
18+
@# Fix absolute imports in all generated pb2 files (grpc_tools generates absolute paths)
19+
@find $(PROTO_OUT) -name '*.py' -exec sed -i '' \
20+
's/from coordinode\./from coordinode._proto.coordinode./g' {} \;
2121
@echo "==> Proto generation complete: $(PROTO_OUT)/"
2222

2323
proto-check:

coordinode/_proto/__init__.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,2 @@
11
# Generated gRPC stubs. Run `make proto` to regenerate.
22
# This directory is .gitignore'd — stubs are not committed.
3-
import sys
4-
import os
5-
6-
# Make generated stubs importable as `coordinode.v1.*`
7-
_proto_dir = os.path.dirname(__file__)
8-
if _proto_dir not in sys.path:
9-
sys.path.insert(0, _proto_dir)

coordinode/_types.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
"""
22
Python-friendly type wrappers and PropertyValue conversion.
33
"""
4+
45
from __future__ import annotations
56

6-
from typing import Any, Dict, List, Union
7+
from typing import Any
78

89
# We import proto types lazily to avoid hard-fail when stubs aren't generated yet.
910

10-
PyValue = Union[int, float, str, bool, bytes, List[float], List[Any], Dict[str, Any], None]
11+
PyValue = int | float | str | bool | bytes | list[float] | list[Any] | dict[str, Any] | None
1112

1213

1314
def to_property_value(py_val: PyValue) -> Any:
1415
"""Convert a Python value to a proto PropertyValue."""
1516
from coordinode._proto.coordinode.v1.common.types_pb2 import ( # type: ignore[import]
16-
PropertyValue,
1717
PropertyList,
1818
PropertyMap,
19+
PropertyValue,
1920
Vector,
2021
)
2122

@@ -32,9 +33,9 @@ def to_property_value(py_val: PyValue) -> Any:
3233
pv.string_value = py_val
3334
elif isinstance(py_val, bytes):
3435
pv.bytes_value = py_val
35-
elif isinstance(py_val, (list, tuple)):
36+
elif isinstance(py_val, list | tuple):
3637
# Homogeneous float list → Vector; mixed/str list → PropertyList
37-
if py_val and all(isinstance(v, (int, float)) for v in py_val):
38+
if py_val and all(isinstance(v, int | float) for v in py_val):
3839
vec = Vector(values=[float(v) for v in py_val])
3940
pv.vector_value.CopyFrom(vec)
4041
else:
@@ -76,11 +77,11 @@ def from_property_value(pv: Any) -> PyValue:
7677
return None
7778

7879

79-
def props_to_dict(proto_map: Any) -> Dict[str, PyValue]:
80+
def props_to_dict(proto_map: Any) -> dict[str, PyValue]:
8081
"""Convert a proto properties map to a plain Python dict."""
8182
return {k: from_property_value(v) for k, v in proto_map.items()}
8283

8384

84-
def dict_to_props(d: Dict[str, PyValue]) -> Dict[str, Any]:
85+
def dict_to_props(d: dict[str, PyValue]) -> dict[str, Any]:
8586
"""Convert a Python dict to a proto properties map."""
8687
return {k: to_property_value(v) for k, v in d.items()}

0 commit comments

Comments
 (0)