From cdb72d5c51634a91fa9e242dc7e965eeb4d4bdf9 Mon Sep 17 00:00:00 2001 From: Angela Li Date: Thu, 11 Oct 2018 13:28:26 -0700 Subject: [PATCH 1/3] Use the latest version for the dependencies --- .../compatibility_lib/compatibility_store.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/compatibility_lib/compatibility_lib/compatibility_store.py b/compatibility_lib/compatibility_lib/compatibility_store.py index 776c4d75..e48c8229 100644 --- a/compatibility_lib/compatibility_lib/compatibility_store.py +++ b/compatibility_lib/compatibility_lib/compatibility_store.py @@ -407,6 +407,12 @@ def save_compatibility_statuses( for cs in compatibility_statuses: if len(cs.packages) == 1: install_name = cs.packages[0].install_name + # Only store the dep info for latest version of the package + # being checked. e.g. pip install apache-beam will have + # different version installed in py2/3. + if not self._should_update_dep_info( + cs, release_time_rows.get(install_name)): + continue row = self._compatibility_status_to_release_time_row(cs) if row: release_time_rows[install_name] = row @@ -416,6 +422,26 @@ def save_compatibility_statuses( self._release_time_table, row) + def _should_update_dep_info(self, cs, dep_info_stored): + """Return True if the stored version is behind latest version.""" + if dep_info_stored is None: + return True + + install_name = cs.packages[0].install_name + install_name_sanitized = install_name.split('[')[0] \ + if '[' in install_name else install_name + installed_version = cs.dependency_info[ + install_name_sanitized]['installed_version'] + + installed_version_stored = '0' + for row in dep_info_stored: + if row['install_name'] == install_name \ + and row['dep_name'] == install_name_sanitized: + installed_version_stored = row['installed_version'] + break + + return True if installed_version > installed_version_stored else False + @retrying.retry(stop_max_attempt_number=7, wait_fixed=2000) def get_dependency_info(self, package_name): From 17d5eae8bd0061a84f74e99065b05a48afbba17b Mon Sep 17 00:00:00 2001 From: Angela Li Date: Thu, 11 Oct 2018 13:44:24 -0700 Subject: [PATCH 2/3] add test --- .../test_compatibility_store.py | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/compatibility_lib/compatibility_lib/test_compatibility_store.py b/compatibility_lib/compatibility_lib/test_compatibility_store.py index 3d38ba74..d27ad4f3 100644 --- a/compatibility_lib/compatibility_lib/test_compatibility_store.py +++ b/compatibility_lib/compatibility_lib/test_compatibility_store.py @@ -25,7 +25,7 @@ PACKAGE_1 = package.Package("package1") PACKAGE_2 = package.Package("package2") PACKAGE_3 = package.Package("package3") -PACKAGE_4 = package.Package("package4") +PACKAGE_4 = package.Package("package4[gcp]") class TestCompatibilityResult(unittest.TestCase): @@ -414,6 +414,65 @@ def MockClient(project=None): mock_client.insert_rows.assert_called_with( store._release_time_table, [row_release_time]) + def test_save_compatibility_statuses_release_time_for_latest(self): + mock_client = mock.Mock() + packages = [PACKAGE_4] + timestamp = '2018-07-17 03:01:06.11693 UTC' + status = compatibility_store.Status.SUCCESS + comp_status_py2 = mock.Mock( + packages=packages, + python_major_version='2', + status=status, + details=None, + dependency_info={'package4': { + 'installed_version': '2.7.0', + 'installed_version_time': '2018-05-12T16:26:31', + 'latest_version': '2.7.0', + 'current_time': '2018-07-13T17:11:29.140608', + 'latest_version_time': '2018-05-12T16:26:31', + 'is_latest': True, + }}, + timestamp=timestamp) + comp_status_py3 = mock.Mock( + packages=packages, + python_major_version='3', + status=status, + details=None, + dependency_info={'package4': { + 'installed_version': '2.2.0', + 'installed_version_time': '2018-05-12T16:26:31', + 'latest_version': '2.7.0', + 'current_time': '2018-07-13T17:11:29.140608', + 'latest_version_time': '2018-05-12T16:26:31', + 'is_latest': False, + }}, + timestamp=timestamp) + row_release_time = { + 'install_name': 'package4[gcp]', + 'dep_name': 'package4', + 'installed_version': '2.7.0', + 'installed_version_time': '2018-05-12T16:26:31', + 'latest_version': '2.7.0', + 'timestamp': '2018-07-13T17:11:29.140608', + 'latest_version_time': '2018-05-12T16:26:31', + 'is_latest': True, + } + + def MockClient(project=None): + return mock_client + + patch_client = mock.patch( + 'compatibility_lib.compatibility_store.bigquery.Client', + MockClient) + + with patch_client: + store = compatibility_store.CompatibilityStore() + store.save_compatibility_statuses( + [comp_status_py2, comp_status_py3]) + + mock_client.insert_rows.assert_called_with( + store._release_time_table, [row_release_time]) + class MockClient(object): From ff14656d1b78c923e19fdd4f66da8bcb157dd3f9 Mon Sep 17 00:00:00 2001 From: Angela Li Date: Thu, 11 Oct 2018 16:17:16 -0700 Subject: [PATCH 3/3] fix --- compatibility_lib/compatibility_lib/compatibility_store.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compatibility_lib/compatibility_lib/compatibility_store.py b/compatibility_lib/compatibility_lib/compatibility_store.py index e48c8229..c13ffa79 100644 --- a/compatibility_lib/compatibility_lib/compatibility_store.py +++ b/compatibility_lib/compatibility_lib/compatibility_store.py @@ -428,8 +428,7 @@ def _should_update_dep_info(self, cs, dep_info_stored): return True install_name = cs.packages[0].install_name - install_name_sanitized = install_name.split('[')[0] \ - if '[' in install_name else install_name + install_name_sanitized = install_name.split('[')[0] installed_version = cs.dependency_info[ install_name_sanitized]['installed_version']