From 7673a5c7208168b0c25f9d147e0d924443f2a053 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Tue, 17 Sep 2024 12:20:08 -0400 Subject: [PATCH 01/21] feat: generate library from local api definition --- library_generation/cli/entry_point.py | 20 ++++++++++- .../generate_composed_library.py | 6 +--- library_generation/generate_repo.py | 6 ++++ library_generation/utils/utilities.py | 36 ------------------- 4 files changed, 26 insertions(+), 42 deletions(-) diff --git a/library_generation/cli/entry_point.py b/library_generation/cli/entry_point.py index d69dde1b77..54d7b60869 100644 --- a/library_generation/cli/entry_point.py +++ b/library_generation/cli/entry_point.py @@ -63,10 +63,21 @@ def main(ctx): directory. """, ) +@click.option( + "--api-definition-path", + type=str, + default=".", + show_default=True, + help=""" + The path to which the api definition (protos and service yaml) resides. + If not specified, the path is the current working directory. + """, +) def generate( baseline_generation_config_path: str, current_generation_config_path: str, repository_path: str, + api_definition_path: str, ): """ Compare baseline generation config and current generation config and @@ -90,7 +101,10 @@ def generate( repository_path/pr_description.txt. """ __generate_repo_and_pr_description_impl( - baseline_generation_config_path, current_generation_config_path, repository_path + baseline_generation_config_path=baseline_generation_config_path, + current_generation_config_path=current_generation_config_path, + repository_path=repository_path, + api_definition_path=api_definition_path, ) @@ -98,6 +112,7 @@ def __generate_repo_and_pr_description_impl( baseline_generation_config_path: str, current_generation_config_path: str, repository_path: str, + api_definition_path: str, ): """ Implementation method for generate(). @@ -129,6 +144,7 @@ def __generate_repo_and_pr_description_impl( current_generation_config_path = os.path.abspath(current_generation_config_path) repository_path = os.path.abspath(repository_path) + api_definition_path = os.path.abspath(api_definition_path) if not baseline_generation_config_path: # Execute full generation based on current_generation_config if # baseline_generation_config is not specified. @@ -136,6 +152,7 @@ def __generate_repo_and_pr_description_impl( generate_from_yaml( config=from_yaml(current_generation_config_path), repository_path=repository_path, + api_definition_path=api_definition_path, ) return @@ -155,6 +172,7 @@ def __generate_repo_and_pr_description_impl( generate_from_yaml( config=config_change.current_config, repository_path=repository_path, + api_definition_path=api_definition_path, target_library_names=target_library_names, ) generate_pr_descriptions( diff --git a/library_generation/generate_composed_library.py b/library_generation/generate_composed_library.py index 2fd014f791..51d1ef21f3 100755 --- a/library_generation/generate_composed_library.py +++ b/library_generation/generate_composed_library.py @@ -59,10 +59,6 @@ def generate_composed_library( :return None """ output_folder = repo_config.output_folder - util.pull_api_definition( - config=config, library=library, output_folder=output_folder - ) - base_arguments = __construct_tooling_arg(config=config) owlbot_cli_source_folder = util.sh_util("mktemp -d") os.makedirs(f"{library_path}", exist_ok=True) @@ -73,7 +69,7 @@ def generate_composed_library( # 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. The value of transport will be - # overriden by the config object if specified. Note that this override + # overridden by the config object if specified. Note that this override # does not affect library generation but instead used only for # generating postprocessing files such as README. util.generate_postprocessing_prerequisite_files( diff --git a/library_generation/generate_repo.py b/library_generation/generate_repo.py index a4f6a5382e..0c7d5b10d5 100755 --- a/library_generation/generate_repo.py +++ b/library_generation/generate_repo.py @@ -12,6 +12,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import shutil + import library_generation.utils.utilities as util from library_generation.generate_composed_library import generate_composed_library from library_generation.model.generation_config import GenerationConfig @@ -22,6 +24,7 @@ def generate_from_yaml( config: GenerationConfig, repository_path: str, + api_definition_path: str, target_library_names: list[str] = None, ) -> None: """ @@ -31,6 +34,7 @@ def generate_from_yaml( :param config: a GenerationConfig object. :param repository_path: The repository path to which the generated files will be sent. + :param api_definition_path: :param target_library_names: a list of libraries to be generated. If specified, only the library whose library_name is in target_library_names will be generated. @@ -43,6 +47,8 @@ def generate_from_yaml( repo_config = util.prepare_repo( gen_config=config, library_config=target_libraries, repo_path=repository_path ) + # copy api definition to output folder. + shutil.copytree(api_definition_path, repo_config.output_folder) for library_path, library in repo_config.get_libraries().items(): print(f"generating library {library.get_library_name()}") diff --git a/library_generation/utils/utilities.py b/library_generation/utils/utilities.py index 1aa60d21c0..894a06ec02 100755 --- a/library_generation/utils/utilities.py +++ b/library_generation/utils/utilities.py @@ -171,42 +171,6 @@ def prepare_repo( ) -def pull_api_definition( - config: GenerationConfig, library: LibraryConfig, output_folder: str -) -> None: - """ - Pull APIs definition from googleapis/googleapis repository. - To avoid duplicated pulling, only perform pulling if the library uses a - different commitish than in generation config. - :param config: a GenerationConfig object representing a parsed configuration - yaml - :param library: a LibraryConfig object contained inside config, passed here - for convenience and to prevent all libraries to be processed - :param output_folder: the folder to which APIs definition (proto files) goes - :return: None - """ - googleapis_commitish = config.googleapis_commitish - if library.googleapis_commitish: - googleapis_commitish = library.googleapis_commitish - print(f"using library-specific googleapis commitish: {googleapis_commitish}") - else: - print(f"using common googleapis_commitish: {config.googleapis_commitish}") - - if googleapis_commitish != config.googleapis_commitish: - print("removing existing APIs definition") - shutil.rmtree(f"{output_folder}/google", ignore_errors=True) - shutil.rmtree(f"{output_folder}/grafeas", ignore_errors=True) - - if not ( - os.path.exists(f"{output_folder}/google") - and os.path.exists(f"{output_folder}/grafeas") - ): - print("downloading googleapis") - sh_util( - f"download_googleapis_files_and_folders {output_folder} {googleapis_commitish}" - ) - - def generate_postprocessing_prerequisite_files( config: GenerationConfig, library: LibraryConfig, From 574e80ca70f9f7ac666bb9a8dd3b3bc87b6da9d2 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Tue, 17 Sep 2024 12:31:44 -0400 Subject: [PATCH 02/21] fix broken tests --- .../test/cli/entry_point_unit_tests.py | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/library_generation/test/cli/entry_point_unit_tests.py b/library_generation/test/cli/entry_point_unit_tests.py index e05c64de55..efaa66af90 100644 --- a/library_generation/test/cli/entry_point_unit_tests.py +++ b/library_generation/test/cli/entry_point_unit_tests.py @@ -105,9 +105,13 @@ def test_generate_non_monorepo_without_changes_triggers_full_generation( baseline_generation_config_path=config_path, current_generation_config_path=config_path, repository_path=".", + api_definition_path=".", ) generate_from_yaml.assert_called_with( - config=ANY, repository_path=ANY, target_library_names=None + config=ANY, + repository_path=ANY, + api_definition_path=ANY, + target_library_names=None, ) @patch("library_generation.cli.entry_point.generate_from_yaml") @@ -134,9 +138,13 @@ def test_generate_non_monorepo_with_changes_triggers_full_generation( baseline_generation_config_path=baseline_config_path, current_generation_config_path=current_config_path, repository_path=".", + api_definition_path=".", ) generate_from_yaml.assert_called_with( - config=ANY, repository_path=ANY, target_library_names=None + config=ANY, + repository_path=ANY, + api_definition_path=ANY, + target_library_names=None, ) @patch("library_generation.cli.entry_point.generate_from_yaml") @@ -160,9 +168,13 @@ def test_generate_monorepo_with_common_protos_triggers_full_generation( baseline_generation_config_path=config_path, current_generation_config_path=config_path, repository_path=".", + api_definition_path=".", ) generate_from_yaml.assert_called_with( - config=ANY, repository_path=ANY, target_library_names=None + config=ANY, + repository_path=ANY, + api_definition_path=ANY, + target_library_names=None, ) @patch("library_generation.cli.entry_point.generate_from_yaml") @@ -187,7 +199,11 @@ def test_generate_monorepo_without_common_protos_does_not_trigger_full_generatio baseline_generation_config_path=config_path, current_generation_config_path=config_path, repository_path=".", + api_definition_path=".", ) generate_from_yaml.assert_called_with( - config=ANY, repository_path=ANY, target_library_names=[] + config=ANY, + repository_path=ANY, + api_definition_path=ANY, + target_library_names=[], ) From f59b5c8fcad34bb6989c8f5a7002a71f9d58a98a Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Tue, 17 Sep 2024 13:27:07 -0400 Subject: [PATCH 03/21] copy if dir exists --- library_generation/generate_repo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library_generation/generate_repo.py b/library_generation/generate_repo.py index 0c7d5b10d5..3f4a3c59bf 100755 --- a/library_generation/generate_repo.py +++ b/library_generation/generate_repo.py @@ -48,7 +48,7 @@ def generate_from_yaml( gen_config=config, library_config=target_libraries, repo_path=repository_path ) # copy api definition to output folder. - shutil.copytree(api_definition_path, repo_config.output_folder) + shutil.copytree(api_definition_path, repo_config.output_folder, dirs_exist_ok=True) for library_path, library in repo_config.get_libraries().items(): print(f"generating library {library.get_library_name()}") From 69df0e16372a4fc0d10690bea669b98cad06335d Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Tue, 17 Sep 2024 14:23:08 -0400 Subject: [PATCH 04/21] copy api definition in IT --- library_generation/test/integration_tests.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index ebb8c66afa..e6a3d8fbcc 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -13,6 +13,7 @@ # limitations under the License. import difflib import json +import tempfile from filecmp import cmp from filecmp import dircmp from git import Repo @@ -46,7 +47,7 @@ } baseline_config_name = "baseline_generation_config.yaml" current_config_name = "current_generation_config.yaml" - +googleapis_committish = "113a378d5aad5018876ec0a8cbfd4d6a4f746809" # This variable is used to override the jar created by building the image # with our own downloaded jar in order to lock the integration test to use # a constant version specified in @@ -54,7 +55,7 @@ # This allows us to decouple the generation workflow testing with what the # generator jar will actually generate. # See library_generation/DEVELOPMENT.md ("The Hermetic Build's -# well-known folder). +# well-known folder"). WELL_KNOWN_GENERATOR_JAR_FILENAME = "gapic-generator-java.jar" @@ -68,6 +69,7 @@ def setUpClass(cls) -> None: def setUp(cls) -> None: cls.__remove_generated_files() os.makedirs(f"{golden_dir}", exist_ok=True) + cls.__copy_api_definition_to_output_dir(googleapis_committish) def test_entry_point_running_in_container(self): config_files = self.__get_config_files(config_dir) @@ -189,9 +191,20 @@ def test_entry_point_running_in_container(self): print(" PR description comparison succeed.") self.__remove_generated_files() + @classmethod + def __copy_api_definition_to_output_dir(cls, committish: str): + temp_dir = tempfile.mkdtemp() + repo_dest = cls.__pull_repo_to( + dest=temp_dir, repo="googleapis", committish=committish + ) + print(f"Copying api definition to {output_dir}...") + shutil.copytree(f"{repo_dest}/google", output_dir, dirs_exist_ok=True) + shutil.copytree(f"{repo_dest}/grafeas", output_dir, dirs_exist_ok=True) + shutil.rmtree(temp_dir) + @classmethod def __build_image(cls, docker_file: str, cwd: str): - # we build the docker image without removing intermediate containers so + # we build the docker image without removing intermediate containers, so # we can re-test more quickly subprocess.check_call( ["docker", "build", "-f", docker_file, "-t", image_tag, "."], From 8f917de06a92cdf09bec010d8c23e0977d67359e Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Tue, 17 Sep 2024 14:55:15 -0400 Subject: [PATCH 05/21] copy api to temp dir --- library_generation/cli/entry_point.py | 2 +- library_generation/generate_repo.py | 2 +- library_generation/test/integration_tests.py | 22 +++++++++++++------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/library_generation/cli/entry_point.py b/library_generation/cli/entry_point.py index 54d7b60869..eab6baff50 100644 --- a/library_generation/cli/entry_point.py +++ b/library_generation/cli/entry_point.py @@ -69,7 +69,7 @@ def main(ctx): default=".", show_default=True, help=""" - The path to which the api definition (protos and service yaml) resides. + The path to which the api definition (proto and service yaml) resides. If not specified, the path is the current working directory. """, ) diff --git a/library_generation/generate_repo.py b/library_generation/generate_repo.py index 3f4a3c59bf..e61d462cf4 100755 --- a/library_generation/generate_repo.py +++ b/library_generation/generate_repo.py @@ -34,7 +34,7 @@ def generate_from_yaml( :param config: a GenerationConfig object. :param repository_path: The repository path to which the generated files will be sent. - :param api_definition_path: + :param api_definition_path: The path to where the api definition resides. :param target_library_names: a list of libraries to be generated. If specified, only the library whose library_name is in target_library_names will be generated. diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index e6a3d8fbcc..b7e37876bb 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -69,9 +69,9 @@ def setUpClass(cls) -> None: def setUp(cls) -> None: cls.__remove_generated_files() os.makedirs(f"{golden_dir}", exist_ok=True) - cls.__copy_api_definition_to_output_dir(googleapis_committish) def test_entry_point_running_in_container(self): + api_definition_path = self.__copy_api_definition(googleapis_committish) config_files = self.__get_config_files(config_dir) for repo, config_file in config_files: config = from_yaml(config_file) @@ -92,6 +92,7 @@ def test_entry_point_running_in_container(self): config_location=config_location, baseline_config=baseline_config_name, current_config=current_config_name, + api_definition=api_definition_path, ) # 4. compare generation result with golden files print( @@ -192,15 +193,16 @@ def test_entry_point_running_in_container(self): self.__remove_generated_files() @classmethod - def __copy_api_definition_to_output_dir(cls, committish: str): - temp_dir = tempfile.mkdtemp() + def __copy_api_definition(cls, committish: str) -> str: repo_dest = cls.__pull_repo_to( - dest=temp_dir, repo="googleapis", committish=committish + dest=tempfile.mkdtemp(), repo="googleapis", committish=committish ) - print(f"Copying api definition to {output_dir}...") - shutil.copytree(f"{repo_dest}/google", output_dir, dirs_exist_ok=True) - shutil.copytree(f"{repo_dest}/grafeas", output_dir, dirs_exist_ok=True) - shutil.rmtree(temp_dir) + api_temp_dir = tempfile.mkdtemp() + print(f"Copying api definition to {api_temp_dir}...") + shutil.copytree(f"{repo_dest}/google", api_temp_dir, dirs_exist_ok=True) + shutil.copytree(f"{repo_dest}/grafeas", api_temp_dir, dirs_exist_ok=True) + shutil.rmtree(repo_dest) + return api_temp_dir @classmethod def __build_image(cls, docker_file: str, cwd: str): @@ -291,6 +293,7 @@ def __run_entry_point_in_docker_container( config_location: str, baseline_config: str, current_config: str, + api_definition: str, ): # we use the calling user to prevent the mapped volumes from changing # owners @@ -308,12 +311,15 @@ def __run_entry_point_in_docker_container( "-v", f"{config_location}:/workspace/config", "-v", + f"{api_definition}:/workspace/api", + "-v", f"{config_dir}/{WELL_KNOWN_GENERATOR_JAR_FILENAME}:/home/.library_generation/{WELL_KNOWN_GENERATOR_JAR_FILENAME}", "-w", "/workspace/repo", image_tag, f"--baseline-generation-config-path=/workspace/config/{baseline_config}", f"--current-generation-config-path=/workspace/config/{current_config}", + f"--api-definition-path=/workspace/api", ], ) From d9bd2df22486a3906f3dc38f0b2a42dad697fad6 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Tue, 17 Sep 2024 15:20:55 -0400 Subject: [PATCH 06/21] debug --- library_generation/generate_repo.py | 6 ++++++ library_generation/test/integration_tests.py | 2 ++ 2 files changed, 8 insertions(+) diff --git a/library_generation/generate_repo.py b/library_generation/generate_repo.py index e61d462cf4..d11a8ae9ca 100755 --- a/library_generation/generate_repo.py +++ b/library_generation/generate_repo.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import os import shutil import library_generation.utils.utilities as util @@ -48,7 +49,12 @@ def generate_from_yaml( gen_config=config, library_config=target_libraries, repo_path=repository_path ) # copy api definition to output folder. + print( + f"Copy api definition from {api_definition_path} to {repo_config.output_folder}" + ) shutil.copytree(api_definition_path, repo_config.output_folder, dirs_exist_ok=True) + print(f"List files in {repo_config.output_folder}") + os.listdir(repo_config.output_folder) for library_path, library in repo_config.get_libraries().items(): print(f"generating library {library.get_library_name()}") diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index b7e37876bb..9e1c40caa8 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -202,6 +202,8 @@ def __copy_api_definition(cls, committish: str) -> str: shutil.copytree(f"{repo_dest}/google", api_temp_dir, dirs_exist_ok=True) shutil.copytree(f"{repo_dest}/grafeas", api_temp_dir, dirs_exist_ok=True) shutil.rmtree(repo_dest) + print(f"List files and dirs in {api_temp_dir}") + os.listdir(api_temp_dir) return api_temp_dir @classmethod From b5491c586ea669c8f0f371960f9a40936620279f Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Tue, 17 Sep 2024 15:30:07 -0400 Subject: [PATCH 07/21] debug --- library_generation/generate_repo.py | 2 +- library_generation/test/integration_tests.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library_generation/generate_repo.py b/library_generation/generate_repo.py index d11a8ae9ca..e5b69dfd46 100755 --- a/library_generation/generate_repo.py +++ b/library_generation/generate_repo.py @@ -54,7 +54,7 @@ def generate_from_yaml( ) shutil.copytree(api_definition_path, repo_config.output_folder, dirs_exist_ok=True) print(f"List files in {repo_config.output_folder}") - os.listdir(repo_config.output_folder) + print(os.listdir(repo_config.output_folder)) for library_path, library in repo_config.get_libraries().items(): print(f"generating library {library.get_library_name()}") diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index 9e1c40caa8..ad073dae12 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -203,7 +203,7 @@ def __copy_api_definition(cls, committish: str) -> str: shutil.copytree(f"{repo_dest}/grafeas", api_temp_dir, dirs_exist_ok=True) shutil.rmtree(repo_dest) print(f"List files and dirs in {api_temp_dir}") - os.listdir(api_temp_dir) + print(os.listdir(api_temp_dir)) return api_temp_dir @classmethod From 0c7e34719df2d33ac1216642350801ce66200d53 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Tue, 17 Sep 2024 15:44:13 -0400 Subject: [PATCH 08/21] copy to dir --- library_generation/test/integration_tests.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index ad073dae12..235dc501dd 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -199,8 +199,12 @@ def __copy_api_definition(cls, committish: str) -> str: ) api_temp_dir = tempfile.mkdtemp() print(f"Copying api definition to {api_temp_dir}...") - shutil.copytree(f"{repo_dest}/google", api_temp_dir, dirs_exist_ok=True) - shutil.copytree(f"{repo_dest}/grafeas", api_temp_dir, dirs_exist_ok=True) + shutil.copytree( + f"{repo_dest}/google", f"{api_temp_dir}/google", dirs_exist_ok=True + ) + shutil.copytree( + f"{repo_dest}/grafeas", f"{api_temp_dir}/grafeas", dirs_exist_ok=True + ) shutil.rmtree(repo_dest) print(f"List files and dirs in {api_temp_dir}") print(os.listdir(api_temp_dir)) From 6455d492c5642e02568e073707684dbb1bbd4e5c Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Tue, 17 Sep 2024 15:55:16 -0400 Subject: [PATCH 09/21] remove debug output --- library_generation/generate_repo.py | 5 ----- library_generation/test/integration_tests.py | 2 -- 2 files changed, 7 deletions(-) diff --git a/library_generation/generate_repo.py b/library_generation/generate_repo.py index e5b69dfd46..2a2329840b 100755 --- a/library_generation/generate_repo.py +++ b/library_generation/generate_repo.py @@ -49,12 +49,7 @@ def generate_from_yaml( gen_config=config, library_config=target_libraries, repo_path=repository_path ) # copy api definition to output folder. - print( - f"Copy api definition from {api_definition_path} to {repo_config.output_folder}" - ) shutil.copytree(api_definition_path, repo_config.output_folder, dirs_exist_ok=True) - print(f"List files in {repo_config.output_folder}") - print(os.listdir(repo_config.output_folder)) for library_path, library in repo_config.get_libraries().items(): print(f"generating library {library.get_library_name()}") diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index 235dc501dd..3ba0f98dc6 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -206,8 +206,6 @@ def __copy_api_definition(cls, committish: str) -> str: f"{repo_dest}/grafeas", f"{api_temp_dir}/grafeas", dirs_exist_ok=True ) shutil.rmtree(repo_dest) - print(f"List files and dirs in {api_temp_dir}") - print(os.listdir(api_temp_dir)) return api_temp_dir @classmethod From 02e6ae20931fe5f45519f70ee2e56178dfa54f89 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Tue, 17 Sep 2024 16:13:30 -0400 Subject: [PATCH 10/21] change readme --- library_generation/DEVELOPMENT.md | 2 +- library_generation/README.md | 33 +++++++++++++------- library_generation/test/integration_tests.py | 8 ++--- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/library_generation/DEVELOPMENT.md b/library_generation/DEVELOPMENT.md index 858b467797..4d3d57955d 100644 --- a/library_generation/DEVELOPMENT.md +++ b/library_generation/DEVELOPMENT.md @@ -102,7 +102,7 @@ shell session. ## Running the script The entrypoint script (`library_generation/cli/entry_point.py`) allows you to update the target repository with the latest changes starting from the -googleapis committish declared in `generation_config.yaml`. +googleapis commitish declared in `generation_config.yaml`. ### Download the repo For example, google-cloud-java diff --git a/library_generation/README.md b/library_generation/README.md index bead08e290..3981df7225 100644 --- a/library_generation/README.md +++ b/library_generation/README.md @@ -48,6 +48,12 @@ right version for each library. Please refer [here](go/java-client-releasing#versionstxt-manifest) for more info of versions.txt. +### Api definition path (`api_definition_path`), optional + +The path to where the api definition (proto, service yaml) resides. + +The default value is the current working directory when running the script. + ## Output of `entry_point.py` ### GAPIC libraries @@ -74,11 +80,13 @@ will be created/modified: | pom.xml (repo root dir) | Always generated from inputs | | versions.txt | New entries will be added if they don’t exist | -### googleapis commit history +### Change history If both `baseline_generation_config` and `current_generation_config` are -specified, and they contain different googleapis commit, the commit history will -be generated into `pr_description.txt` in the `repository_path`. +specified and the contents are different, the changed contents will be generated +into `pr_description.txt` in the `repository_path`. +In addition, if the `googleapis_commitish` is different, the googleapis commit +history will be generated. ## Configuration to generate a repository @@ -96,7 +104,7 @@ They are shared by library level parameters. | gapic_generator_version | No | set through env variable if not specified | | protoc_version | No | inferred from the generator if not specified | | grpc_version | No | inferred from the generator if not specified | -| googleapis-commitish | Yes | | +| googleapis_commitish | Yes | | | libraries_bom_version | No | empty string if not specified | ### Library level parameters @@ -183,14 +191,16 @@ The virtual environment can be installed to any folder, usually it is recommende 2. Assuming the virtual environment is installed under `sdk-platform-java`. Run the following command under the root folder of `sdk-platform-java` to install the dependencies of `library_generation` -```bash -python -m pip install -r library_generation/requirements.txt -``` + ```bash + python -m pip install -r library_generation/requirements.txt + ``` 3. Run the following command to install `library_generation` as a module, which allows the `library_generation` module to be imported from anywhere -```bash -python -m pip install library_generation/ -``` + ```bash + python -m pip install library_generation/ + ``` + +4. Download api definition to a local directory ## An example to generate a repository using `entry_point.py` @@ -198,7 +208,8 @@ python -m pip install library_generation/ python library_generation/entry_point.py generate \ --baseline-generation-config-path=/path/to/baseline_config_file \ --current-generation-config-path=/path/to/current_config_file \ ---repository-path=path/to/repository +--repository-path=path/to/repository \ +--api-definition-path=path/to/api_definition ``` If you run `entry_point.py` with the example [configuration](#an-example-of-generation-configuration) shown above, the repository structure is: diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index 3ba0f98dc6..a4c458e811 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -41,13 +41,13 @@ repo_prefix = "https://github.com/googleapis" output_dir = shell_call("get_output_folder") # this map tells which branch of each repo should we use for our diff tests -committish_map = { +commitish_map = { "google-cloud-java": "chore/test-hermetic-build", "java-bigtable": "chore/test-hermetic-build", } baseline_config_name = "baseline_generation_config.yaml" current_config_name = "current_generation_config.yaml" -googleapis_committish = "113a378d5aad5018876ec0a8cbfd4d6a4f746809" +googleapis_commitish = "113a378d5aad5018876ec0a8cbfd4d6a4f746809" # This variable is used to override the jar created by building the image # with our own downloaded jar in order to lock the integration test to use # a constant version specified in @@ -71,7 +71,7 @@ def setUp(cls) -> None: os.makedirs(f"{golden_dir}", exist_ok=True) def test_entry_point_running_in_container(self): - api_definition_path = self.__copy_api_definition(googleapis_committish) + api_definition_path = self.__copy_api_definition(googleapis_commitish) config_files = self.__get_config_files(config_dir) for repo, config_file in config_files: config = from_yaml(config_file) @@ -79,7 +79,7 @@ def test_entry_point_running_in_container(self): config_location = f"{golden_dir}/../{repo}" # 1. pull repository repo_dest = self.__pull_repo_to( - Path(repo_location), repo, committish_map[repo] + Path(repo_location), repo, commitish_map[repo] ) # 2. prepare golden files library_names = self.__get_library_names_from_config(config) From 855d60132e57a2b76bcc70585bb737f420cbcfed Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Tue, 17 Sep 2024 16:27:37 -0400 Subject: [PATCH 11/21] change development guide --- library_generation/DEVELOPMENT.md | 36 +++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/library_generation/DEVELOPMENT.md b/library_generation/DEVELOPMENT.md index 4d3d57955d..438ccb5794 100644 --- a/library_generation/DEVELOPMENT.md +++ b/library_generation/DEVELOPMENT.md @@ -101,8 +101,14 @@ shell session. ## Running the script The entrypoint script (`library_generation/cli/entry_point.py`) allows you to -update the target repository with the latest changes starting from the -googleapis commitish declared in `generation_config.yaml`. +generate a GAPIC repository with a given api definition (proto, service yaml). + +### Download the api definition +For example, googleapis +``` +git clone https://github.com/googleapis/googleapis +export api_definition_path="$(pwd)/googleapis" +``` ### Download the repo For example, google-cloud-java @@ -118,7 +124,9 @@ python -m pip install . ### Run the script ``` -python cli/entry_point.py generate --repository-path="${path_to_repo}" +python cli/entry_point.py generate \ + --repository-path="${path_to_repo}" \ + --api-definition-path="${api_definition_path}" ``` @@ -144,16 +152,21 @@ repo to this folder). To run the docker container on the google-cloud-java repo, you must run: ```bash -docker run -u "$(id -u)":"$(id -g)" -v/path/to/google-cloud-java:/workspace $(cat image-id) +docker run \ + -u "$(id -u)":"$(id -g)" \ + -v /path/to/google-cloud-java:/workspace \ + $(cat image-id) ``` * `-u "$(id -u)":"$(id -g)"` makes docker run the container impersonating yourself. This avoids folder ownership changes since it runs as root by default. - * `-v/path/to/google-cloud-java:/workspace` maps the host machine's - google-cloud-java folder to the /workspace folder. The image is configured to - perform changes in this directory - * `$(cat image-id)` obtains the image ID created in the build step + * `-v /path/to/google-cloud-java:/workspace` maps the host machine's + google-cloud-java folder to the /workspace folder. + The image is configured to perform changes in this directory. + Note that this setup assumes the api definition resides in host machine's + google-cloud-java folder. + * `$(cat image-id)` obtains the image ID created in the build step. ## Debug the created containers If you are working on changing the way the containers are created, you may want @@ -173,5 +186,10 @@ We add `less` and `vim` as text tools for further inspection. You can also run a shell in a new container by running: ```bash -docker run --rm -it -u=$(id -u):$(id -g) -v/path/to/google-cloud-java:/workspace --entrypoint="bash" $(cat image-id) +docker run \ + --rm -it \ + -u $(id -u):$(id -g) \ + -v /path/to/google-cloud-java:/workspace \ + --entrypoint="bash" \ + $(cat image-id) ``` From c6af16e4e70d2f90b3643b71095f823eb1e24e7f Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Wed, 18 Sep 2024 10:41:57 -0400 Subject: [PATCH 12/21] change doc --- library_generation/README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/library_generation/README.md b/library_generation/README.md index 3981df7225..deb8b1b80b 100644 --- a/library_generation/README.md +++ b/library_generation/README.md @@ -1,7 +1,7 @@ # Generate a repository containing GAPIC Client Libraries The script, `entry_point.py`, allows you to generate a repository containing -GAPIC client libraries with googleapis commit history (a monorepo, for example, +GAPIC client libraries with change history (a monorepo, for example, google-cloud-java) from a configuration file. ## Environment @@ -54,6 +54,14 @@ The path to where the api definition (proto, service yaml) resides. The default value is the current working directory when running the script. +Note that you need not only the protos defined the service, but also the transitive +dependencies of those protos. +For example, if your service is defined in `example_service.proto` and it imports +`google/api/annotations.proto`, you need the `annotations.proto` resides in a +folder that has the exact structure of the import statement (`google/api` in this +case), and set `api_definition_path` to the path contains the root folder (`google` +in this case). + ## Output of `entry_point.py` ### GAPIC libraries From 1600dfbcd3e34d4d645286906099b360cc5dbbe6 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Wed, 18 Sep 2024 11:15:55 -0400 Subject: [PATCH 13/21] download api def --- .github/scripts/hermetic_library_generation.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/scripts/hermetic_library_generation.sh b/.github/scripts/hermetic_library_generation.sh index 73f4a39426..a162c44b67 100755 --- a/.github/scripts/hermetic_library_generation.sh +++ b/.github/scripts/hermetic_library_generation.sh @@ -84,16 +84,29 @@ git show "${target_branch}":"${generation_config}" > "${baseline_generation_conf # get .m2 folder so it's mapped into the docker container m2_folder=$(dirname "$(mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout)") +# download api definition from googleapis repository +googleapis_commitish=$(grep googleapis_commitish "${generation_config}" | cut -d ":" -f 2 | xargs) +api_def_dir=$(mktemp -d) +git clone https://github.com/googleapis/googleapis.git "${api_def_dir}" +pushd "${api_def_dir}" +git checkout "${googleapis_commitish}" +popd + # run hermetic code generation docker image. docker run \ --rm \ -u "$(id -u):$(id -g)" \ -v "$(pwd):${workspace_name}" \ -v "${m2_folder}":/home/.m2 \ + -v "${api_def_dir}:${workspace_name}/api" \ -e GENERATOR_VERSION="${image_tag}" \ gcr.io/cloud-devrel-public-resources/java-library-generation:"${image_tag}" \ --baseline-generation-config-path="${workspace_name}/${baseline_generation_config}" \ - --current-generation-config-path="${workspace_name}/${generation_config}" + --current-generation-config-path="${workspace_name}/${generation_config}" \ + --api-definition-path="${workspace_name}/api" + +# remove api definition after generation +rm -rf "${api_def_dir}" # commit the change to the pull request. rm -rdf output googleapis "${baseline_generation_config}" From e3139aee88b90dcced21e510663e34cc2280a7b7 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Wed, 18 Sep 2024 11:31:34 -0400 Subject: [PATCH 14/21] remove api def in IT --- library_generation/test/integration_tests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index a4c458e811..da88221d6e 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -191,6 +191,7 @@ def test_entry_point_running_in_container(self): ) print(" PR description comparison succeed.") self.__remove_generated_files() + shutil.rmtree(api_definition_path) @classmethod def __copy_api_definition(cls, committish: str) -> str: From a3e9840fc9ec1ae6b35560c45700bb2fbd44e7da Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Thu, 19 Sep 2024 14:32:24 -0400 Subject: [PATCH 15/21] change comment --- library_generation/cli/entry_point.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library_generation/cli/entry_point.py b/library_generation/cli/entry_point.py index eab6baff50..f04decd098 100644 --- a/library_generation/cli/entry_point.py +++ b/library_generation/cli/entry_point.py @@ -69,7 +69,8 @@ def main(ctx): default=".", show_default=True, help=""" - The path to which the api definition (proto and service yaml) resides. + The path to which the api definition (proto and service yaml) and its + dependencies resides. If not specified, the path is the current working directory. """, ) From 69e23dfa069633788bc47fb620beee48d3e1cf9f Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Thu, 19 Sep 2024 14:35:56 -0400 Subject: [PATCH 16/21] test missing dep --- library_generation/test/integration_tests.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index da88221d6e..67be9e30fa 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -207,6 +207,8 @@ def __copy_api_definition(cls, committish: str) -> str: f"{repo_dest}/grafeas", f"{api_temp_dir}/grafeas", dirs_exist_ok=True ) shutil.rmtree(repo_dest) + print(f"Removing api dependency in {api_temp_dir}/google/api...") + shutil.rmtree(f"{api_temp_dir}/google/api") return api_temp_dir @classmethod From f4f274857f1c99d2cafaa2eabbfa0e4b312565ae Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Thu, 19 Sep 2024 14:49:01 -0400 Subject: [PATCH 17/21] restore deps --- library_generation/test/integration_tests.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index 67be9e30fa..da88221d6e 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -207,8 +207,6 @@ def __copy_api_definition(cls, committish: str) -> str: f"{repo_dest}/grafeas", f"{api_temp_dir}/grafeas", dirs_exist_ok=True ) shutil.rmtree(repo_dest) - print(f"Removing api dependency in {api_temp_dir}/google/api...") - shutil.rmtree(f"{api_temp_dir}/google/api") return api_temp_dir @classmethod From bec08b03b81ebf26168aea65755e68c5a9658143 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Thu, 19 Sep 2024 14:52:05 -0400 Subject: [PATCH 18/21] update doc --- library_generation/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library_generation/README.md b/library_generation/README.md index deb8b1b80b..03729fb497 100644 --- a/library_generation/README.md +++ b/library_generation/README.md @@ -56,6 +56,8 @@ The default value is the current working directory when running the script. Note that you need not only the protos defined the service, but also the transitive dependencies of those protos. +Any missing dependencies will cause `File not found` error. + For example, if your service is defined in `example_service.proto` and it imports `google/api/annotations.proto`, you need the `annotations.proto` resides in a folder that has the exact structure of the import statement (`google/api` in this From 2d8ce358e570096e9ced9573f88f2a9c2946b46e Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Fri, 20 Sep 2024 08:10:17 -0400 Subject: [PATCH 19/21] change dir name --- .github/scripts/hermetic_library_generation.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/hermetic_library_generation.sh b/.github/scripts/hermetic_library_generation.sh index a162c44b67..221865cc19 100755 --- a/.github/scripts/hermetic_library_generation.sh +++ b/.github/scripts/hermetic_library_generation.sh @@ -98,12 +98,12 @@ docker run \ -u "$(id -u):$(id -g)" \ -v "$(pwd):${workspace_name}" \ -v "${m2_folder}":/home/.m2 \ - -v "${api_def_dir}:${workspace_name}/api" \ + -v "${api_def_dir}:${workspace_name}/googleapis" \ -e GENERATOR_VERSION="${image_tag}" \ gcr.io/cloud-devrel-public-resources/java-library-generation:"${image_tag}" \ --baseline-generation-config-path="${workspace_name}/${baseline_generation_config}" \ --current-generation-config-path="${workspace_name}/${generation_config}" \ - --api-definition-path="${workspace_name}/api" + --api-definition-path="${workspace_name}/googleapis" # remove api definition after generation rm -rf "${api_def_dir}" From b3ef95159563a7918475fffaac84f39d00126c85 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Fri, 20 Sep 2024 09:00:59 -0400 Subject: [PATCH 20/21] change doc --- library_generation/DEVELOPMENT.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/library_generation/DEVELOPMENT.md b/library_generation/DEVELOPMENT.md index 438ccb5794..f96255b4a0 100644 --- a/library_generation/DEVELOPMENT.md +++ b/library_generation/DEVELOPMENT.md @@ -155,7 +155,9 @@ To run the docker container on the google-cloud-java repo, you must run: docker run \ -u "$(id -u)":"$(id -g)" \ -v /path/to/google-cloud-java:/workspace \ - $(cat image-id) + -v /path/to/api-definition:/workspace/apis \ + $(cat image-id) \ + --api-definition-path=/workspace/apis ``` * `-u "$(id -u)":"$(id -g)"` makes docker run the container impersonating @@ -164,9 +166,11 @@ docker run \ * `-v /path/to/google-cloud-java:/workspace` maps the host machine's google-cloud-java folder to the /workspace folder. The image is configured to perform changes in this directory. - Note that this setup assumes the api definition resides in host machine's - google-cloud-java folder. + * `-v /path/to/api-definition:/workspace/apis` maps the host machine's + api-definition folder to /workspace/apis folder. * `$(cat image-id)` obtains the image ID created in the build step. + * `--api-definition-path=/workspace/apis` set the API definition path to + `/workspace/apis`. ## Debug the created containers If you are working on changing the way the containers are created, you may want From 5817ea924bdca4e92a1d57b2de4eaac7780939e3 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Fri, 20 Sep 2024 13:36:08 -0400 Subject: [PATCH 21/21] change to api_definitions_path --- .github/scripts/hermetic_library_generation.sh | 6 +++--- library_generation/DEVELOPMENT.md | 8 ++++---- library_generation/README.md | 6 +++--- library_generation/cli/entry_point.py | 14 +++++++------- library_generation/generate_repo.py | 6 +++--- .../test/cli/entry_point_unit_tests.py | 16 ++++++++-------- library_generation/test/integration_tests.py | 8 ++++---- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/.github/scripts/hermetic_library_generation.sh b/.github/scripts/hermetic_library_generation.sh index 221865cc19..2c5552f77d 100755 --- a/.github/scripts/hermetic_library_generation.sh +++ b/.github/scripts/hermetic_library_generation.sh @@ -84,7 +84,7 @@ git show "${target_branch}":"${generation_config}" > "${baseline_generation_conf # get .m2 folder so it's mapped into the docker container m2_folder=$(dirname "$(mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout)") -# download api definition from googleapis repository +# download api definitions from googleapis repository googleapis_commitish=$(grep googleapis_commitish "${generation_config}" | cut -d ":" -f 2 | xargs) api_def_dir=$(mktemp -d) git clone https://github.com/googleapis/googleapis.git "${api_def_dir}" @@ -103,9 +103,9 @@ docker run \ gcr.io/cloud-devrel-public-resources/java-library-generation:"${image_tag}" \ --baseline-generation-config-path="${workspace_name}/${baseline_generation_config}" \ --current-generation-config-path="${workspace_name}/${generation_config}" \ - --api-definition-path="${workspace_name}/googleapis" + --api-definitions-path="${workspace_name}/googleapis" -# remove api definition after generation +# remove api definitions after generation rm -rf "${api_def_dir}" # commit the change to the pull request. diff --git a/library_generation/DEVELOPMENT.md b/library_generation/DEVELOPMENT.md index f96255b4a0..cc893133ed 100644 --- a/library_generation/DEVELOPMENT.md +++ b/library_generation/DEVELOPMENT.md @@ -107,7 +107,7 @@ generate a GAPIC repository with a given api definition (proto, service yaml). For example, googleapis ``` git clone https://github.com/googleapis/googleapis -export api_definition_path="$(pwd)/googleapis" +export api_definitions_path="$(pwd)/googleapis" ``` ### Download the repo @@ -126,7 +126,7 @@ python -m pip install . ``` python cli/entry_point.py generate \ --repository-path="${path_to_repo}" \ - --api-definition-path="${api_definition_path}" + --api-definitions-path="${api_definitions_path}" ``` @@ -157,7 +157,7 @@ docker run \ -v /path/to/google-cloud-java:/workspace \ -v /path/to/api-definition:/workspace/apis \ $(cat image-id) \ - --api-definition-path=/workspace/apis + --api-definitions-path=/workspace/apis ``` * `-u "$(id -u)":"$(id -g)"` makes docker run the container impersonating @@ -169,7 +169,7 @@ docker run \ * `-v /path/to/api-definition:/workspace/apis` maps the host machine's api-definition folder to /workspace/apis folder. * `$(cat image-id)` obtains the image ID created in the build step. - * `--api-definition-path=/workspace/apis` set the API definition path to + * `--api-definitions-path=/workspace/apis` set the API definition path to `/workspace/apis`. ## Debug the created containers diff --git a/library_generation/README.md b/library_generation/README.md index 03729fb497..3496568288 100644 --- a/library_generation/README.md +++ b/library_generation/README.md @@ -48,7 +48,7 @@ right version for each library. Please refer [here](go/java-client-releasing#versionstxt-manifest) for more info of versions.txt. -### Api definition path (`api_definition_path`), optional +### Api definitions path (`api_definitions_path`), optional The path to where the api definition (proto, service yaml) resides. @@ -61,7 +61,7 @@ Any missing dependencies will cause `File not found` error. For example, if your service is defined in `example_service.proto` and it imports `google/api/annotations.proto`, you need the `annotations.proto` resides in a folder that has the exact structure of the import statement (`google/api` in this -case), and set `api_definition_path` to the path contains the root folder (`google` +case), and set `api_definitions_path` to the path contains the root folder (`google` in this case). ## Output of `entry_point.py` @@ -219,7 +219,7 @@ python library_generation/entry_point.py generate \ --baseline-generation-config-path=/path/to/baseline_config_file \ --current-generation-config-path=/path/to/current_config_file \ --repository-path=path/to/repository \ ---api-definition-path=path/to/api_definition +--api-definitions-path=path/to/api_definition ``` If you run `entry_point.py` with the example [configuration](#an-example-of-generation-configuration) shown above, the repository structure is: diff --git a/library_generation/cli/entry_point.py b/library_generation/cli/entry_point.py index f04decd098..e5055d8030 100644 --- a/library_generation/cli/entry_point.py +++ b/library_generation/cli/entry_point.py @@ -64,7 +64,7 @@ def main(ctx): """, ) @click.option( - "--api-definition-path", + "--api-definitions-path", type=str, default=".", show_default=True, @@ -78,7 +78,7 @@ def generate( baseline_generation_config_path: str, current_generation_config_path: str, repository_path: str, - api_definition_path: str, + api_definitions_path: str, ): """ Compare baseline generation config and current generation config and @@ -105,7 +105,7 @@ def generate( baseline_generation_config_path=baseline_generation_config_path, current_generation_config_path=current_generation_config_path, repository_path=repository_path, - api_definition_path=api_definition_path, + api_definitions_path=api_definitions_path, ) @@ -113,7 +113,7 @@ def __generate_repo_and_pr_description_impl( baseline_generation_config_path: str, current_generation_config_path: str, repository_path: str, - api_definition_path: str, + api_definitions_path: str, ): """ Implementation method for generate(). @@ -145,7 +145,7 @@ def __generate_repo_and_pr_description_impl( current_generation_config_path = os.path.abspath(current_generation_config_path) repository_path = os.path.abspath(repository_path) - api_definition_path = os.path.abspath(api_definition_path) + api_definitions_path = os.path.abspath(api_definitions_path) if not baseline_generation_config_path: # Execute full generation based on current_generation_config if # baseline_generation_config is not specified. @@ -153,7 +153,7 @@ def __generate_repo_and_pr_description_impl( generate_from_yaml( config=from_yaml(current_generation_config_path), repository_path=repository_path, - api_definition_path=api_definition_path, + api_definitions_path=api_definitions_path, ) return @@ -173,7 +173,7 @@ def __generate_repo_and_pr_description_impl( generate_from_yaml( config=config_change.current_config, repository_path=repository_path, - api_definition_path=api_definition_path, + api_definitions_path=api_definitions_path, target_library_names=target_library_names, ) generate_pr_descriptions( diff --git a/library_generation/generate_repo.py b/library_generation/generate_repo.py index 2a2329840b..cb44fadcbe 100755 --- a/library_generation/generate_repo.py +++ b/library_generation/generate_repo.py @@ -25,7 +25,7 @@ def generate_from_yaml( config: GenerationConfig, repository_path: str, - api_definition_path: str, + api_definitions_path: str, target_library_names: list[str] = None, ) -> None: """ @@ -35,7 +35,7 @@ def generate_from_yaml( :param config: a GenerationConfig object. :param repository_path: The repository path to which the generated files will be sent. - :param api_definition_path: The path to where the api definition resides. + :param api_definitions_path: The path to where the api definition resides. :param target_library_names: a list of libraries to be generated. If specified, only the library whose library_name is in target_library_names will be generated. @@ -49,7 +49,7 @@ def generate_from_yaml( gen_config=config, library_config=target_libraries, repo_path=repository_path ) # copy api definition to output folder. - shutil.copytree(api_definition_path, repo_config.output_folder, dirs_exist_ok=True) + shutil.copytree(api_definitions_path, repo_config.output_folder, dirs_exist_ok=True) for library_path, library in repo_config.get_libraries().items(): print(f"generating library {library.get_library_name()}") diff --git a/library_generation/test/cli/entry_point_unit_tests.py b/library_generation/test/cli/entry_point_unit_tests.py index efaa66af90..171be31236 100644 --- a/library_generation/test/cli/entry_point_unit_tests.py +++ b/library_generation/test/cli/entry_point_unit_tests.py @@ -105,12 +105,12 @@ def test_generate_non_monorepo_without_changes_triggers_full_generation( baseline_generation_config_path=config_path, current_generation_config_path=config_path, repository_path=".", - api_definition_path=".", + api_definitions_path=".", ) generate_from_yaml.assert_called_with( config=ANY, repository_path=ANY, - api_definition_path=ANY, + api_definitions_path=ANY, target_library_names=None, ) @@ -138,12 +138,12 @@ def test_generate_non_monorepo_with_changes_triggers_full_generation( baseline_generation_config_path=baseline_config_path, current_generation_config_path=current_config_path, repository_path=".", - api_definition_path=".", + api_definitions_path=".", ) generate_from_yaml.assert_called_with( config=ANY, repository_path=ANY, - api_definition_path=ANY, + api_definitions_path=ANY, target_library_names=None, ) @@ -168,12 +168,12 @@ def test_generate_monorepo_with_common_protos_triggers_full_generation( baseline_generation_config_path=config_path, current_generation_config_path=config_path, repository_path=".", - api_definition_path=".", + api_definitions_path=".", ) generate_from_yaml.assert_called_with( config=ANY, repository_path=ANY, - api_definition_path=ANY, + api_definitions_path=ANY, target_library_names=None, ) @@ -199,11 +199,11 @@ def test_generate_monorepo_without_common_protos_does_not_trigger_full_generatio baseline_generation_config_path=config_path, current_generation_config_path=config_path, repository_path=".", - api_definition_path=".", + api_definitions_path=".", ) generate_from_yaml.assert_called_with( config=ANY, repository_path=ANY, - api_definition_path=ANY, + api_definitions_path=ANY, target_library_names=[], ) diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index da88221d6e..c5f8221cc9 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -71,7 +71,7 @@ def setUp(cls) -> None: os.makedirs(f"{golden_dir}", exist_ok=True) def test_entry_point_running_in_container(self): - api_definition_path = self.__copy_api_definition(googleapis_commitish) + api_definitions_path = self.__copy_api_definition(googleapis_commitish) config_files = self.__get_config_files(config_dir) for repo, config_file in config_files: config = from_yaml(config_file) @@ -92,7 +92,7 @@ def test_entry_point_running_in_container(self): config_location=config_location, baseline_config=baseline_config_name, current_config=current_config_name, - api_definition=api_definition_path, + api_definition=api_definitions_path, ) # 4. compare generation result with golden files print( @@ -191,7 +191,7 @@ def test_entry_point_running_in_container(self): ) print(" PR description comparison succeed.") self.__remove_generated_files() - shutil.rmtree(api_definition_path) + shutil.rmtree(api_definitions_path) @classmethod def __copy_api_definition(cls, committish: str) -> str: @@ -324,7 +324,7 @@ def __run_entry_point_in_docker_container( image_tag, f"--baseline-generation-config-path=/workspace/config/{baseline_config}", f"--current-generation-config-path=/workspace/config/{current_config}", - f"--api-definition-path=/workspace/api", + f"--api-definitions-path=/workspace/api", ], )