Skip to content

Commit 4458828

Browse files
yonromaiclaude
andauthored
fix: detect missing proto outputs in iris hatch build hook (#3710)
## Summary - The hatch build hook only compared timestamps to decide if proto regeneration was needed. Adding `query.proto` (#3649) without a matching `query_pb2.py` broke all local `iris` CLI usage with `ImportError: cannot import name 'query_pb2'`. - Add `_has_missing_outputs()` to detect `.proto` files without a corresponding `_pb2.py`, and use it in the rebuild decision and fallback paths (missing `npx`/generate script) so they raise instead of silently continuing with incomplete outputs. - Add the missing `query_pb2` import to `rpc/__init__.py` (descriptor pool load order requires it before `cluster_pb2`). Fixes #3709 ## Test plan - [x] Reproduced `ImportError` on main, confirmed fix resolves it - [x] Verified `uv run iris --help` loads cleanly after fix - [x] Verified `_has_missing_outputs` correctly returns `True` when a `_pb2.py` is absent and `False` when all are present - [x] Pre-commit passes on changed files 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 73970cc commit 4458828

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

lib/iris/hatch_build.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,14 @@ def _oldest_mtime(root: Path, globs: list[str]) -> float:
5252
return oldest if found else 0.0
5353

5454

55-
def _outputs_exist(root: Path, output_globs: list[str]) -> bool:
56-
"""Return True if at least one output file exists."""
57-
return _oldest_mtime(root, output_globs) > 0.0
55+
def _has_missing_outputs(root: Path, source_globs: list[str]) -> bool:
56+
"""Return True if any .proto source is missing its corresponding _pb2.py."""
57+
for pattern in source_globs:
58+
for proto_path in root.glob(pattern):
59+
pb2_path = proto_path.with_name(proto_path.stem + "_pb2.py")
60+
if not pb2_path.exists():
61+
return True
62+
return False
5863

5964

6065
def _needs_rebuild(root: Path, source_globs: list[str], output_globs: list[str]) -> bool:
@@ -77,15 +82,15 @@ def initialize(self, version: str, build_data: dict) -> None:
7782
self._maybe_generate_protos(root)
7883

7984
def _maybe_generate_protos(self, root: Path) -> None:
80-
outputs_present = _outputs_exist(root, _PROTO_OUTPUT_GLOBS)
85+
outputs_complete = not _has_missing_outputs(root, _PROTO_SOURCE_GLOBS)
8186

82-
if outputs_present and not _needs_rebuild(root, _PROTO_SOURCE_GLOBS, _PROTO_OUTPUT_GLOBS):
87+
if outputs_complete and not _needs_rebuild(root, _PROTO_SOURCE_GLOBS, _PROTO_OUTPUT_GLOBS):
8388
logger.info("Protobuf outputs are up-to-date, skipping generation")
8489
return
8590

8691
generate_script = root / "scripts" / "generate_protos.py"
8792
if not generate_script.exists():
88-
if not outputs_present:
93+
if not outputs_complete:
8994
raise RuntimeError(
9095
"Protobuf outputs are missing and scripts/generate_protos.py not found. "
9196
"Cannot build iris without generated protobuf files."
@@ -94,7 +99,7 @@ def _maybe_generate_protos(self, root: Path) -> None:
9499
return
95100

96101
if shutil.which("npx") is None:
97-
if not outputs_present:
102+
if not outputs_complete:
98103
raise RuntimeError(
99104
"Protobuf outputs are missing and npx is not installed. "
100105
"Install Node.js (which provides npx) to generate protobuf files: "

lib/iris/src/iris/rpc/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
# Import order matters for proto descriptor pool: each module must be loaded
5-
# after its dependencies. Chain: time → config → vm → cluster.
5+
# after its dependencies. Chain: time → config → vm → query → cluster.
66
from iris.rpc import time_pb2 as time_pb2
77
from iris.rpc import config_pb2 as config_pb2
88
from iris.rpc import vm_pb2 as vm_pb2
9+
from iris.rpc import query_pb2 as query_pb2
910
from iris.rpc import cluster_pb2 as cluster_pb2

0 commit comments

Comments
 (0)