Skip to content

Commit ce83729

Browse files
authored
chore(librarian): Add exception namespaces for googleapis-common-protos (#14598)
This PR fixes the following error when running `librarian generate --build` for a `proto-only` library such as `googleapis-common-protos` ``` Traceback (most recent call last): File "/app/./cli.py", line 977, in handle_build _verify_library_namespace(library_id, repo) File "/app/./cli.py", line 913, in _verify_library_namespace raise ValueError( ValueError: Error: namespace cannot be determined for googleapis-common-protos. Library is missing a `gapic_version.py`. The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/./cli.py", line 1404, in <module> args.func(librarian=args.librarian, repo=args.repo) File "/app/./cli.py", line 981, in handle_build raise ValueError("Build failed.") from e ValueError: Build failed. time=2025-09-30T09:00:03.583Z level=INFO ```
1 parent 24f11c9 commit ce83729

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

.generator/cli.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,8 @@ def _determine_library_namespace(
863863
def _verify_library_namespace(library_id: str, repo: str):
864864
"""
865865
Verifies that all found package namespaces are one of
866-
`google`, `google.cloud`, or `google.ads`.
866+
the hardcoded `exception_namespaces` or
867+
`valid_namespaces`.
867868
868869
Args:
869870
library_id (str): The library id under test (e.g., "google-cloud-language").
@@ -872,6 +873,7 @@ def _verify_library_namespace(library_id: str, repo: str):
872873
# TODO(https://github.com/googleapis/google-cloud-python/issues/14376): Update the list of namespaces which are exceptions.
873874
exception_namespaces = [
874875
"google.area120",
876+
"google.api",
875877
"google.apps.script",
876878
"google.apps.script.type",
877879
"google.cloud.alloydb",
@@ -883,14 +885,17 @@ def _verify_library_namespace(library_id: str, repo: str):
883885
"google.cloud.security",
884886
"google.cloud.video",
885887
"google.cloud.workflows",
888+
"google.gapic",
889+
"google.logging",
886890
"google.monitoring",
891+
"google.rpc",
887892
]
888893
valid_namespaces = [
889894
"google",
890-
"google.analytics",
891-
"google.apps",
892895
"google.ads",
893896
"google.ai",
897+
"google.analytics",
898+
"google.apps",
894899
"google.cloud",
895900
"google.geo",
896901
"google.maps",
@@ -899,28 +904,32 @@ def _verify_library_namespace(library_id: str, repo: str):
899904
*exception_namespaces,
900905
]
901906
gapic_version_file = "gapic_version.py"
907+
proto_file = "*.proto"
902908

903-
# This is now the "package root" path we will use for comparison
904909
library_path = Path(f"{repo}/packages/{library_id}")
905910

906911
if not library_path.is_dir():
907912
raise ValueError(f"Error: Path is not a directory: {library_path}")
908913

909-
# Recursively glob (rglob) for all 'gapic_version.py' files
910-
all_gapic_files = list(library_path.rglob(gapic_version_file))
914+
# Use a set to store unique parent directories of relevant directories
915+
relevant_dirs = set()
911916

912-
if not all_gapic_files:
917+
# Find all parent directories for 'gapic_version.py' files
918+
for gapic_file in library_path.rglob(gapic_version_file):
919+
relevant_dirs.add(gapic_file.parent)
920+
921+
# Find all parent directories for '*.proto' files
922+
for proto_file in library_path.rglob(proto_file):
923+
relevant_dirs.add(proto_file.parent)
924+
925+
if not relevant_dirs:
913926
raise ValueError(
914927
f"Error: namespace cannot be determined for {library_id}."
915-
f" Library is missing a `{gapic_version_file}`."
928+
f" Library is missing a `{gapic_version_file}` or `{proto_file}` file."
916929
)
917930

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)
931+
for relevant_dir in relevant_dirs:
932+
library_namespace = _determine_library_namespace(relevant_dir, library_path)
924933

925934
if library_namespace not in valid_namespaces:
926935
raise ValueError(

.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)