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 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
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
17 changes: 17 additions & 0 deletions tests/unit/schema/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2726,6 +2726,23 @@ 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()
assert api_schema.all_library_settings["google.example.v1beta1"].python_settings.experimental_features \
== client_pb2.PythonSettings.ExperimentalFeatures()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you link me to this property in client_pb2 file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert api_schema.all_library_settings["google.example.v1beta1"].python_settings.experimental_features.rest_async_io_enabled \
== False


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