Skip to content

Commit

Permalink
separate two functions
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeWang1127 committed May 14, 2024
1 parent 5a4e495 commit 4b1e5c8
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion library_generation/generate_composed_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion library_generation/generate_pr_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion library_generation/generate_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions library_generation/model/generation_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions library_generation/test/integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
14 changes: 2 additions & 12 deletions library_generation/test/model/generation_config_unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions library_generation/utils/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 4b1e5c8

Please sign in to comment.