Skip to content

Commit e9f8471

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

File tree

3 files changed

+123
-0
lines changed

3 files changed

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