Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.

Commit 7da1852

Browse files
authored
Use the latest version for the dependencies (#157)
1 parent 70e7eb8 commit 7da1852

2 files changed

Lines changed: 85 additions & 1 deletion

File tree

compatibility_lib/compatibility_lib/compatibility_store.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,12 @@ def save_compatibility_statuses(
407407
for cs in compatibility_statuses:
408408
if len(cs.packages) == 1:
409409
install_name = cs.packages[0].install_name
410+
# Only store the dep info for latest version of the package
411+
# being checked. e.g. pip install apache-beam will have
412+
# different version installed in py2/3.
413+
if not self._should_update_dep_info(
414+
cs, release_time_rows.get(install_name)):
415+
continue
410416
row = self._compatibility_status_to_release_time_row(cs)
411417
if row:
412418
release_time_rows[install_name] = row
@@ -416,6 +422,25 @@ def save_compatibility_statuses(
416422
self._release_time_table,
417423
row)
418424

425+
def _should_update_dep_info(self, cs, dep_info_stored):
426+
"""Return True if the stored version is behind latest version."""
427+
if dep_info_stored is None:
428+
return True
429+
430+
install_name = cs.packages[0].install_name
431+
install_name_sanitized = install_name.split('[')[0]
432+
installed_version = cs.dependency_info[
433+
install_name_sanitized]['installed_version']
434+
435+
installed_version_stored = '0'
436+
for row in dep_info_stored:
437+
if row['install_name'] == install_name \
438+
and row['dep_name'] == install_name_sanitized:
439+
installed_version_stored = row['installed_version']
440+
break
441+
442+
return True if installed_version > installed_version_stored else False
443+
419444
@retrying.retry(stop_max_attempt_number=7,
420445
wait_fixed=2000)
421446
def get_dependency_info(self, package_name):

compatibility_lib/compatibility_lib/test_compatibility_store.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
PACKAGE_1 = package.Package("package1")
2626
PACKAGE_2 = package.Package("package2")
2727
PACKAGE_3 = package.Package("package3")
28-
PACKAGE_4 = package.Package("package4")
28+
PACKAGE_4 = package.Package("package4[gcp]")
2929

3030

3131
class TestCompatibilityResult(unittest.TestCase):
@@ -414,6 +414,65 @@ def MockClient(project=None):
414414
mock_client.insert_rows.assert_called_with(
415415
store._release_time_table, [row_release_time])
416416

417+
def test_save_compatibility_statuses_release_time_for_latest(self):
418+
mock_client = mock.Mock()
419+
packages = [PACKAGE_4]
420+
timestamp = '2018-07-17 03:01:06.11693 UTC'
421+
status = compatibility_store.Status.SUCCESS
422+
comp_status_py2 = mock.Mock(
423+
packages=packages,
424+
python_major_version='2',
425+
status=status,
426+
details=None,
427+
dependency_info={'package4': {
428+
'installed_version': '2.7.0',
429+
'installed_version_time': '2018-05-12T16:26:31',
430+
'latest_version': '2.7.0',
431+
'current_time': '2018-07-13T17:11:29.140608',
432+
'latest_version_time': '2018-05-12T16:26:31',
433+
'is_latest': True,
434+
}},
435+
timestamp=timestamp)
436+
comp_status_py3 = mock.Mock(
437+
packages=packages,
438+
python_major_version='3',
439+
status=status,
440+
details=None,
441+
dependency_info={'package4': {
442+
'installed_version': '2.2.0',
443+
'installed_version_time': '2018-05-12T16:26:31',
444+
'latest_version': '2.7.0',
445+
'current_time': '2018-07-13T17:11:29.140608',
446+
'latest_version_time': '2018-05-12T16:26:31',
447+
'is_latest': False,
448+
}},
449+
timestamp=timestamp)
450+
row_release_time = {
451+
'install_name': 'package4[gcp]',
452+
'dep_name': 'package4',
453+
'installed_version': '2.7.0',
454+
'installed_version_time': '2018-05-12T16:26:31',
455+
'latest_version': '2.7.0',
456+
'timestamp': '2018-07-13T17:11:29.140608',
457+
'latest_version_time': '2018-05-12T16:26:31',
458+
'is_latest': True,
459+
}
460+
461+
def MockClient(project=None):
462+
return mock_client
463+
464+
patch_client = mock.patch(
465+
'compatibility_lib.compatibility_store.bigquery.Client',
466+
MockClient)
467+
468+
with patch_client:
469+
store = compatibility_store.CompatibilityStore()
470+
store.save_compatibility_statuses(
471+
[comp_status_py2, comp_status_py3])
472+
473+
mock_client.insert_rows.assert_called_with(
474+
store._release_time_table, [row_release_time])
475+
417476

418477
class MockClient(object):
419478

0 commit comments

Comments
 (0)