@@ -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" ,
@@ -188,9 +187,7 @@ def _get_new_library_config(request_data: Dict) -> Dict:
188187 return {}
189188
190189
191- def _add_new_library_version (
192- library_config : Dict
193- ) -> None :
190+ def _add_new_library_version (library_config : Dict ) -> None :
194191 """Adds the library version to the configuration if it's not present.
195192
196193 Args:
@@ -377,11 +374,6 @@ def _clean_up_files_after_post_processing(output: str, library_id: str):
377374 ): # pragma: NO COVER
378375 os .remove (post_processing_file )
379376
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-
385377
386378def _create_repo_metadata_from_service_config (
387379 service_config_name : str , api_path : str , source : str , library_id : str
@@ -488,10 +480,11 @@ def handle_generate(
488480 request_data = _read_json_file (f"{ librarian } /{ GENERATE_REQUEST_FILE } " )
489481 library_id = _get_library_id (request_data )
490482 apis_to_generate = request_data .get ("apis" , [])
483+ version = request_data .get ("version" )
491484 for api in apis_to_generate :
492485 api_path = api .get ("path" )
493486 if api_path :
494- _generate_api (api_path , library_id , source , output )
487+ _generate_api (api_path , library_id , source , output , version )
495488 _copy_files_needed_for_post_processing (output , input , library_id )
496489 _generate_repo_metadata_file (output , library_id , source , apis_to_generate )
497490 _run_post_processor (output , library_id )
@@ -522,13 +515,17 @@ def _read_bazel_build_py_rule(api_path: str, source: str) -> Dict:
522515 return result [py_gapic_entries [0 ]]
523516
524517
525- def _get_api_generator_options (api_path : str , py_gapic_config : Dict ) -> List [str ]:
518+ def _get_api_generator_options (
519+ api_path : str , py_gapic_config : Dict , gapic_version : str
520+ ) -> List [str ]:
526521 """
527522 Extracts generator options from the parsed Python GAPIC rule configuration.
528523
529524 Args:
530525 api_path (str): The relative path to the API directory.
531526 py_gapic_config (Dict): The parsed attributes of the Python GAPIC rule.
527+ gapic_version(str): The desired version number for the GAPIC client library
528+ in a format which follows PEP-440.
532529
533530 Returns:
534531 List[str]: A list of formatted generator options (e.g., ['retry-config=...', 'transport=...']).
@@ -553,11 +550,12 @@ def _get_api_generator_options(api_path: str, py_gapic_config: Dict) -> List[str
553550 # Other options use the value directly
554551 generator_options .append (f"{ protoc_key } ={ config_value } " )
555552
553+ # The value of `opt_args` in the `py_gapic` bazel rule is already a list of strings.
554+ optional_arguments = py_gapic_config .get ("opt_args" , [])
555+ # Specify `gapic-version` using the version from `state.yaml`
556+ optional_arguments .extend ([f"gapic-version={ gapic_version } " ])
556557 # 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 )
558+ generator_options .extend (optional_arguments )
561559
562560 return generator_options
563561
@@ -609,7 +607,9 @@ def _run_generator_command(generator_command: str, source: str):
609607 )
610608
611609
612- def _generate_api (api_path : str , library_id : str , source : str , output : str ):
610+ def _generate_api (
611+ api_path : str , library_id : str , source : str , output : str , gapic_version : str
612+ ):
613613 """
614614 Handles the generation and staging process for a single API path.
615615
@@ -618,9 +618,13 @@ def _generate_api(api_path: str, library_id: str, source: str, output: str):
618618 library_id (str): The ID of the library being generated.
619619 source (str): Path to the directory containing API protos.
620620 output (str): Path to the output directory where code should be staged.
621+ gapic_version(str): The desired version number for the GAPIC client library
622+ in a format which follows PEP-440.
621623 """
622624 py_gapic_config = _read_bazel_build_py_rule (api_path , source )
623- generator_options = _get_api_generator_options (api_path , py_gapic_config )
625+ generator_options = _get_api_generator_options (
626+ api_path , py_gapic_config , gapic_version = gapic_version
627+ )
624628
625629 with tempfile .TemporaryDirectory () as tmp_dir :
626630 generator_command = _determine_generator_command (
0 commit comments