Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 53 additions & 2 deletions .generator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
logger = logging.getLogger()

BUILD_REQUEST_FILE = "build-request.json"
CONFIGURE_REQUEST_FILE = "configure-request.json"
GENERATE_REQUEST_FILE = "generate-request.json"
RELEASE_INIT_REQUEST_FILE = "release-init-request.json"
STATE_YAML_FILE = "state.yaml"
Expand Down Expand Up @@ -115,8 +116,51 @@ def _write_json_file(path: str, updated_content: Dict):
f.write("\n")


def handle_configure():
# TODO(https://github.com/googleapis/librarian/issues/466): Implement configure command and update docstring.
def _get_library_version(library_id: str, repo: str) -> str:
"""Gets the library version from its gapic_version.py file."""
library_path = Path(f"{repo}/packages/{library_id}")
gapic_version_files = list(library_path.rglob("**/gapic_version.py"))
if not gapic_version_files:
raise ValueError(f"Could not find gapic_version.py for {library_id}")

content = _read_text_file(gapic_version_files[0])
match = re.search(r"__version__\s*=\s*[\"']([^\"']+)[\"']", content)
if not match:
raise ValueError(f"Could not extract version from {gapic_version_files[0]}")

return match.group(1)


def handle_configure(
librarian: str = LIBRARIAN_DIR,
source: str = SOURCE_DIR,
repo: str = REPO_DIR,
input: str = INPUT_DIR,
):
try:
library_config = _read_json_file(f"{librarian}/{CONFIGURE_REQUEST_FILE}")
library_id = _get_library_id(library_config)

library_config["version"] = _get_library_version(library_id, repo)
library_config["source_roots"] = [f"packages/{library_id}"]
library_config["preserve_regex"] = [
f"packages/{library_id}/CHANGELOG.md",
"docs/CHANGELOG.md",
"docs/README.rst",
"samples/README.txt",
"tar.gz",
"gapic_version.py",
"scripts/client-post-processing",
"samples/snippets/README.rst",
"tests/system",
]
library_config["remove_regex"] = [f"packages/{library_id}"]
library_config["tag_format"] = "{id}-v{version}"

_write_json_file(f"{librarian}/configure-response.json", library_config)

except Exception as e:
raise ValueError("Configuring a new library failed.") from e
logger.info("'configure' command executed.")


Expand Down Expand Up @@ -1004,6 +1048,13 @@ def handle_release_init(
output=args.output,
input=args.input,
)
elif args.command == "configure":
args.func(
librarian=args.librarian,
source=args.source,
repo=args.repo,
input=args.input,
)
elif args.command == "build":
args.func(librarian=args.librarian, repo=args.repo)
elif args.command == "release-init":
Expand Down
57 changes: 35 additions & 22 deletions .librarian/state.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
image: us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator:latest
image: python-librarian-generator:latest
libraries:
- id: google-cloud-dlp
version: 3.32.0
last_generated_commit: f8776fec04e336527ba7279d960105533a1c4e21
apis:
- path: google/privacy/dlp/v2
service_config: dlp_v2.yaml
source_roots:
- packages/google-cloud-dlp
preserve_regex:
- packages/google-cloud-dlp/CHANGELOG.md
- docs/CHANGELOG.md
- docs/README.rst
- samples/README.txt
- tar.gz
- gapic_version.py
- scripts/client-post-processing
- samples/snippets/README.rst
- tests/system
remove_regex:
- packages/google-cloud-dlp
tag_format: '{id}-v{version}'
- id: google-cloud-eventarc
version: 1.15.3
last_generated_commit: d300b151a973ce0425ae4ad07b3de957ca31bec6
apis:
- path: google/cloud/eventarc/v1
service_config: eventarc_v1.yaml
source_roots:
- packages/google-cloud-eventarc
preserve_regex:
Expand All @@ -46,6 +26,7 @@ libraries:
last_generated_commit: d300b151a973ce0425ae4ad07b3de957ca31bec6
apis:
- path: google/cloud/video/livestream/v1
service_config: livestream_v1.yaml
source_roots:
- packages/google-cloud-video-live-stream
preserve_regex:
Expand All @@ -66,6 +47,7 @@ libraries:
last_generated_commit: d300b151a973ce0425ae4ad07b3de957ca31bec6
apis:
- path: google/marketingplatform/admin/v1alpha
service_config: marketingplatformadmin_v1alpha.yaml
source_roots:
- packages/google-ads-marketingplatform-admin
preserve_regex:
Expand All @@ -86,10 +68,15 @@ libraries:
last_generated_commit: d300b151a973ce0425ae4ad07b3de957ca31bec6
apis:
- path: google/ai/generativelanguage/v1
service_config: generativelanguage_v1.yaml
- path: google/ai/generativelanguage/v1beta
service_config: generativelanguage_v1beta.yaml
- path: google/ai/generativelanguage/v1beta3
service_config: generativelanguage_v1beta3.yaml
- path: google/ai/generativelanguage/v1beta2
service_config: generativelanguage_v1beta2.yaml
- path: google/ai/generativelanguage/v1alpha
service_config: generativelanguage_v1alpha.yaml
source_roots:
- packages/google-ai-generativelanguage
preserve_regex:
Expand All @@ -110,7 +97,9 @@ libraries:
last_generated_commit: d300b151a973ce0425ae4ad07b3de957ca31bec6
apis:
- path: google/analytics/admin/v1beta
service_config: analyticsadmin_v1beta.yaml
- path: google/analytics/admin/v1alpha
service_config: analyticsadmin_v1alpha.yaml
source_roots:
- packages/google-analytics-admin
preserve_regex:
Expand All @@ -131,7 +120,9 @@ libraries:
last_generated_commit: d300b151a973ce0425ae4ad07b3de957ca31bec6
apis:
- path: google/analytics/data/v1alpha
service_config: analyticsdata_v1alpha.yaml
- path: google/analytics/data/v1beta
service_config: analyticsdata_v1beta.yaml
source_roots:
- packages/google-analytics-data
preserve_regex:
Expand All @@ -152,6 +143,7 @@ libraries:
last_generated_commit: d300b151a973ce0425ae4ad07b3de957ca31bec6
apis:
- path: google/ads/admanager/v1
service_config: admanager_v1.yaml
source_roots:
- packages/google-ads-admanager
preserve_regex:
Expand All @@ -167,3 +159,24 @@ libraries:
remove_regex:
- packages/google-ads-admanager
tag_format: '{id}-v{version}'
- id: google-cloud-dlp
version: 3.32.0
last_generated_commit: b7e013ac0b9896cf89de48706221ec22212d8d0e
apis:
- path: google/privacy/dlp/v2
service_config: dlp_v2.yaml
source_roots:
- packages/google-cloud-dlp
preserve_regex:
- packages/google-cloud-dlp/CHANGELOG.md
- docs/CHANGELOG.md
- docs/README.rst
- samples/README.txt
- tar.gz
- gapic_version.py
- scripts/client-post-processing
- samples/snippets/README.rst
- tests/system
remove_regex:
- packages/google-cloud-dlp
tag_format: '{id}-v{version}'