Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add default library settings #2120

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 11 additions & 1 deletion gapic/schema/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,14 +698,24 @@ def all_library_settings(
self.service_yaml_config.publishing.library_settings
)

return {
result = {
library_setting.version: client_pb2.ClientLibrarySettings(
version=library_setting.version,
python_settings=library_setting.python_settings,
)
for library_setting in self.service_yaml_config.publishing.library_settings
}

# Add default settings for the current proto package
if not result:
result = {
self.naming.proto_package: client_pb2.ClientLibrarySettings(
version=self.naming.proto_package
)
}

return result

def enforce_valid_library_settings(
self, client_library_settings: Sequence[client_pb2.ClientLibrarySettings]
) -> None:
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/schema/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2726,6 +2726,19 @@ def test_read_python_settings_from_service_yaml():
}


def test_read_empty_python_settings_from_service_yaml():
service_yaml_config = {
"apis": [
{"name": "google.example.v1beta1.ServiceOne.Example1"},
],
}
cli_options = Options(service_yaml_config=service_yaml_config)
fd = get_file_descriptor_proto_for_tests(fields=[])
api_schema = api.API.build(fd, "google.example.v1beta1", opts=cli_options)
assert api_schema.all_library_settings["google.example.v1beta1"].python_settings \
== client_pb2.PythonSettings()


def test_python_settings_duplicate_version_raises_error():
"""
Test that `ClientLibrarySettingsError` is raised when there are duplicate versions in
Expand Down