Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions compatibility_lib/compatibility_lib/compatibility_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
_DATASET_NAME = 'compatibility_checker'
_SELF_COMPATIBILITY_STATUS_TABLE_NAME = 'self_compatibility_status'
_PAIRWISE_COMPATIBILITY_STATUS_TABLE_NAME = 'pairwise_compatibility_status'
_RELEASE_TIME_FOR_DEPENDENCIES_TABLE_NAME = 'release_time_for_dependencies'


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

Expand Down Expand Up @@ -136,6 +139,12 @@ def __init__(self):
self._pairwise_table = self._client.get_table(dataset_ref.table(
_PAIRWISE_COMPATIBILITY_STATUS_TABLE_NAME))

self._release_time_table_id = (
'{}.{}'.format(
_DATASET_NAME, _RELEASE_TIME_FOR_DEPENDENCIES_TABLE_NAME))
self._release_time_table = self._client.get_table(dataset_ref.table(
_RELEASE_TIME_FOR_DEPENDENCIES_TABLE_NAME))

@staticmethod
def _row_to_compatibility_status(packages: Iterable[package.Package],
row: table.Row) -> \
Expand Down Expand Up @@ -168,6 +177,28 @@ def _compatibility_status_to_row(
row['install_name_lower'], row['install_name_higher'] = names
return row

@staticmethod
def _compatibility_status_to_release_time_row(
cs: CompatibilityResult) -> List[Mapping[str, Any]]:
"""Converts a CompatibilityResult into a dict which is a row for
release time table."""
if len(cs.packages) != 1 or cs.dependency_info is None:
return []
install_name = cs.packages[0].install_name
dependency_info = cs.dependency_info
rows = []

for pkg, version_info in dependency_info.items():
row = {
'install_name': install_name,
'dep_name': pkg,
}
row.update(version_info)
row['timestamp'] = row.pop('current_time')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to pop this? Can't you just use the value?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for changing the key name from current_time to timestamp in the dict, as current_time is a reserved variable in bigquery.

rows.append(row)

return rows

@staticmethod
def _filter_older_versions(crs: Iterable[CompatibilityResult]) \
-> Iterable[CompatibilityResult]:
Expand Down Expand Up @@ -350,8 +381,10 @@ def save_compatibility_statuses(
if any(cs for cs in compatibility_statuses
if len(cs.packages) not in [1, 2]):
raise ValueError('CompatibilityResult must have 1 or 2 packages')

rows = [self._compatibility_status_to_row(s) for s in
compatibility_statuses]

self_rows = [r for r in rows if 'install_name' in r]
pair_rows = [r for r in rows if 'install_name' not in r]
if self_rows:
Expand All @@ -362,3 +395,16 @@ def save_compatibility_statuses(
self._client.insert_rows(
self._pairwise_table,
pair_rows)

release_time_rows = {}
for cs in compatibility_statuses:
if len(cs.packages) == 1:
install_name = cs.packages[0].install_name
row = self._compatibility_status_to_release_time_row(cs)
if row:
release_time_rows[install_name] = row

for row in release_time_rows.values():
self._client.insert_rows(
self._release_time_table,
row)
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ def _result_dict_to_compatibility_result(results, python_version):

def write_to_status_table():
# Write self compatibility status to BigQuery
self_res_list = []
for py_version in [PY2, PY3]:
results = checker.get_self_compatibility(py_version)
res_list = _result_dict_to_compatibility_result(results, py_version)
store.save_compatibility_statuses(res_list)
self_res_list.extend(res_list)

store.save_compatibility_statuses(self_res_list)

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