@@ -872,6 +872,7 @@ def _verify_library_namespace(library_id: str, repo: str):
872872 # TODO(https://github.com/googleapis/google-cloud-python/issues/14376): Update the list of namespaces which are exceptions.
873873 exception_namespaces = [
874874 "google.area120" ,
875+ "google.api" ,
875876 "google.apps.script" ,
876877 "google.apps.script.type" ,
877878 "google.cloud.alloydb" ,
@@ -883,7 +884,10 @@ def _verify_library_namespace(library_id: str, repo: str):
883884 "google.cloud.security" ,
884885 "google.cloud.video" ,
885886 "google.cloud.workflows" ,
887+ "google.gapic" ,
888+ "google.logging" ,
886889 "google.monitoring" ,
890+ "google.rpc" ,
887891 ]
888892 valid_namespaces = [
889893 "google" ,
@@ -899,32 +903,42 @@ def _verify_library_namespace(library_id: str, repo: str):
899903 * exception_namespaces ,
900904 ]
901905 gapic_version_file = "gapic_version.py"
906+ proto_file = "*.proto"
902907
903- # This is now the "package root" path we will use for comparison
904908 library_path = Path (f"{ repo } /packages/{ library_id } " )
905909
906910 if not library_path .is_dir ():
907911 raise ValueError (f"Error: Path is not a directory: { library_path } " )
908912
909- # Recursively glob (rglob) for all 'gapic_version.py' files
910- all_gapic_files = list ( library_path . rglob ( gapic_version_file ) )
913+ # Use a set to store unique parent directories of relevant files
914+ relevant_dirs = set ( )
911915
912- if not all_gapic_files :
916+ # 1. Find all parent directories for 'gapic_version.py' files
917+ for gapic_file in library_path .rglob (gapic_version_file ):
918+ relevant_dirs .add (gapic_file .parent )
919+
920+ # 2. Find all parent directories for '*.proto' files
921+ for proto_file in library_path .rglob (proto_file ):
922+ relevant_dirs .add (proto_file .parent )
923+
924+ # --- Validation ---
925+
926+ if not relevant_dirs :
913927 raise ValueError (
914928 f"Error: namespace cannot be determined for { library_id } ."
915- f" Library is missing a `{ gapic_version_file } `."
929+ f" Library is missing a `{ gapic_version_file } ` or ` { proto_file } ` file ."
916930 )
917931
918- for gapic_file in all_gapic_files :
919- # The directory we want is the parent of `gapic_version.py` file.
920- gapic_parent_dir = gapic_file .parent
921-
922- # Pass both the specific dir and the package root for a safe relative comparison
923- library_namespace = _determine_library_namespace (gapic_parent_dir , library_path )
932+ # Iterate over the unique relevant directories and validate the namespace for each
933+ for relevant_dir in relevant_dirs :
934+ # Determine the library namespace based on the directory path
935+ library_namespace = _determine_library_namespace (relevant_dir , library_path )
924936
925937 if library_namespace not in valid_namespaces :
938+ # Sort the valid namespaces for a clean error message
939+ valid_list = sorted (list (valid_namespaces ))
926940 raise ValueError (
927- f"The namespace `{ library_namespace } ` for `{ library_id } ` must be one of { valid_namespaces } ."
941+ f"The namespace `{ library_namespace } ` for `{ library_id } ` must be one of { valid_list } ."
928942 )
929943
930944
0 commit comments