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
20 changes: 15 additions & 5 deletions .generator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ def _update_changelog_for_library(
version: str,
previous_version: str,
library_id: str,
relative_path: str,
is_mono_repo: bool,
):
"""Prepends a new release entry with multiple, grouped changes, to a changelog.

Expand All @@ -1361,7 +1361,15 @@ def _update_changelog_for_library(
previous_version(str): The version in state.yaml for a given library
library_id(str): The id of the library where the changelog should
be updated.
is_mono_repo(bool): True if the current repository is a mono-repo.
"""
if is_mono_repo:
relative_path = f"packages/{library_id}/CHANGELOG.md"
docs_relative_path = f"packages/{library_id}/docs/CHANGELOG.md"
else:
relative_path = "CHANGELOG.md"
docs_relative_path = f"docs/CHANGELOG.md"

changelog_src = f"{repo}/{relative_path}"
changelog_dest = f"{output}/{relative_path}"
updated_content = _process_changelog(
Expand All @@ -1373,6 +1381,11 @@ def _update_changelog_for_library(
)
_write_text_file(changelog_dest, updated_content)

docs_changelog_src = f"{repo}/{docs_relative_path}"
if os.path.lexists(docs_changelog_src):
docs_changelog_dst = f"{output}/{docs_relative_path}"
_write_text_file(docs_changelog_dst, updated_content)


def _is_mono_repo(repo: str) -> bool:
"""Determines if a library is generated or handwritten.
Expand Down Expand Up @@ -1424,7 +1437,6 @@ def handle_release_init(
)

if is_mono_repo:

# only a mono repo has a global changelog
_update_global_changelog(
f"{repo}/CHANGELOG.md",
Expand All @@ -1449,10 +1461,8 @@ def handle_release_init(

if is_mono_repo:
path_to_library = f"packages/{library_id}"
changelog_relative_path = f"packages/{library_id}/CHANGELOG.md"
else:
path_to_library = "."
changelog_relative_path = "CHANGELOG.md"

_update_version_for_library(repo, output, path_to_library, version)
_update_changelog_for_library(
Expand All @@ -1462,7 +1472,7 @@ def handle_release_init(
version,
previous_version,
library_id,
relative_path=changelog_relative_path,
is_mono_repo=is_mono_repo,
)

except Exception as e:
Expand Down
66 changes: 50 additions & 16 deletions .generator/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ def test_handle_configure_no_new_library(mocker):
with pytest.raises(ValueError, match="Configuring a new library failed."):
handle_configure()


def test_create_new_changelog_for_library(mocker):
"""Tests that the changelog files are created correctly."""
library_id = "google-cloud-language"
Expand All @@ -325,7 +326,9 @@ def test_create_new_changelog_for_library(mocker):
docs_changelog_path = f"{output}/packages/{library_id}/docs/CHANGELOG.md"

# Check that makedirs was called for both parent directories
mock_makedirs.assert_any_call(os.path.dirname(package_changelog_path), exist_ok=True)
mock_makedirs.assert_any_call(
os.path.dirname(package_changelog_path), exist_ok=True
)
mock_makedirs.assert_any_call(os.path.dirname(docs_changelog_path), exist_ok=True)
assert mock_makedirs.call_count == 2

Expand Down Expand Up @@ -1141,29 +1144,60 @@ def test_get_previous_version_failure(mock_state_file):
_get_previous_version("google-cloud-does-not-exist", LIBRARIAN_DIR)


def test_update_changelog_for_library_success(mocker):
m = mock_open()

def test_update_changelog_for_library_writes_both_changelogs(mocker):
"""Tests that _update_changelog_for_library writes to both changelogs."""
mock_content = """# Changelog

[PyPI History][1]

[1]: https://pypi.org/project/google-cloud-language/#history
"""
mock_read = mocker.patch("cli._read_text_file", return_value=mock_content)
mock_write = mocker.patch("cli._write_text_file")
mock_path_exists = mocker.patch("cli.os.path.lexists", return_value=True)
_update_changelog_for_library(
"repo",
"output",
_MOCK_LIBRARY_CHANGES,
"1.2.3",
"1.2.2",
"google-cloud-language",
is_mono_repo=True,
)

## [2.17.2](https://github.com/googleapis/google-cloud-python/compare/google-cloud-language-v2.17.1...google-cloud-language-v2.17.2) (2025-06-11)
assert mock_write.call_count == 2
mock_write.assert_any_call(
"output/packages/google-cloud-language/CHANGELOG.md", mocker.ANY
)
mock_write.assert_any_call(
"output/packages/google-cloud-language/docs/CHANGELOG.md", mocker.ANY
)


def test_update_changelog_for_library_single_repo(mocker):
"""Tests that _update_changelog_for_library writes to both changelogs in a single repo."""
mock_content = """# Changelog

[PyPI History][1]

[1]: https://pypi.org/project/google-cloud-language/#history
"""
with unittest.mock.patch("cli.open", m):
mocker.patch("cli._read_text_file", return_value=mock_content)
_update_changelog_for_library(
"repo",
"output",
_MOCK_LIBRARY_CHANGES,
"1.2.3",
"1.2.2",
"google-cloud-language",
"CHANGELOG.md",
)
mock_read = mocker.patch("cli._read_text_file", return_value=mock_content)
mock_write = mocker.patch("cli._write_text_file")
mock_path_exists = mocker.patch("cli.os.path.lexists", return_value=True)
_update_changelog_for_library(
"repo",
"output",
_MOCK_LIBRARY_CHANGES,
"1.2.3",
"1.2.2",
"google-cloud-language",
is_mono_repo=False,
)

assert mock_write.call_count == 2
mock_write.assert_any_call("output/CHANGELOG.md", mocker.ANY)
mock_write.assert_any_call("output/docs/CHANGELOG.md", mocker.ANY)


def test_process_changelog_success():
Expand Down
19 changes: 19 additions & 0 deletions .librarian/state.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2092,6 +2092,25 @@ libraries:
remove_regex:
- packages/google-cloud-gke-multicloud
tag_format: '{id}-v{version}'
- id: google-cloud-gkerecommender
version: 0.1.0
last_generated_commit: 94ccdfe4519e0ba817bd33aa22eb9c64f88a6874
apis:
- path: google/cloud/gkerecommender/v1
service_config: gkerecommender_v1.yaml
source_roots:
- packages/google-cloud-gkerecommender
preserve_regex:
- packages/google-cloud-gkerecommender/CHANGELOG.md
- docs/CHANGELOG.md
- docs/README.rst
- samples/README.txt
- scripts/client-post-processing
- samples/snippets/README.rst
- tests/system
remove_regex:
- packages/google-cloud-gkerecommender
tag_format: '{id}-v{version}'
- id: google-cloud-gsuiteaddons
version: 0.3.18
last_generated_commit: 3322511885371d2b2253f209ccc3aa60d4100cfd
Expand Down
13 changes: 13 additions & 0 deletions packages/google-cloud-gkerecommender/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[run]
branch = True

[report]
show_missing = True
omit =
google/cloud/gkerecommender/__init__.py
google/cloud/gkerecommender/gapic_version.py
exclude_lines =
# Re-enable the standard pragma
pragma: NO COVER
# Ignore debug-only repr
def __repr__
34 changes: 34 additions & 0 deletions packages/google-cloud-gkerecommender/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
[flake8]
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333):
# Resolve flake8 lint issues
ignore = E203, E231, E266, E501, W503
exclude =
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333):
# Ensure that generated code passes flake8 lint
**/gapic/**
**/services/**
**/types/**
# Exclude Protobuf gencode
*_pb2.py

# Standard linting exemptions.
**/.nox/**
__pycache__,
.git,
*.pyc,
conf.py
16 changes: 16 additions & 0 deletions packages/google-cloud-gkerecommender/.repo-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "google-cloud-gkerecommender",
"name_pretty": "GKE Recommender API",
"api_description": "GKE Recommender API",
"product_documentation": "https://cloud.google.com/kubernetes-engine/docs/how-to/machine-learning/inference-quickstart",
"client_documentation": "https://cloud.google.com/python/docs/reference/google-cloud-gkerecommender/latest",
"issue_tracker": "https://issuetracker.google.com/issues/new?component=1790908",
"release_level": "preview",
"language": "python",
"library_type": "GAPIC_AUTO",
"repo": "googleapis/google-cloud-python",
"distribution_name": "google-cloud-gkerecommender",
"api_id": "gkerecommender.googleapis.com",
"default_version": "v1",
"api_shortname": "gkerecommender"
}
12 changes: 12 additions & 0 deletions packages/google-cloud-gkerecommender/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog

[PyPI History][1]

[1]: https://pypi.org/project/google-cloud-gkerecommender/#history

## [0.1.0](https://github.com/googleapis/google-cloud-python/compare/google-cloud-gkerecommender-v0.0.0...google-cloud-gkerecommender-v0.1.0) (2025-10-21)


### Features

* generate libraries ([05936fa0577e9b8fe556728b6f4719d4bcefb9a2](https://github.com/googleapis/google-cloud-python/commit/05936fa0577e9b8fe556728b6f4719d4bcefb9a2))
Loading
Loading