-
Notifications
You must be signed in to change notification settings - Fork 55
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
feat: generate proto-only repository #2720
Changes from 57 commits
53e0a2b
7541b67
4f5118c
6629f2f
b8be0b2
7f48e08
0026eed
78dd8d7
788e30c
971867e
f3a6fbd
ddce346
8c21004
7da4e21
abcc81b
9a65467
e19c0ff
edc09e2
4321f11
a4f945f
8b3563b
396ea8e
905ce01
ed8e811
afa2f2f
a4a6f4a
a7c3768
49f4b11
fb2d417
2830340
f5a2d5b
b3e5955
6bba76b
1497d1b
1a34c4f
b0982b5
c808c62
ea50d89
71690cd
e7b0232
5a4e495
4b1e5c8
08ddac8
599a45b
6c7fa80
ff451ff
59b5657
d4d9082
bd7859f
c18090f
b46723d
685905a
7748828
a25e604
958ef5a
efa3efa
c76524d
c4731d1
7385de4
534ae9c
1751738
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ | |
"SECURITY.md", | ||
"java.header", | ||
"license-checks.xml", | ||
"README.md", | ||
"renovate.json", | ||
".gitignore" | ||
]) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,18 +48,17 @@ def generate_from_yaml( | |
|
||
for library_path, library in repo_config.libraries.items(): | ||
print(f"generating library {library.get_library_name()}") | ||
|
||
generate_composed_library( | ||
config_path=config_path, | ||
config=config, | ||
library_path=library_path, | ||
library=library, | ||
output_folder=repo_config.output_folder, | ||
versions_file=repo_config.versions_file, | ||
gapic_repo=not config.contains_common_protos(), | ||
) | ||
|
||
# we skip monorepo_postprocessing if not in a monorepo | ||
if not config.is_monorepo(): | ||
if not config.is_monorepo() or config.contains_common_protos(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only perform monorepo post processing if this is a gapic monorepo. |
||
return | ||
|
||
monorepo_postprocessing( | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -20,6 +20,7 @@ | |||||
REPO_LEVEL_PARAMETER = "Repo level parameter" | ||||||
LIBRARY_LEVEL_PARAMETER = "Library level parameter" | ||||||
GAPIC_LEVEL_PARAMETER = "GAPIC level parameter" | ||||||
COMMON_PROTOS = "common-protos" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||
|
||||||
|
||||||
class GenerationConfig: | ||||||
|
@@ -31,9 +32,9 @@ def __init__( | |||||
self, | ||||||
gapic_generator_version: str, | ||||||
googleapis_commitish: str, | ||||||
libraries_bom_version: str, | ||||||
template_excludes: list[str], | ||||||
libraries: list[LibraryConfig], | ||||||
libraries_bom_version: Optional[str] = None, | ||||||
grpc_version: Optional[str] = None, | ||||||
protoc_version: Optional[str] = None, | ||||||
): | ||||||
|
@@ -44,6 +45,9 @@ def __init__( | |||||
self.libraries = libraries | ||||||
self.grpc_version = grpc_version | ||||||
self.protoc_version = protoc_version | ||||||
# explicit set to None so that we can compute the | ||||||
# value in getter. | ||||||
self.__contains_common_protos = None | ||||||
self.__validate() | ||||||
|
||||||
def get_proto_path_to_library_name(self) -> dict[str, str]: | ||||||
|
@@ -61,6 +65,15 @@ def get_proto_path_to_library_name(self) -> dict[str, str]: | |||||
def is_monorepo(self) -> bool: | ||||||
return len(self.libraries) > 1 | ||||||
|
||||||
def contains_common_protos(self) -> bool: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this method to determine whether there are common protos in the configuration. We can't just have one
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have one method to set the value and one to compute, plus we store a variable in the config object. Maybe we can put the logic of the setter in the getter method and compute the value once in the field we create in the constructor. That would leave us with one less method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed the setter method. |
||||||
if self.__contains_common_protos is None: | ||||||
self.__contains_common_protos = False | ||||||
for library in self.libraries: | ||||||
if library.get_library_name() == COMMON_PROTOS: | ||||||
self.__contains_common_protos = True | ||||||
break | ||||||
return self.__contains_common_protos | ||||||
|
||||||
def __validate(self) -> None: | ||||||
seen_library_names = dict() | ||||||
for library in self.libraries: | ||||||
|
@@ -133,15 +146,13 @@ def from_yaml(path_to_yaml: str) -> GenerationConfig: | |||||
gapic_generator_version=__required( | ||||||
config, "gapic_generator_version", REPO_LEVEL_PARAMETER | ||||||
), | ||||||
grpc_version=__optional(config, "grpc_version", None), | ||||||
protoc_version=__optional(config, "protoc_version", None), | ||||||
googleapis_commitish=__required( | ||||||
config, "googleapis_commitish", REPO_LEVEL_PARAMETER | ||||||
), | ||||||
libraries_bom_version=__required( | ||||||
config, "libraries_bom_version", REPO_LEVEL_PARAMETER | ||||||
), | ||||||
template_excludes=__required(config, "template_excludes", REPO_LEVEL_PARAMETER), | ||||||
grpc_version=__optional(config, "grpc_version", None), | ||||||
protoc_version=__optional(config, "protoc_version", None), | ||||||
libraries_bom_version=__optional(config, "libraries_bom_version", None), | ||||||
libraries=parsed_libraries, | ||||||
) | ||||||
|
||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for backfilling this test! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import os | ||
import unittest | ||
from pathlib import Path | ||
|
||
from parameterized import parameterized | ||
from library_generation.model.gapic_inputs import parse | ||
|
||
script_dir = os.path.dirname(os.path.realpath(__file__)) | ||
resources_dir = os.path.join(script_dir, "..", "resources") | ||
build_file = Path(os.path.join(resources_dir, "misc")).resolve() | ||
|
||
|
||
class UtilitiesTest(unittest.TestCase): | ||
@parameterized.expand( | ||
[ | ||
("BUILD_no_additional_protos.bazel", " "), | ||
("BUILD_common_resources.bazel", " google/cloud/common_resources.proto"), | ||
("BUILD_comment_common_resources.bazel", " "), | ||
("BUILD_locations.bazel", " google/cloud/location/locations.proto"), | ||
("BUILD_comment_locations.bazel", " "), | ||
("BUILD_iam_policy.bazel", " google/iam/v1/iam_policy.proto"), | ||
("BUILD_comment_iam_policy.bazel", " "), | ||
( | ||
"BUILD_iam_locations.bazel", | ||
" google/cloud/location/locations.proto google/iam/v1/iam_policy.proto", | ||
), | ||
] | ||
) | ||
def test_gapic_inputs_parse_additional_protos(self, build_name, expected): | ||
parsed = parse(build_file, "", build_name) | ||
self.assertEqual( | ||
expected, | ||
parsed.additional_protos, | ||
) | ||
|
||
def test_gapic_inputs_parse_grpc_only_succeeds(self): | ||
parsed = parse(build_file, "", "BUILD_grpc.bazel") | ||
self.assertEqual("grpc", parsed.transport) | ||
|
||
def test_gapic_inputs_parse_grpc_rest_succeeds(self): | ||
parsed = parse(build_file, "", "BUILD_grpc_rest.bazel") | ||
self.assertEqual("grpc+rest", parsed.transport) | ||
|
||
def test_gapic_inputs_parse_rest_succeeds(self): | ||
parsed = parse(build_file, "", "BUILD_rest.bazel") | ||
self.assertEqual("rest", parsed.transport) | ||
|
||
def test_gapic_inputs_parse_empty_include_samples_succeeds(self): | ||
parsed = parse(build_file, "", "BUILD_include_samples_empty.bazel") | ||
self.assertEqual("false", parsed.include_samples) | ||
|
||
def test_gapic_inputs_parse_include_samples_false_succeeds(self): | ||
parsed = parse(build_file, "", "BUILD_include_samples_false.bazel") | ||
self.assertEqual("false", parsed.include_samples) | ||
|
||
def test_gapic_inputs_parse_include_samples_true_succeeds(self): | ||
parsed = parse(build_file, "", "BUILD_include_samples_true.bazel") | ||
self.assertEqual("true", parsed.include_samples) | ||
|
||
def test_gapic_inputs_parse_empty_rest_numeric_enums_succeeds(self): | ||
parsed = parse(build_file, "", "BUILD_rest_numeric_enums_empty.bazel") | ||
self.assertEqual("false", parsed.rest_numeric_enum) | ||
|
||
def test_gapic_inputs_parse_rest_numeric_enums_false_succeeds(self): | ||
parsed = parse(build_file, "", "BUILD_rest_numeric_enums_false.bazel") | ||
self.assertEqual("false", parsed.rest_numeric_enum) | ||
|
||
def test_gapic_inputs_parse_rest_numeric_enums_true_succeeds(self): | ||
parsed = parse(build_file, "", "BUILD_rest_numeric_enums_true.bazel") | ||
self.assertEqual("true", parsed.rest_numeric_enum) | ||
|
||
def test_gapic_inputs_parse_no_gapic_library_returns_proto_only_true(self): | ||
# include_samples_empty only has a gradle assembly rule | ||
parsed = parse(build_file, "", "BUILD_include_samples_empty.bazel") | ||
self.assertEqual("true", parsed.proto_only) | ||
|
||
def test_gapic_inputs_parse_with_gapic_library_returns_proto_only_false(self): | ||
# rest.bazel has a java_gapic_library rule | ||
parsed = parse(build_file, "", "BUILD_rest.bazel") | ||
self.assertEqual("false", parsed.proto_only) | ||
|
||
def test_gapic_inputs_parse_gapic_yaml_succeeds(self): | ||
parsed = parse(build_file, "test/versioned/path", "BUILD_gapic_yaml.bazel") | ||
self.assertEqual("test/versioned/path/test_gapic_yaml.yaml", parsed.gapic_yaml) | ||
|
||
def test_gapic_inputs_parse_no_gapic_yaml_returns_empty_string(self): | ||
parsed = parse(build_file, "test/versioned/path", "BUILD_no_gapic_yaml.bazel") | ||
self.assertEqual("", parsed.gapic_yaml) | ||
|
||
def test_gapic_inputs_parse_service_config_succeeds(self): | ||
parsed = parse(build_file, "test/versioned/path", "BUILD_service_config.bazel") | ||
self.assertEqual( | ||
"test/versioned/path/test_service_config.json", parsed.service_config | ||
) | ||
|
||
def test_gapic_inputs_parse_service_yaml_relative_target(self): | ||
parsed = parse( | ||
build_file, | ||
"google/cloud/compute/v1", | ||
"BUILD_service_config_relative_target.bazel", | ||
) | ||
self.assertEqual( | ||
"google/cloud/compute/v1/compute_grpc_service_config.json", | ||
parsed.service_config, | ||
) | ||
|
||
def test_gapic_inputs_parse_no_service_config_returns_empty_string(self): | ||
parsed = parse( | ||
build_file, "test/versioned/path", "BUILD_no_service_config.bazel" | ||
) | ||
self.assertEqual("", parsed.service_config) | ||
|
||
def test_gapic_inputs_parse_service_yaml_succeeds(self): | ||
parsed = parse(build_file, "test/versioned/path", "BUILD_service_yaml.bazel") | ||
self.assertEqual( | ||
"test/versioned/path/test_service_yaml.yaml", parsed.service_yaml | ||
) | ||
|
||
def test_gapic_inputs_parse_service_yaml_absolute_target(self): | ||
parsed = parse(build_file, "", "BUILD_service_yaml_absolute_target.bazel") | ||
self.assertEqual( | ||
"google/cloud/videointelligence/videointelligence_v1p3beta1.yaml", | ||
parsed.service_yaml, | ||
) | ||
|
||
def test_gapic_inputs_parse_no_service_yaml_returns_empty_string(self): | ||
parsed = parse(build_file, "test/versioned/path", "BUILD_no_service_yaml.bazel") | ||
self.assertEqual("", parsed.service_yaml) | ||
|
||
def test_gapic_inputs_parse_proto_only_returns_grpc(self): | ||
parsed = parse(build_file, "test/versioned/path", "BUILD_proto_only.bazel") | ||
self.assertEqual("grpc", parsed.transport) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"api_shortname": "baremetalsolution", | ||
"name_pretty": "Bare Metal Solution", | ||
"product_documentation": "https://cloud.google.com/bare-metal/docs", | ||
"api_description": "Bring your Oracle workloads to Google Cloud with Bare Metal Solution and jumpstart your cloud journey with minimal risk.", | ||
"client_documentation": "https://cloud.google.com/java/docs/reference/google-cloud-bare-metal-solution/latest/overview", | ||
"release_level": "preview", | ||
"transport": "grpc", | ||
"language": "java", | ||
"repo": "googleapis/sdk-platform-java", | ||
"repo_short": "java-bare-metal-solution", | ||
"distribution_name": "com.google.cloud:google-cloud-bare-metal-solution", | ||
"library_type": "OTHER", | ||
"requires_billing": true, | ||
"rest_documentation": "https://cloud.google.com/bare-metal/docs/reference/rest", | ||
"rpc_documentation": "https://cloud.google.com/bare-metal/docs/reference/rpc" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we call this
gapic_repo
? I see thatconfig
is already being passed around, can we just useconfig.contains_common_protos()
? I feel it is easier to understand.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this parameter as we already pass the config.