1717import logging
1818import os
1919import sys
20+ import subprocess
2021
2122logger = logging .getLogger ()
2223
@@ -37,14 +38,40 @@ def handle_configure(dry_run=False):
3738
3839def handle_generate (dry_run = False ):
3940
40- # Read a generate-request.json file
4141 if not dry_run :
42+
43+ # Read generate-request.json file
4244 try :
4345 request_data = _read_json_file (f"{ LIBRARIAN_DIR } /{ GENERATE_REQUEST_FILE } " )
4446 except Exception as e :
4547 logger .error (f"failed to read { LIBRARIAN_DIR } /{ GENERATE_REQUEST_FILE } : { e } " )
4648 sys .exit (1 )
4749
50+ library_id = request_data .get ("id" )
51+ if not library_id :
52+ logger .error ("Request file is missing required 'id' field." )
53+ sys .exit (1 )
54+
55+ for api in request_data .get ("apis" , []):
56+ api_path = api .get ("path" )
57+ if api_path :
58+ try :
59+ query = f'filter("-py$", kind("rule", //{ api_path } /...:*))'
60+ command = ["bazelisk" , "query" , query ]
61+ result = subprocess .run (
62+ command , capture_output = True , text = True , check = True
63+ )
64+
65+ bazel_rule = result .stdout .strip ()
66+ if not bazel_rule :
67+ logger .error ("Bazel query returned an empty result." )
68+ sys .exit (1 )
69+
70+ logger .info (f"Found Bazel rule: { bazel_rule } " )
71+ except Exception as e :
72+ logger .error (f"Bazelisk query failed: { e } " )
73+ sys .exit (1 )
74+
4875 logger .info (json .dumps (request_data , indent = 2 ))
4976
5077 # TODO(https://github.com/googleapis/librarian/issues/448): Implement generate command.
0 commit comments