@@ -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" ,
@@ -375,11 +374,6 @@ def _clean_up_files_after_post_processing(output: str, library_id: str):
375374 ): # pragma: NO COVER
376375 os .remove (post_processing_file )
377376
378- for gapic_version_file in glob .glob (
379- f"{ output } /{ path_to_library } /**/gapic_version.py" , recursive = True
380- ): # pragma: NO COVER
381- os .remove (gapic_version_file )
382-
383377
384378def _determine_release_level (api_path : str ) -> str :
385379 # TODO(https://github.com/googleapis/librarian/issues/2352): Determine if
@@ -521,10 +515,11 @@ def handle_generate(
521515 request_data = _read_json_file (f"{ librarian } /{ GENERATE_REQUEST_FILE } " )
522516 library_id = _get_library_id (request_data )
523517 apis_to_generate = request_data .get ("apis" , [])
518+ version = request_data .get ("version" )
524519 for api in apis_to_generate :
525520 api_path = api .get ("path" )
526521 if api_path :
527- _generate_api (api_path , library_id , source , output )
522+ _generate_api (api_path , library_id , source , output , version )
528523 _copy_files_needed_for_post_processing (output , input , library_id )
529524 _generate_repo_metadata_file (output , library_id , source , apis_to_generate )
530525 _run_post_processor (output , library_id )
@@ -555,13 +550,17 @@ def _read_bazel_build_py_rule(api_path: str, source: str) -> Dict:
555550 return result [py_gapic_entries [0 ]]
556551
557552
558- def _get_api_generator_options (api_path : str , py_gapic_config : Dict ) -> List [str ]:
553+ def _get_api_generator_options (
554+ api_path : str , py_gapic_config : Dict , gapic_version : str
555+ ) -> List [str ]:
559556 """
560557 Extracts generator options from the parsed Python GAPIC rule configuration.
561558
562559 Args:
563560 api_path (str): The relative path to the API directory.
564561 py_gapic_config (Dict): The parsed attributes of the Python GAPIC rule.
562+ gapic_version(str): The desired version number for the GAPIC client library
563+ in a format which follows PEP-440.
565564
566565 Returns:
567566 List[str]: A list of formatted generator options (e.g., ['retry-config=...', 'transport=...']).
@@ -586,11 +585,12 @@ def _get_api_generator_options(api_path: str, py_gapic_config: Dict) -> List[str
586585 # Other options use the value directly
587586 generator_options .append (f"{ protoc_key } ={ config_value } " )
588587
588+ # The value of `opt_args` in the `py_gapic` bazel rule is already a list of strings.
589+ optional_arguments = py_gapic_config .get ("opt_args" , [])
590+ # Specify `gapic-version` using the version from `state.yaml`
591+ optional_arguments .extend ([f"gapic-version={ gapic_version } " ])
589592 # Add optional arguments
590- optional_arguments = py_gapic_config .get ("opt_args" , None )
591- if optional_arguments :
592- # opt_args in Bazel rule is already a list of strings
593- generator_options .extend (optional_arguments )
593+ generator_options .extend (optional_arguments )
594594
595595 return generator_options
596596
@@ -642,7 +642,9 @@ def _run_generator_command(generator_command: str, source: str):
642642 )
643643
644644
645- def _generate_api (api_path : str , library_id : str , source : str , output : str ):
645+ def _generate_api (
646+ api_path : str , library_id : str , source : str , output : str , gapic_version : str
647+ ):
646648 """
647649 Handles the generation and staging process for a single API path.
648650
@@ -651,9 +653,13 @@ def _generate_api(api_path: str, library_id: str, source: str, output: str):
651653 library_id (str): The ID of the library being generated.
652654 source (str): Path to the directory containing API protos.
653655 output (str): Path to the output directory where code should be staged.
656+ gapic_version(str): The desired version number for the GAPIC client library
657+ in a format which follows PEP-440.
654658 """
655659 py_gapic_config = _read_bazel_build_py_rule (api_path , source )
656- generator_options = _get_api_generator_options (api_path , py_gapic_config )
660+ generator_options = _get_api_generator_options (
661+ api_path , py_gapic_config , gapic_version = gapic_version
662+ )
657663
658664 with tempfile .TemporaryDirectory () as tmp_dir :
659665 generator_command = _determine_generator_command (
0 commit comments