From 4b1e5c8e4806fd140ac5f3c79dc64b9ae685a497 Mon Sep 17 00:00:00 2001 From: JoeWang1127 Date: Tue, 14 May 2024 14:24:24 +0000 Subject: [PATCH] separate two functions --- library_generation/generate_composed_library.py | 2 +- library_generation/generate_pr_description.py | 2 +- library_generation/generate_repo.py | 2 +- library_generation/model/generation_config.py | 4 ++-- library_generation/test/integration_tests.py | 6 +++--- .../test/model/generation_config_unit_tests.py | 14 ++------------ library_generation/utils/utilities.py | 6 +++--- 7 files changed, 13 insertions(+), 23 deletions(-) diff --git a/library_generation/generate_composed_library.py b/library_generation/generate_composed_library.py index 28cc9d311a..79080c5aba 100755 --- a/library_generation/generate_composed_library.py +++ b/library_generation/generate_composed_library.py @@ -117,7 +117,7 @@ def generate_composed_library( "", versions_file, owlbot_cli_source_folder, - str(config.is_gapic_monorepo()).lower(), + str(config.is_monorepo()).lower(), config_path, ], "Library postprocessing", diff --git a/library_generation/generate_pr_description.py b/library_generation/generate_pr_description.py index a40df186ff..a223a8f88d 100644 --- a/library_generation/generate_pr_description.py +++ b/library_generation/generate_pr_description.py @@ -59,7 +59,7 @@ def generate_pr_descriptions( current_commit=config.googleapis_commitish, baseline_commit=baseline_commit, paths=paths, - is_monorepo=config.is_gapic_monorepo(), + is_monorepo=config.is_monorepo(), ) description_file = f"{description_path}/pr_description.txt" diff --git a/library_generation/generate_repo.py b/library_generation/generate_repo.py index 5c3b43c24c..1443efcf6d 100755 --- a/library_generation/generate_repo.py +++ b/library_generation/generate_repo.py @@ -60,7 +60,7 @@ def generate_from_yaml( gapic_repo=not config.contains_common_protos(), ) - if not config.is_gapic_monorepo(): + if not config.is_monorepo() or config.contains_common_protos(): return monorepo_postprocessing( diff --git a/library_generation/model/generation_config.py b/library_generation/model/generation_config.py index 2ba3ade042..3af6f5f4ac 100644 --- a/library_generation/model/generation_config.py +++ b/library_generation/model/generation_config.py @@ -60,8 +60,8 @@ def get_proto_path_to_library_name(self) -> dict[str, str]: paths[gapic_config.proto_path] = library.get_library_name() return paths - def is_gapic_monorepo(self) -> bool: - return len(self.libraries) > 1 and (not self.contains_common_protos()) + def is_monorepo(self) -> bool: + return len(self.libraries) > 1 def contains_common_protos(self) -> bool: return self.__contains_common_protos diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index eea8f202c9..2ffb353849 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -92,7 +92,7 @@ def test_entry_point_running_in_container(self): for library_name in library_names: actual_library = ( f"{repo_dest}/{library_name}" - if config.is_gapic_monorepo() + if config.is_monorepo() else repo_dest ) print("*" * 50) @@ -151,7 +151,7 @@ def test_entry_point_running_in_container(self): ) print(" .repo-metadata.json comparison succeed.") - if not config.is_gapic_monorepo(): + if not config.is_monorepo(): continue # compare gapic-libraries-bom/pom.xml and pom.xml @@ -218,7 +218,7 @@ def __prepare_golden_files( cls, config: GenerationConfig, library_names: list[str], repo_dest: str ): for library_name in library_names: - if config.is_gapic_monorepo(): + if config.is_monorepo(): copy_tree(f"{repo_dest}/{library_name}", f"{golden_dir}/{library_name}") copy_tree( f"{repo_dest}/gapic-libraries-bom", diff --git a/library_generation/test/model/generation_config_unit_tests.py b/library_generation/test/model/generation_config_unit_tests.py index b46f67bfee..8f94ecae1e 100644 --- a/library_generation/test/model/generation_config_unit_tests.py +++ b/library_generation/test/model/generation_config_unit_tests.py @@ -118,7 +118,7 @@ def test_is_monorepo_with_one_library_returns_false(self): template_excludes=[], libraries=[library_1], ) - self.assertFalse(config.is_gapic_monorepo()) + self.assertFalse(config.is_monorepo()) def test_is_monorepo_with_two_libraries_returns_true(self): config = GenerationConfig( @@ -128,17 +128,7 @@ def test_is_monorepo_with_two_libraries_returns_true(self): template_excludes=[], libraries=[library_1, library_2], ) - self.assertTrue(config.is_gapic_monorepo()) - - def test_is_monorepo_with_common_protos_returns_false(self): - config = GenerationConfig( - gapic_generator_version="", - googleapis_commitish="", - libraries_bom_version="", - template_excludes=[], - libraries=[library_1, library_2, common_protos_library], - ) - self.assertFalse(config.is_gapic_monorepo()) + self.assertTrue(config.is_monorepo()) def test_contains_common_protos_with_common_protos_returns_true(self): config = GenerationConfig( diff --git a/library_generation/utils/utilities.py b/library_generation/utils/utilities.py index 283cd96d44..f8526334ce 100755 --- a/library_generation/utils/utilities.py +++ b/library_generation/utils/utilities.py @@ -124,7 +124,7 @@ def prepare_repo( library_name = f"{language}-{library.get_library_name()}" library_path = ( f"{repo_path}/{library_name}" - if gen_config.is_gapic_monorepo() + if gen_config.is_monorepo() else f"{repo_path}" ) # use absolute path because docker requires absolute path @@ -217,7 +217,7 @@ def generate_prerequisite_files( distribution_name_short = re.split(r"[:/]", distribution_name)[-1] if not gapic_repo: repo = "googleapis/sdk-platform-java" - elif config.is_gapic_monorepo(): + elif config.is_monorepo(): repo = "googleapis/google-cloud-java" else: repo = f"googleapis/{language}-{library_name}" @@ -287,7 +287,7 @@ def generate_prerequisite_files( owlbot_yaml_file = ".OwlBot-hermetic.yaml" path_to_owlbot_yaml_file = ( f"{library_path}/{owlbot_yaml_file}" - if config.is_gapic_monorepo() + if config.is_monorepo() else f"{library_path}/.github/{owlbot_yaml_file}" ) if not os.path.exists(path_to_owlbot_yaml_file):