Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: googleapis/sdk-platform-java
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cd1691aa6ecb11260598e286562480777ab68560
Choose a base ref
..
head repository: googleapis/sdk-platform-java
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: df957ce9e3cf562e79f5c7c9f338f8cd622a6a7f
Choose a head ref
Showing with 34 additions and 5 deletions.
  1. +1 −0 CHANGELOG.md
  2. +15 −0 library_generation/test/utils/generation_config_comparator_unit_tests.py
  3. +18 −5 library_generation/utils/generation_config_comparator.py
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@

### Bug Fixes

* do not populate repo level change while removing library ([#2740](https://github.com/googleapis/sdk-platform-java/issues/2740)) ([43e62b9](https://github.com/googleapis/sdk-platform-java/commit/43e62b998958abd4ca96b83800380c9696ff693f))
* only append `.api.grpc` suffix to group id if the artifact id starts with `proto-` or `grpc-` ([#2731](https://github.com/googleapis/sdk-platform-java/issues/2731)) ([8e87b2e](https://github.com/googleapis/sdk-platform-java/commit/8e87b2e9a28a1797efb2eea531d25094b4438e0d))


Original file line number Diff line number Diff line change
@@ -178,6 +178,21 @@ def test_compare_config_library_addition(self):
config_change = result.change_to_libraries[ChangeType.LIBRARIES_ADDITION][0]
self.assertEqual("new_library", config_change.library_name)

def test_compare_config_library_removal_does_not_have_repo_or_library_level_change(
self,
):
self.current_config.libraries = []
result = compare_config(
baseline_config=self.baseline_config,
current_config=self.current_config,
)
self.assertTrue(
len(result.change_to_libraries[ChangeType.REPO_LEVEL_CHANGE]) == 0
)
self.assertTrue(
len(result.change_to_libraries[ChangeType.LIBRARY_LEVEL_CHANGE]) == 0
)

def test_compare_config_api_shortname_update_without_library_name(self):
self.current_config.libraries[0].api_shortname = "new_api_shortname"
result = compare_config(
23 changes: 18 additions & 5 deletions library_generation/utils/generation_config_comparator.py
Original file line number Diff line number Diff line change
@@ -38,8 +38,17 @@ def compare_config(
:return: a ConfigChange objects.
"""
diff = defaultdict(list[LibraryChange])
baseline_params = __convert_params_to_sorted_list(baseline_config)
current_params = __convert_params_to_sorted_list(current_config)
# Exclude `libraries` because an empty library list (e.g., by library
# removal) will cause this parameter appears in the sorted param list,
# which leads to unequal list of parameters.
excluded_params = {"libraries"}
baseline_params = __convert_params_to_sorted_list(
obj=baseline_config, excluded_params=excluded_params
)
current_params = __convert_params_to_sorted_list(
obj=current_config, excluded_params=excluded_params
)

for baseline_param, current_param in zip(baseline_params, current_params):
if baseline_param == current_param:
continue
@@ -216,7 +225,7 @@ def __compare_gapic_configs(
diff[ChangeType.GAPIC_ADDITION].append(config_change)


def __convert_params_to_sorted_list(obj: Any) -> List[tuple]:
def __convert_params_to_sorted_list(obj: Any, excluded_params=None) -> List[tuple]:
"""
Convert the parameter and its value of a given object to a sorted list of
tuples.
@@ -230,13 +239,17 @@ def __convert_params_to_sorted_list(obj: Any) -> List[tuple]:
Note that built-in params, e.g., __str__, and methods will be skipped.
:param obj: an object
:param obj: an object.
:param excluded_params: excluded params.
:return: a sorted list of tuples.
"""
if excluded_params is None:
excluded_params = set()
param_and_values = []
for param, value in vars(obj).items():
if (
param.startswith("__") # skip built-in params
param in excluded_params
or param.startswith("__") # skip built-in params
or callable(getattr(obj, param)) # skip methods
# skip if the type of param is not one of the following types
# 1. str