1212# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313# See the License for the specific language governing permissions and
1414# limitations under the License.
15- import shutil
1615import copy
16+ import re
17+ import shutil
1718from pathlib import Path
1819from typing import Optional
1920import library_generation .utils .utilities as util
2021from common .model .generation_config import GenerationConfig
2122from common .model .library_config import LibraryConfig
23+ from common .utils .proto_path_utils import ends_with_version
2224from library_generation .generate_composed_library import generate_composed_library
2325from library_generation .utils .monorepo_postprocessor import monorepo_postprocessing
2426
@@ -125,7 +127,8 @@ def _get_target_libraries_from_api_path(
125127) -> list [LibraryConfig ]:
126128 """
127129 Retrieves a copy of the LibraryConfig objects that contain the specified
128- target API path, removed other proto_path from LibraryConfig if any.
130+ target API path, removed other proto_path versions from LibraryConfig if any.
131+ proto_path that is dependency, not another version is kept.
129132
130133 :param config: The GenerationConfig object.
131134 :param target_api_path: The target proto path to search for.
@@ -136,11 +139,15 @@ def _get_target_libraries_from_api_path(
136139 """
137140 target_libraries = []
138141 for library in config .libraries :
142+ target_library = copy .deepcopy (library )
143+ gapic_config_list = []
139144 for item in library .gapic_configs :
140- if item .proto_path == target_api_path :
141- target_library = copy .deepcopy (library )
142- target_library .set_gapic_configs ([GapicConfig (target_api_path )])
143- target_libraries .append (target_library )
144- return target_libraries
145-
145+ if item .proto_path == target_api_path or not ends_with_version (
146+ item .proto_path
147+ ):
148+ gapic_config_list .append (GapicConfig (item .proto_path ))
149+ if gapic_config_list :
150+ target_library .set_gapic_configs (gapic_config_list )
151+ target_libraries .append (target_library )
152+ return target_libraries
146153 return []
0 commit comments