Skip to content

Commit bf20f1c

Browse files
authored
chore(librarian): update configure_state_yaml.py to avoid duplicate entries (#14452)
This PR resolves the issue where duplicate values for `id` could be added to `state.yaml`. When duplicate entries exist in `state.yaml` librarian seems to provide an empty `generate-request.json` which leads to the following error (see googleapis/librarian#2186): ``` Traceback (most recent call last): File "/app/./cli.py", line 261, in handle_generate request_data = _read_json_file(f"{librarian}/{GENERATE_REQUEST_FILE}") File "/app/./cli.py", line 100, in _read_json_file return json.load(f) File "/usr/local/lib/python3.9/json/__init__.py", line 293, in load return loads(fp.read(), File "/usr/local/lib/python3.9/json/__init__.py", line 346, in loads return _default_decoder.decode(s) File "/usr/local/lib/python3.9/json/decoder.py", line 340, in decode raise JSONDecodeError("Extra data", s, end) json.decoder.JSONDecodeError: Extra data: line 31 column 2 (char 755) ``` See output below for `google-cloud-dlp` and `google-cloud-eventarc` which already exist in `.librarian/state.yaml` ``` partheniou@partheniou-vm-3:~/git/google-cloud-python/scripts/configure_state_yaml$ python3 configure_state_yaml.py Skipping package 'google-cloud-dlp' as it already exists in state.yaml. Skipping package 'google-cloud-eventarc' as it already exists in state.yaml. ```
1 parent c9e1b8d commit bf20f1c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

scripts/configure_state_yaml/configure_state_yaml.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ def configure_state_yaml() -> None:
4848
with open(LIBRARIAN_YAML, "r") as state_yaml_file:
4949
state_dict = yaml.safe_load(state_yaml_file)
5050

51+
existing_library_ids = {library["id"] for library in state_dict.get("libraries", [])}
52+
5153
for package_name in packages_to_onboard["packages_to_onboard"]:
54+
# Check for duplication
55+
if package_name in existing_library_ids:
56+
print(f"Skipping package '{package_name}' as it already exists in state.yaml.")
57+
continue
58+
5259
package_path = Path(PACKAGES_DIR / package_name).resolve()
5360
api_paths = []
5461
for individual_metadata_file in package_path.rglob(f"**/{GAPIC_METADATA_JSON}"):

0 commit comments

Comments
 (0)