Skip to content

Commit a2be801

Browse files
committed
chore: add librarian state.yaml
1 parent cde9590 commit a2be801

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed

.librarian/state.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
image: gapic-generator-python:latest
2+
libraries:
3+
- apis:
4+
- path: google/cloud/language/v1beta2
5+
service_config: ''
6+
- path: google/cloud/language/v2
7+
service_config: ''
8+
- path: google/cloud/language/v1
9+
service_config: ''
10+
id: google-cloud-language
11+
last_generated_commit: 97a83d76a09a7f6dcab43675c87bdfeb5bcf1cb5
12+
preserve_regex: ''
13+
remove_regex: ''
14+
sourcePaths:
15+
- packages/google-cloud-language
16+
version: 2.17.2
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2025 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
import json
18+
from pathlib import Path
19+
from typing import List
20+
import yaml
21+
22+
SCRIPT_DIR = Path(__file__).resolve().parent
23+
ROOT_DIR = Path(SCRIPT_DIR / ".." / "..").resolve()
24+
PACKAGES_DIR = ROOT_DIR / "packages"
25+
PACKAGES_TO_ONBOARD_YAML = SCRIPT_DIR / "packages_to_onboard.yaml"
26+
LIBRARIAN_DIR = ROOT_DIR / ".librarian"
27+
LIBRARIAN_YAML = LIBRARIAN_DIR / "state.yaml"
28+
RELEASE_PLEASE_MANIFEST_JSON = ROOT_DIR / ".release-please-manifest.json"
29+
GAPIC_METADATA_JSON = "gapic_metadata.json"
30+
31+
32+
def configure_state_yaml(package_dirs: List[Path]) -> None:
33+
"""
34+
This method updates the `state.yaml` file in the directory
35+
`.librarian`.
36+
37+
Args:
38+
package_dirs(List[pathlib.Path]): A list of Paths, one for each package in the
39+
`packages/` folder whose entry will be updated in the `state.yaml`.
40+
41+
Returns:
42+
None
43+
"""
44+
45+
state_dict = {}
46+
47+
release_please_manifest = {}
48+
with open(RELEASE_PLEASE_MANIFEST_JSON, "r") as release_please_manifest_json_file:
49+
release_please_manifest = json.load(release_please_manifest_json_file)
50+
51+
packages_to_onboard = {}
52+
with open(PACKAGES_TO_ONBOARD_YAML, "r") as packages_to_onboard_yaml_file:
53+
packages_to_onboard = yaml.safe_load(packages_to_onboard_yaml_file)
54+
55+
state_dict["image"] = "gapic-generator-python:latest"
56+
state_dict["libraries"] = []
57+
for package_dir in package_dirs:
58+
if package_dir.name not in packages_to_onboard["packages_to_onboard"]:
59+
continue
60+
api_paths = []
61+
for individual_metadata_file in package_dir.rglob(f"**/{GAPIC_METADATA_JSON}"):
62+
with open(individual_metadata_file, "r") as gapic_metadata_json_file:
63+
gapic_metadata = json.load(gapic_metadata_json_file)
64+
api_paths.extend(
65+
[
66+
{
67+
"path": gapic_metadata["protoPackage"].replace(".", "/"),
68+
"service_config": "",
69+
}
70+
]
71+
)
72+
state_dict["libraries"].append(
73+
{
74+
"id": package_dir.name,
75+
"version": release_please_manifest[f"packages/{package_dir.name}"],
76+
"last_generated_commit": "97a83d76a09a7f6dcab43675c87bdfeb5bcf1cb5",
77+
"apis": api_paths,
78+
"sourcePaths": [f"packages/{package_dir.name}"],
79+
"preserve_regex": "",
80+
"remove_regex": "",
81+
}
82+
)
83+
84+
with open(LIBRARIAN_YAML, "w") as f:
85+
yaml.dump(state_dict, f)
86+
87+
88+
def get_all_packages(packages_dir: Path = PACKAGES_DIR) -> List[Path]:
89+
"""
90+
Walks through all API packages in the specified `packages_dir` path.
91+
92+
Args:
93+
packages_dir(pathlib.Path): Path to the directory which contains packages.
94+
95+
Returns:
96+
List[pathlib.Path] where each entry corresponds to a package within the
97+
specified `packages_dir`.
98+
"""
99+
if not Path(packages_dir).exists():
100+
raise FileNotFoundError(f"Directory {packages_dir} not found")
101+
return [obj.parents[0].resolve() for obj in packages_dir.rglob("**/.OwlBot.yaml")]
102+
103+
104+
if __name__ == "__main__":
105+
package_dirs = get_all_packages()
106+
configure_state_yaml(package_dirs)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
packages_to_onboard: [
2+
"google-cloud-language"
3+
]

0 commit comments

Comments
 (0)