Skip to content
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: add generation config comparator #2587

Merged
merged 25 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7f91d91
feat: add a generation config comparator
JoeWang1127 Mar 15, 2024
e5aae8e
compare library configs
JoeWang1127 Mar 16, 2024
7110bb3
Merge branch 'main' into feat/config-comparator
JoeWang1127 Mar 16, 2024
7cb2e97
code refactor
JoeWang1127 Mar 17, 2024
a8b1b26
add proto_path removal or addition change
JoeWang1127 Mar 17, 2024
218e431
change to HashLibrary
JoeWang1127 Mar 17, 2024
15e0db7
use object, rather than file path in comparator interface
JoeWang1127 Mar 17, 2024
b876354
add unit tests
JoeWang1127 Mar 17, 2024
5348539
add setUp method in ut
JoeWang1127 Mar 17, 2024
8e6b1c1
add unit tests against repo level changes
JoeWang1127 Mar 17, 2024
4f0f2c1
add unit tests against library parameters
JoeWang1127 Mar 17, 2024
e8b2d6b
add unit tests against versioned proto_path
JoeWang1127 Mar 17, 2024
e5f7a5e
restore gapic_config
JoeWang1127 Mar 17, 2024
2d6b13b
add comments
JoeWang1127 Mar 18, 2024
2dc41b3
code refactor
JoeWang1127 Mar 18, 2024
6fba2ad
change type
JoeWang1127 Mar 18, 2024
cda24a1
change enum types
JoeWang1127 Mar 19, 2024
af85a4f
move get_library_name method to LibraryConfig
JoeWang1127 Mar 19, 2024
989da47
fix integration tests
JoeWang1127 Mar 19, 2024
d3df205
Merge branch 'main' into feat/config-comparator
JoeWang1127 Mar 19, 2024
376015d
comment out library removal and gapic removal type
JoeWang1127 Mar 20, 2024
70e0fe8
raise an error if api_shortname is changed but library_name remains t…
JoeWang1127 Mar 20, 2024
42b5b03
use built-in method, `vars`, to list parameters of an object
JoeWang1127 Mar 20, 2024
4890786
Merge branch 'main' into feat/config-comparator
JoeWang1127 Mar 20, 2024
33b8c47
Merge branch 'main' into feat/config-comparator
JoeWang1127 Mar 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions library_generation/model/library_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
from hashlib import sha1

from typing import List, Optional
from library_generation.model.gapic_config import GapicConfig
Expand Down Expand Up @@ -71,3 +72,70 @@ def __init__(
self.cloud_api = cloud_api
self.requires_billing = requires_billing
self.extra_versioned_modules = extra_versioned_modules

def get_library_name(self) -> str:
"""
Return the library name of a given LibraryConfig object
:return: the library name
"""
return self.library_name if self.library_name else self.api_shortname

def __eq__(self, other):
return (
self.api_shortname == other.api_shortname
and self.api_description == other.api_description
and self.name_pretty == other.name_pretty
and self.product_documentation == other.product_documentation
and self.gapic_configs == other.gapic_configs
and self.library_type == other.library_type
and self.release_level == other.release_level
and self.api_id == other.api_id
and self.api_reference == other.api_reference
and self.codeowner_team == other.codeowner_team
and self.excluded_dependencies == other.excluded_dependencies
and self.excluded_poms == other.excluded_poms
and self.client_documentation == other.client_documentation
and self.distribution_name == other.distribution_name
and self.googleapis_commitish == other.googleapis_commitish
and self.group_id == other.group_id
and self.issue_tracker == other.issue_tracker
and self.library_name == other.library_name
and self.rest_documentation == other.rest_documentation
and self.rpc_documentation == other.rpc_documentation
and self.cloud_api == other.cloud_api
and self.requires_billing == other.requires_billing
and self.extra_versioned_modules == other.extra_versioned_modules
)

def __hash__(self):
m = sha1()
m.update(
str(
[
self.api_shortname,
self.api_description,
self.name_pretty,
self.product_documentation,
self.library_type,
self.release_level,
self.api_id,
self.api_reference,
self.codeowner_team,
self.excluded_dependencies,
self.excluded_poms,
self.client_documentation,
self.distribution_name,
self.googleapis_commitish,
self.group_id,
self.issue_tracker,
self.library_name,
self.rest_documentation,
self.rpc_documentation,
self.cloud_api,
self.requires_billing,
self.extra_versioned_modules,
]
+ [config.proto_path for config in self.gapic_configs]
).encode("utf-8")
)
return int(m.hexdigest(), 16)
10 changes: 5 additions & 5 deletions library_generation/test/integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from library_generation.model.generation_config import from_yaml, GenerationConfig
from library_generation.test.compare_poms import compare_xml
from library_generation.utilities import (
get_library_name,
sh_util as shell_call,
run_process_and_print_output,
)
Expand Down Expand Up @@ -214,7 +213,7 @@ def __pull_repo_to(cls, default_dest: Path, repo: str, committish: str) -> str:
def __get_library_names_from_config(cls, config: GenerationConfig) -> List[str]:
library_names = []
for library in config.libraries:
library_names.append(f"java-{get_library_name(library)}")
library_names.append(f"java-{library.get_library_name()}")

return library_names

Expand Down Expand Up @@ -248,21 +247,22 @@ def __load_json_to_sorted_list(cls, path: str) -> List[tuple]:

@classmethod
def __recursive_diff_files(
self,
cls,
dcmp: dircmp,
diff_files: List[str],
left_only: List[str],
right_only: List[str],
dirname: str = "",
):
"""
recursively compares two subdirectories. The found differences are passed to three expected list references
Recursively compares two subdirectories. The found differences are
passed to three expected list references.
"""
append_dirname = lambda d: dirname + d
diff_files.extend(map(append_dirname, dcmp.diff_files))
left_only.extend(map(append_dirname, dcmp.left_only))
right_only.extend(map(append_dirname, dcmp.right_only))
for sub_dirname, sub_dcmp in dcmp.subdirs.items():
self.__recursive_diff_files(
cls.__recursive_diff_files(
sub_dcmp, diff_files, left_only, right_only, dirname + sub_dirname + "/"
)
Empty file.
39 changes: 39 additions & 0 deletions library_generation/test/model/library_config_unit_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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 unittest

from library_generation.model.library_config import LibraryConfig


class LibraryConfigTest(unittest.TestCase):
def test_get_library_returns_library_name(self):
library = LibraryConfig(
api_shortname="secret",
name_pretty="",
product_documentation="",
api_description="",
gapic_configs=list(),
library_name="secretmanager",
)
self.assertEqual("secretmanager", library.get_library_name())

def test_get_library_returns_api_shortname(self):
library = LibraryConfig(
api_shortname="secret",
name_pretty="",
product_documentation="",
api_description="",
gapic_configs=list(),
)
self.assertEqual("secret", library.get_library_name())
6 changes: 0 additions & 6 deletions library_generation/test/utilities_unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,6 @@ def test_remove_version_from_returns_self(self):
"google/cloud/aiplatform", util.remove_version_from(proto_path)
)

def test_get_library_returns_library_name(self):
self.assertEqual("bare-metal-solution", util.get_library_name(library_1))

def test_get_library_returns_api_shortname(self):
self.assertEqual("secretmanager", util.get_library_name(library_2))

def test_generate_prerequisite_files_non_monorepo_success(self):
library_path = self.__setup_prerequisite_files(
num_libraries=1, library_type="GAPIC_COMBO"
Expand Down
Loading
Loading