Skip to content

Commit 75a3146

Browse files
committed
additional fixes
1 parent 2e26bc6 commit 75a3146

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

.generator/cli.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ def _copy_files_needed_for_post_processing(output: str, input: str, library_id:
330330
os.makedirs(
331331
f"{output}/{path_to_library}/scripts/client-post-processing", exist_ok=True
332332
)
333+
# TODO(https://github.com/googleapis/synthtool/pull/2126): Remove once this PR is merged
333334
# This is needed to avoid the following error for proto-only libraries
334335
# Traceback (most recent call last):
335336
# File "/app/./cli.py", line 535, in handle_generate
@@ -691,7 +692,7 @@ def _run_protoc_command(generator_command: str, source: str):
691692
)
692693

693694

694-
def _get_staging_child_directory(api_path: str) -> str:
695+
def _get_staging_child_directory(api_path: str, is_proto_only_library: bool) -> str:
695696
"""
696697
Determines the correct sub-path within 'owl-bot-staging' for the generated code.
697698
@@ -701,13 +702,14 @@ def _get_staging_child_directory(api_path: str) -> str:
701702
702703
Args:
703704
api_path (str): The relative path to the API directory (e.g., 'google/cloud/language/v1').
705+
is_proto_only_library(bool): True, if this is a proto-only library.
704706
705707
Returns:
706708
str: The sub-directory name to use for staging.
707709
"""
708710

709711
version_candidate = api_path.split("/")[-1]
710-
if version_candidate.startswith("v"):
712+
if version_candidate.startswith("v") and not is_proto_only_library:
711713
return version_candidate
712714
else:
713715
# Fallback for non-'v' version segment
@@ -790,7 +792,7 @@ def _generate_api(
790792
_run_protoc_command(command, source)
791793

792794
# 3. Determine staging location
793-
staging_child_directory = _get_staging_child_directory(api_path)
795+
staging_child_directory = _get_staging_child_directory(api_path, is_proto_only_library)
794796
staging_dir = os.path.join(
795797
output, "owl-bot-staging", library_id, staging_child_directory
796798
)

.generator/test_cli.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,18 +1365,22 @@ def test_get_staging_child_directory_gapic():
13651365
# Standard v1
13661366
api_path = "google/cloud/language/v1"
13671367
expected = "v1"
1368-
assert _get_staging_child_directory(api_path) == expected
1368+
assert _get_staging_child_directory(api_path, False) == expected
13691369

13701370

13711371
def test_get_staging_child_directory_proto_only():
13721372
"""
1373-
Tests the behavior for GAPIC clients when the last path segment
1374-
does not start with 'v' (should use the proto-only fallback structure).
1373+
Tests the behavior for proto-only clients.
13751374
"""
13761375
# A non-versioned path segment
13771376
api_path = "google/protobuf"
13781377
expected = "protobuf-py/google/protobuf"
1379-
assert _get_staging_child_directory(api_path) == expected
1378+
assert _get_staging_child_directory(api_path, True) == expected
1379+
1380+
# A non-versioned path segment
1381+
api_path = "google/protobuf/v1"
1382+
expected = "v1-py/google/protobuf/v1"
1383+
assert _get_staging_child_directory(api_path, True) == expected
13801384

13811385

13821386
def test_stage_proto_only_library(mocker):

0 commit comments

Comments
 (0)