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
3233class 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 )
0 commit comments