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

Commit ad58a20

Browse files
authored
Record release time data into bigquery (#46)
1 parent 5927d04 commit ad58a20

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

compatibility_lib/compatibility_lib/compatibility_store.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
_DATASET_NAME = 'compatibility_checker'
2828
_SELF_COMPATIBILITY_STATUS_TABLE_NAME = 'self_compatibility_status'
2929
_PAIRWISE_COMPATIBILITY_STATUS_TABLE_NAME = 'pairwise_compatibility_status'
30+
_RELEASE_TIME_FOR_DEPENDENCIES_TABLE_NAME = 'release_time_for_dependencies'
3031

3132

3233
class Status(enum.Enum):
@@ -46,6 +47,8 @@ class CompatibilityResult:
4647
status: The overall result of the compatibility check.
4748
details: A text description of the compatibility check. Will be None
4849
if the check succeeded.
50+
dependency_info: The dict contains the dependency version info and
51+
release time info.
4952
timestamp: The time at which the compatibility check was performed.
5053
"""
5154

@@ -136,6 +139,12 @@ def __init__(self):
136139
self._pairwise_table = self._client.get_table(dataset_ref.table(
137140
_PAIRWISE_COMPATIBILITY_STATUS_TABLE_NAME))
138141

142+
self._release_time_table_id = (
143+
'{}.{}'.format(
144+
_DATASET_NAME, _RELEASE_TIME_FOR_DEPENDENCIES_TABLE_NAME))
145+
self._release_time_table = self._client.get_table(dataset_ref.table(
146+
_RELEASE_TIME_FOR_DEPENDENCIES_TABLE_NAME))
147+
139148
@staticmethod
140149
def _row_to_compatibility_status(packages: Iterable[package.Package],
141150
row: table.Row) -> \
@@ -168,6 +177,28 @@ def _compatibility_status_to_row(
168177
row['install_name_lower'], row['install_name_higher'] = names
169178
return row
170179

180+
@staticmethod
181+
def _compatibility_status_to_release_time_row(
182+
cs: CompatibilityResult) -> List[Mapping[str, Any]]:
183+
"""Converts a CompatibilityResult into a dict which is a row for
184+
release time table."""
185+
if len(cs.packages) != 1 or cs.dependency_info is None:
186+
return []
187+
install_name = cs.packages[0].install_name
188+
dependency_info = cs.dependency_info
189+
rows = []
190+
191+
for pkg, version_info in dependency_info.items():
192+
row = {
193+
'install_name': install_name,
194+
'dep_name': pkg,
195+
}
196+
row.update(version_info)
197+
row['timestamp'] = row.pop('current_time')
198+
rows.append(row)
199+
200+
return rows
201+
171202
@staticmethod
172203
def _filter_older_versions(crs: Iterable[CompatibilityResult]) \
173204
-> Iterable[CompatibilityResult]:
@@ -350,8 +381,10 @@ def save_compatibility_statuses(
350381
if any(cs for cs in compatibility_statuses
351382
if len(cs.packages) not in [1, 2]):
352383
raise ValueError('CompatibilityResult must have 1 or 2 packages')
384+
353385
rows = [self._compatibility_status_to_row(s) for s in
354386
compatibility_statuses]
387+
355388
self_rows = [r for r in rows if 'install_name' in r]
356389
pair_rows = [r for r in rows if 'install_name' not in r]
357390
if self_rows:
@@ -362,3 +395,16 @@ def save_compatibility_statuses(
362395
self._client.insert_rows(
363396
self._pairwise_table,
364397
pair_rows)
398+
399+
release_time_rows = {}
400+
for cs in compatibility_statuses:
401+
if len(cs.packages) == 1:
402+
install_name = cs.packages[0].install_name
403+
row = self._compatibility_status_to_release_time_row(cs)
404+
if row:
405+
release_time_rows[install_name] = row
406+
407+
for row in release_time_rows.values():
408+
self._client.insert_rows(
409+
self._release_time_table,
410+
row)

compatibility_lib/compatibility_lib/get_compatibility_data.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,13 @@ def _result_dict_to_compatibility_result(results, python_version):
5454

5555
def write_to_status_table():
5656
# Write self compatibility status to BigQuery
57+
self_res_list = []
5758
for py_version in [PY2, PY3]:
5859
results = checker.get_self_compatibility(py_version)
5960
res_list = _result_dict_to_compatibility_result(results, py_version)
60-
store.save_compatibility_statuses(res_list)
61+
self_res_list.extend(res_list)
62+
63+
store.save_compatibility_statuses(self_res_list)
6164

6265
# Write pairwise compatibility status to BigQuery
6366
for py_version in [PY2, PY3]:

0 commit comments

Comments
 (0)