Skip to content

Commit 3395b04

Browse files
committed
chore(librarian): Add exception namespaces for googleapis-common-protos
1 parent 5853e97 commit 3395b04

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

.generator/cli.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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,40 @@ 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+
# 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+
# 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+
if not relevant_dirs:
913925
raise ValueError(
914926
f"Error: namespace cannot be determined for {library_id}."
915-
f" Library is missing a `{gapic_version_file}`."
927+
f" Library is missing a `{gapic_version_file}` or `{proto_file}` file."
916928
)
917929

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)
930+
# Iterate over the unique relevant directories and validate the namespace for each
931+
for relevant_dir in relevant_dirs:
932+
# Determine the library namespace based on the directory path
933+
library_namespace = _determine_library_namespace(relevant_dir, library_path)
924934

925935
if library_namespace not in valid_namespaces:
936+
# Sort the valid namespaces for a clean error message
937+
valid_list = sorted(list(valid_namespaces))
926938
raise ValueError(
927-
f"The namespace `{library_namespace}` for `{library_id}` must be one of {valid_namespaces}."
939+
f"The namespace `{library_namespace}` for `{library_id}` must be one of {valid_list}."
928940
)
929941

930942

.generator/test_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ def test_verify_library_namespace_failure_invalid(mocker, mock_path_class):
13211321
mock_instance.rglob.return_value = [mock_file]
13221322

13231323
mock_determine_ns = mocker.patch(
1324-
"cli._determine_library_namespace", return_value="google.api"
1324+
"cli._determine_library_namespace", return_value="google.apis"
13251325
)
13261326

13271327
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)