diff --git a/lib/iris/hatch_build.py b/lib/iris/hatch_build.py index 5b7d544d74..3b05b81d85 100644 --- a/lib/iris/hatch_build.py +++ b/lib/iris/hatch_build.py @@ -52,9 +52,14 @@ def _oldest_mtime(root: Path, globs: list[str]) -> float: return oldest if found else 0.0 -def _outputs_exist(root: Path, output_globs: list[str]) -> bool: - """Return True if at least one output file exists.""" - return _oldest_mtime(root, output_globs) > 0.0 +def _has_missing_outputs(root: Path, source_globs: list[str]) -> bool: + """Return True if any .proto source is missing its corresponding _pb2.py.""" + for pattern in source_globs: + for proto_path in root.glob(pattern): + pb2_path = proto_path.with_name(proto_path.stem + "_pb2.py") + if not pb2_path.exists(): + return True + return False 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: self._maybe_generate_protos(root) def _maybe_generate_protos(self, root: Path) -> None: - outputs_present = _outputs_exist(root, _PROTO_OUTPUT_GLOBS) + outputs_complete = not _has_missing_outputs(root, _PROTO_SOURCE_GLOBS) - if outputs_present and not _needs_rebuild(root, _PROTO_SOURCE_GLOBS, _PROTO_OUTPUT_GLOBS): + if outputs_complete and not _needs_rebuild(root, _PROTO_SOURCE_GLOBS, _PROTO_OUTPUT_GLOBS): logger.info("Protobuf outputs are up-to-date, skipping generation") return generate_script = root / "scripts" / "generate_protos.py" if not generate_script.exists(): - if not outputs_present: + if not outputs_complete: raise RuntimeError( "Protobuf outputs are missing and scripts/generate_protos.py not found. " "Cannot build iris without generated protobuf files." @@ -94,7 +99,7 @@ def _maybe_generate_protos(self, root: Path) -> None: return if shutil.which("npx") is None: - if not outputs_present: + if not outputs_complete: raise RuntimeError( "Protobuf outputs are missing and npx is not installed. " "Install Node.js (which provides npx) to generate protobuf files: " diff --git a/lib/iris/src/iris/rpc/__init__.py b/lib/iris/src/iris/rpc/__init__.py index 67d88e4c9d..9dea8586eb 100644 --- a/lib/iris/src/iris/rpc/__init__.py +++ b/lib/iris/src/iris/rpc/__init__.py @@ -2,8 +2,9 @@ # SPDX-License-Identifier: Apache-2.0 # Import order matters for proto descriptor pool: each module must be loaded -# after its dependencies. Chain: time → config → vm → cluster. +# after its dependencies. Chain: time → config → vm → query → cluster. from iris.rpc import time_pb2 as time_pb2 from iris.rpc import config_pb2 as config_pb2 from iris.rpc import vm_pb2 as vm_pb2 +from iris.rpc import query_pb2 as query_pb2 from iris.rpc import cluster_pb2 as cluster_pb2