@@ -141,7 +141,6 @@ def _add_new_library_preserve_regex(library_config: Dict, library_id: str) -> No
141141 "docs/README.rst" ,
142142 "samples/README.txt" ,
143143 "tar.gz" ,
144- "gapic_version.py" ,
145144 "scripts/client-post-processing" ,
146145 "samples/snippets/README.rst" ,
147146 "tests/system" ,
@@ -377,11 +376,6 @@ def _clean_up_files_after_post_processing(output: str, library_id: str):
377376 ): # pragma: NO COVER
378377 os .remove (post_processing_file )
379378
380- for gapic_version_file in glob .glob (
381- f"{ output } /{ path_to_library } /**/gapic_version.py" , recursive = True
382- ): # pragma: NO COVER
383- os .remove (gapic_version_file )
384-
385379
386380def _create_repo_metadata_from_service_config (
387381 service_config_name : str , api_path : str , source : str , library_id : str
@@ -488,10 +482,11 @@ def handle_generate(
488482 request_data = _read_json_file (f"{ librarian } /{ GENERATE_REQUEST_FILE } " )
489483 library_id = _get_library_id (request_data )
490484 apis_to_generate = request_data .get ("apis" , [])
485+ version = request_data .get ("version" )
491486 for api in apis_to_generate :
492487 api_path = api .get ("path" )
493488 if api_path :
494- _generate_api (api_path , library_id , source , output )
489+ _generate_api (api_path , library_id , source , output , version )
495490 _copy_files_needed_for_post_processing (output , input , library_id )
496491 _generate_repo_metadata_file (output , library_id , source , apis_to_generate )
497492 _run_post_processor (output , library_id )
@@ -522,13 +517,17 @@ def _read_bazel_build_py_rule(api_path: str, source: str) -> Dict:
522517 return result [py_gapic_entries [0 ]]
523518
524519
525- def _get_api_generator_options (api_path : str , py_gapic_config : Dict ) -> List [str ]:
520+ def _get_api_generator_options (
521+ api_path : str , py_gapic_config : Dict , gapic_version : str
522+ ) -> List [str ]:
526523 """
527524 Extracts generator options from the parsed Python GAPIC rule configuration.
528525
529526 Args:
530527 api_path (str): The relative path to the API directory.
531528 py_gapic_config (Dict): The parsed attributes of the Python GAPIC rule.
529+ gapic_version(str): The desired version number for the GAPIC client library
530+ in a format which follows PEP-440.
532531
533532 Returns:
534533 List[str]: A list of formatted generator options (e.g., ['retry-config=...', 'transport=...']).
@@ -553,11 +552,12 @@ def _get_api_generator_options(api_path: str, py_gapic_config: Dict) -> List[str
553552 # Other options use the value directly
554553 generator_options .append (f"{ protoc_key } ={ config_value } " )
555554
555+ # The value of `opt_args` in the `py_gapic` bazel rule is already a list of strings.
556+ optional_arguments = py_gapic_config .get ("opt_args" , [])
557+ # Specify `gapic-version` using the version from `state.yaml`
558+ optional_arguments .extend ([f"gapic-version={ gapic_version } " ])
556559 # Add optional arguments
557- optional_arguments = py_gapic_config .get ("opt_args" , None )
558- if optional_arguments :
559- # opt_args in Bazel rule is already a list of strings
560- generator_options .extend (optional_arguments )
560+ generator_options .extend (optional_arguments )
561561
562562 return generator_options
563563
@@ -609,7 +609,9 @@ def _run_generator_command(generator_command: str, source: str):
609609 )
610610
611611
612- def _generate_api (api_path : str , library_id : str , source : str , output : str ):
612+ def _generate_api (
613+ api_path : str , library_id : str , source : str , output : str , gapic_version : str
614+ ):
613615 """
614616 Handles the generation and staging process for a single API path.
615617
@@ -618,9 +620,13 @@ def _generate_api(api_path: str, library_id: str, source: str, output: str):
618620 library_id (str): The ID of the library being generated.
619621 source (str): Path to the directory containing API protos.
620622 output (str): Path to the output directory where code should be staged.
623+ gapic_version(str): The desired version number for the GAPIC client library
624+ in a format which follows PEP-440.
621625 """
622626 py_gapic_config = _read_bazel_build_py_rule (api_path , source )
623- generator_options = _get_api_generator_options (api_path , py_gapic_config )
627+ generator_options = _get_api_generator_options (
628+ api_path , py_gapic_config , gapic_version = gapic_version
629+ )
624630
625631 with tempfile .TemporaryDirectory () as tmp_dir :
626632 generator_command = _determine_generator_command (
0 commit comments