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

Commit ec87a23

Browse files
authored
Make the compatibility_lib externally usable (#118)
1 parent d61de7e commit ec87a23

5 files changed

Lines changed: 17 additions & 21 deletions

File tree

compatibility_lib/compatibility_lib/compatibility_store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ def timestamp(self, timestamp: datetime.datetime):
123123
class CompatibilityStore:
124124
"""Storage for package compatibility information."""
125125

126-
def __init__(self):
127-
self._client = bigquery.Client()
126+
def __init__(self, project_id=None):
127+
self._client = bigquery.Client(project=project_id)
128128
dataset_ref = self._client.dataset(_DATASET_NAME)
129129

130130
self._self_table_id = (

compatibility_lib/compatibility_lib/dependency_highlighter.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ def __init__(self, py_version=None, checker=None, store=None):
9292
if checker is None:
9393
checker = compatibility_checker.CompatibilityChecker()
9494

95-
if store is None:
96-
store = compatibility_store.CompatibilityStore()
97-
9895
self.py_version = py_version
9996
self._checker = checker
10097
self._store = store

compatibility_lib/compatibility_lib/deprecated_dep_finder.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ def __init__(self,
4242
if checker is None:
4343
checker = compatibility_checker.CompatibilityChecker()
4444

45-
if store is None:
46-
store = compatibility_store.CompatibilityStore()
47-
4845
self.max_workers = max_workers
4946
self.py_version = py_version
5047
self._checker = checker

compatibility_lib/compatibility_lib/test_compatibility_store.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def test_get_packages(self):
115115
[pkgs[0], 'SUCCESS'],
116116
[pkgs[1], 'CHECK WARNING'],
117117
]
118-
def MockClient():
118+
def MockClient(project=None):
119119
return mock_client
120120

121121
patch_client = mock.patch(
@@ -134,7 +134,7 @@ def MockClient():
134134

135135
def test_get_self_compatibility(self):
136136
mock_client = mock.Mock()
137-
def MockClient():
137+
def MockClient(project=None):
138138
return mock_client
139139

140140
row = mock.Mock(
@@ -166,7 +166,7 @@ def MockClient():
166166
def test_get_self_compatibilities(self):
167167
mock_client = mock.Mock()
168168

169-
def MockClient():
169+
def MockClient(project=None):
170170
return mock_client
171171

172172
packages = [PACKAGE_1, PACKAGE_2, PACKAGE_3, PACKAGE_4]
@@ -203,7 +203,7 @@ def test_get_pair_compatibility_value_error(self):
203203
# raise ValueError.
204204
mock_client = mock.Mock()
205205

206-
def MockClient():
206+
def MockClient(project=None):
207207
return mock_client
208208

209209
patch_client = mock.patch(
@@ -220,7 +220,7 @@ def MockClient():
220220
def test_get_pair_compatibility(self):
221221
mock_client = mock.Mock()
222222

223-
def MockClient():
223+
def MockClient(project=None):
224224
return mock_client
225225

226226
row = mock.Mock(
@@ -252,7 +252,7 @@ def MockClient():
252252
def test_compatibility_combinations(self):
253253
mock_client = mock.Mock()
254254

255-
def MockClient():
255+
def MockClient(project=None):
256256
return mock_client
257257

258258
row1 = mock.Mock(
@@ -322,7 +322,7 @@ def test_save_compatibility_statuses_pair(self):
322322
'details': None,
323323
}
324324

325-
def MockClient():
325+
def MockClient(project=None):
326326
return mock_client
327327

328328
patch_client = mock.patch(
@@ -356,7 +356,7 @@ def test_save_compatibility_statuses_self(self):
356356
'details': None,
357357
}
358358

359-
def MockClient():
359+
def MockClient(project=None):
360360
return mock_client
361361

362362
patch_client = mock.patch(
@@ -400,7 +400,7 @@ def test_save_compatibility_statuses_release_time(self):
400400
'is_latest': True,
401401
}
402402

403-
def MockClient():
403+
def MockClient(project=None):
404404
return mock_client
405405

406406
patch_client = mock.patch(
@@ -416,6 +416,10 @@ def MockClient():
416416

417417

418418
class MockClient(object):
419+
420+
def __init__(self, project=None):
421+
self.project = project
422+
419423
def dataset(self, dataset_name):
420424
dataset_ref = mock.Mock()
421425

compatibility_lib/compatibility_lib/utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ def __init__(self, py_version=None, checker=None, store=None):
5656
if checker is None:
5757
checker = compatibility_checker.CompatibilityChecker()
5858

59-
if store is None:
60-
store = compatibility_store.CompatibilityStore()
61-
6259
self.py_version = py_version
6360
self.checker = checker
6461
self.store = store
@@ -72,7 +69,7 @@ def _get_from_bigquery(self, package_name):
7269
a dict mapping from dependency package name (string) to
7370
the info (dict)
7471
"""
75-
if package_name in configs.PKG_LIST:
72+
if self.store is not None and package_name in configs.PKG_LIST:
7673
depinfo = self.store.get_dependency_info(package_name)
7774
return depinfo
7875
else:
@@ -112,6 +109,7 @@ def get_dependency_info(self, package_name):
112109
the info (dict)
113110
"""
114111
depinfo = self._get_from_bigquery(package_name)
112+
115113
if depinfo is None:
116114
depinfo = self._get_from_endpoint(package_name)
117115
return depinfo

0 commit comments

Comments
 (0)