公開前の確認用サイト
日常訳NICHIJOYAKUEnglish ↗

OPEN SOURCE

software/scripts/compile_protos.py

このサイトで読み、必要なファイルを保存できます。

日常訳はAIを用いて作成された翻訳です。人間の聖書学・原語の専門家による全訳の検証は確認されていません。既存の翻訳や原語資料と照らし合わせてお読みください。

← オープンソースの案内へ

software/scripts/compile_protos.py107 行このファイルを保存 ↓

ZIPに含まれるものと同じ公開ソースです。行番号から、その行へのリンクを保存できます。

ファイルの確認情報SHA-256 40b27e78f1796bfe4fc4ad6197162a4f206679d97c4282525a0d8680ad3b1736
1#!/usr/bin/env python32"""Compile Protocol Buffer definitions to Python code.34This script compiles the .proto files in the protos/ directory to Python code5in the src/protos/ directory.67Usage:8    uv run python scripts/compile_protos.py910Requirements:11    Install the proto optional dependencies:12        uv pip install -e ".[proto]"13"""1415from __future__ import annotations1617import subprocess18import sys19from pathlib import Path202122def main() -> int:23    """Compile proto files to Python."""24    project_root = Path(__file__).parent.parent25    protos_dir = project_root / "protos"26    output_dir = project_root / "src" / "protos"2728    # Ensure directories exist29    protos_dir.mkdir(exist_ok=True)30    output_dir.mkdir(exist_ok=True)3132    # Find all .proto files33    proto_files = list(protos_dir.glob("*.proto"))3435    if not proto_files:36        print("No .proto files found in protos/ directory")37        return 13839    print(f"Found {len(proto_files)} proto file(s):")40    for pf in proto_files:41        print(f"  - {pf.name}")4243    # Compile each proto file44    for proto_file in proto_files:45        print(f"\nCompiling {proto_file.name}...")4647        cmd = [48            sys.executable,49            "-m",50            "grpc_tools.protoc",51            f"--proto_path={protos_dir}",52            # Include Google protobuf well-known types53            f"--proto_path={_get_protobuf_include_path()}",54            f"--python_out={output_dir}",55            f"--pyi_out={output_dir}",  # Generate type stubs56            str(proto_file),57        ]5859        try:60            result = subprocess.run(cmd, capture_output=True, text=True, check=False)6162            if result.returncode != 0:63                print(f"Error compiling {proto_file.name}:")64                print(result.stderr)65                return result.returncode6667            print(f"  Generated: {proto_file.stem}_pb2.py")68            print(f"  Generated: {proto_file.stem}_pb2.pyi")6970        except FileNotFoundError:71            print("Error: grpc_tools not found. Install with:")72            print('  uv pip install -e ".[proto]"')73            return 17475    print("\nProto compilation complete!")76    return 0777879def _get_protobuf_include_path() -> str:80    """Get the path to protobuf well-known types."""81    try:82        import grpc_tools.protoc8384        grpc_tools_path = Path(grpc_tools.protoc.__file__).parent85        # The _proto directory contains google/protobuf/*.proto86        proto_path = grpc_tools_path / "_proto"87        if proto_path.exists():88            return str(proto_path)89    except ImportError:90        pass9192    # Fallback: try to find in site-packages93    try:94        import google.protobuf9596        protobuf_path = Path(google.protobuf.__file__).parent.parent97        return str(protobuf_path)98    except ImportError:99        pass100101    # Last resort: return empty string and let protoc find it102    return ""103104105if __name__ == "__main__":106    sys.exit(main())107