Skip to content

Commit

Permalink
chore: adjust repo-metadata generation to fit existing files in HW re…
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomarquezp authored Jun 19, 2024
1 parent f952e3f commit 9829721
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 22 deletions.
4 changes: 2 additions & 2 deletions library_generation/generate_composed_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ def generate_composed_library(
build_file_folder = Path(f"{output_folder}/{gapic.proto_path}").resolve()
print(f"build_file_folder: {build_file_folder}")
gapic_inputs = parse_build_file(build_file_folder, gapic.proto_path)
# generate prerequisite files (.repo-metadata.json, .OwlBot-hermetic.yaml,
# generate postprocessing prerequisite files (.repo-metadata.json, .OwlBot-hermetic.yaml,
# owlbot.py) here because transport is parsed from BUILD.bazel,
# which lives in a versioned proto_path.
util.generate_prerequisite_files(
util.generate_postprocessing_prerequisite_files(
config=config,
library=library,
proto_path=util.remove_version_from(gapic.proto_path),
Expand Down
2 changes: 2 additions & 0 deletions library_generation/model/generation_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ def from_yaml(path_to_yaml: str) -> GenerationConfig:
extra_versioned_modules=__optional(
library, "extra_versioned_modules", None
),
recommended_package=__optional(library, "recommended_package", None),
min_java_version=__optional(library, "min_java_version", None),
)
parsed_libraries.append(new_library)

Expand Down
8 changes: 8 additions & 0 deletions library_generation/model/library_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def __init__(
cloud_api: Optional[bool] = True,
requires_billing: Optional[bool] = True,
extra_versioned_modules: Optional[str] = None,
recommended_package: Optional[str] = None,
min_java_version: Optional[int] = None,
):
self.api_shortname = api_shortname
self.api_description = api_description
Expand All @@ -72,6 +74,8 @@ def __init__(
self.cloud_api = cloud_api
self.requires_billing = requires_billing
self.extra_versioned_modules = extra_versioned_modules
self.recommended_package = recommended_package
self.min_java_version = min_java_version

def get_library_name(self) -> str:
"""
Expand Down Expand Up @@ -105,6 +109,8 @@ def __eq__(self, other):
and self.cloud_api == other.cloud_api
and self.requires_billing == other.requires_billing
and self.extra_versioned_modules == other.extra_versioned_modules
and self.recommended_package == other.recommended_package
and self.min_java_version == other.min_java_version
)

def __hash__(self):
Expand Down Expand Up @@ -134,6 +140,8 @@ def __hash__(self):
self.cloud_api,
self.requires_billing,
self.extra_versioned_modules,
self.recommended_package,
self.min_java_version,
]
+ [config.proto_path for config in self.gapic_configs]
).encode("utf-8")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@
"library_type": "GAPIC_AUTO",
"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"
"rpc_documentation": "https://cloud.google.com/bare-metal/docs/reference/rpc",
"recommended_package": "com.google.example",
"min_java_version": 8
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
"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",
"extra_versioned_modules": "test-module"
"extra_versioned_modules": "test-module",
"recommended_package": "com.google.example",
"min_java_version": 8
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
"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"
"rpc_documentation": "https://cloud.google.com/bare-metal/docs/reference/rpc",
"recommended_package": "com.google.example",
"min_java_version": 8
}
30 changes: 18 additions & 12 deletions library_generation/test/utilities_unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
library_name="bare-metal-solution",
rest_documentation="https://cloud.google.com/bare-metal/docs/reference/rest",
rpc_documentation="https://cloud.google.com/bare-metal/docs/reference/rpc",
recommended_package="com.google.example",
min_java_version=8,
)
library_2 = LibraryConfig(
api_shortname="secretmanager",
Expand Down Expand Up @@ -167,8 +169,8 @@ def test_eprint_valid_input_succeeds(self):
# print() appends a `\n` each time it's called
self.assertEqual(test_input + "\n", result)

def test_generate_prerequisite_files_non_monorepo_success(self):
library_path = self.__setup_prerequisite_files(
def test_generate_postprocessing_prerequisite_files_non_monorepo_success(self):
library_path = self.__setup_postprocessing_prerequisite_files(
combination=1, library_type="GAPIC_COMBO"
)

Expand All @@ -185,10 +187,12 @@ def test_generate_prerequisite_files_non_monorepo_success(self):
file_comparator.compare_files(
f"{library_path}/owlbot.py", f"{library_path}/owlbot-golden.py"
)
self.__remove_prerequisite_files(path=library_path, is_monorepo=False)
self.__remove_postprocessing_prerequisite_files(
path=library_path, is_monorepo=False
)

def test_generate_prerequisite_files_monorepo_success(self):
library_path = self.__setup_prerequisite_files(combination=2)
def test_generate_postprocessing_prerequisite_files_monorepo_success(self):
library_path = self.__setup_postprocessing_prerequisite_files(combination=2)

file_comparator.compare_files(
f"{library_path}/.repo-metadata.json",
Expand All @@ -201,10 +205,10 @@ def test_generate_prerequisite_files_monorepo_success(self):
file_comparator.compare_files(
f"{library_path}/owlbot.py", f"{library_path}/owlbot-golden.py"
)
self.__remove_prerequisite_files(path=library_path)
self.__remove_postprocessing_prerequisite_files(path=library_path)

def test_generate_prerequisite_files_proto_only_repo_success(self):
library_path = self.__setup_prerequisite_files(
def test_generate_postprocessing_prerequisite_files_proto_only_repo_success(self):
library_path = self.__setup_postprocessing_prerequisite_files(
combination=3, library_type="OTHER"
)

Expand All @@ -219,7 +223,7 @@ def test_generate_prerequisite_files_proto_only_repo_success(self):
file_comparator.compare_files(
f"{library_path}/owlbot.py", f"{library_path}/owlbot-golden.py"
)
self.__remove_prerequisite_files(path=library_path)
self.__remove_postprocessing_prerequisite_files(path=library_path)

def test_prepare_repo_monorepo_success(self):
gen_config = self.__get_a_gen_config(2)
Expand Down Expand Up @@ -256,7 +260,7 @@ def test_prepare_repo_split_repo_success(self):
self.assertEqual(["misc"], library_path)
shutil.rmtree(repo_config.output_folder)

def __setup_prerequisite_files(
def __setup_postprocessing_prerequisite_files(
self,
combination: int,
library_type: str = "GAPIC_AUTO",
Expand All @@ -273,7 +277,7 @@ def __setup_prerequisite_files(
config = self.__get_a_gen_config(combination, library_type=library_type)
proto_path = "google/cloud/baremetalsolution/v2"
transport = "grpc"
util.generate_prerequisite_files(
util.generate_postprocessing_prerequisite_files(
config=config,
library=library,
proto_path=proto_path,
Expand Down Expand Up @@ -319,7 +323,9 @@ def __get_a_gen_config(
)

@staticmethod
def __remove_prerequisite_files(path: str, is_monorepo: bool = True) -> None:
def __remove_postprocessing_prerequisite_files(
path: str, is_monorepo: bool = True
) -> None:
os.remove(f"{path}/.repo-metadata.json")
os.remove(f"{path}/owlbot.py")
if is_monorepo:
Expand Down
13 changes: 8 additions & 5 deletions library_generation/utils/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def pull_api_definition(
)


def generate_prerequisite_files(
def generate_postprocessing_prerequisite_files(
config: GenerationConfig,
library: LibraryConfig,
proto_path: str,
Expand All @@ -192,14 +192,13 @@ def generate_prerequisite_files(
language: str = "java",
) -> None:
"""
Generate prerequisite files for a library.
Note that the version, if any, in the proto_path will be removed.
Generates the postprocessing prerequisite files for a library.
:param config: a GenerationConfig object representing a parsed configuration
yaml
:param library: the library configuration
:param proto_path: the proto path
:param proto_path: the path from the root of googleapis to the location of the service
protos. If the path contains a version, it will be removed
:param transport: transport supported by the library
:param library_path: the path to which the generated file goes
:param language: programming language of the library
Expand Down Expand Up @@ -275,6 +274,10 @@ def generate_prerequisite_files(
repo_metadata["rpc_documentation"] = library.rpc_documentation
if library.extra_versioned_modules:
repo_metadata["extra_versioned_modules"] = library.extra_versioned_modules
if library.recommended_package:
repo_metadata["recommended_package"] = library.recommended_package
if library.min_java_version:
repo_metadata["min_java_version"] = library.min_java_version

# generate .repo-meta.json
json_file = ".repo-metadata.json"
Expand Down

0 comments on commit 9829721

Please sign in to comment.