8000 Move google.cloud.future to google.api.core (#3764) · landrito/google-cloud-python@74fcf00 · GitHub
[go: up one dir, main page]

Skip to content

Commit 74fcf00

Browse files
Jon Wayne Parrottlandrito
authored andcommitted
Move google.cloud.future to google.api.core (googleapis#3764)
1 parent d60b6af commit 74fcf00

File tree

16 files changed

+48
-25
lines changed

16 files changed

+48
-25
lines changed

bigquery/google/cloud/bigquery/job.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import six
2020
from six.moves import http_client
2121

22+
import google.api.core.future.polling
2223
from google.cloud import exceptions
2324
from google.cloud.exceptions import NotFound
2425
from google.cloud._helpers import _datetime_from_microseconds
@@ -31,7 +32,6 @@
3132
from google.cloud.bigquery._helpers import UDFResourcesProperty
3233
from google.cloud.bigquery._helpers import _EnumProperty
3334
from google.cloud.bigquery._helpers import _TypedProperty
34-
import google.cloud.future.polling
3535

3636
_DONE_STATE = 'DONE'
3737
_STOPPED_REASON = 'stopped'
@@ -140,7 +140,7 @@ class WriteDisposition(_EnumProperty):
140140
WRITE_EMPTY = 'WRITE_EMPTY'
141141

142142

143-
class _AsyncJob(google.cloud.future.polling.PollingFuture):
143+
class _AsyncJob(google.api.core.future.polling.PollingFuture):
144144
"""Base class for asynchronous jobs.
145145
146146
:type name: str
@@ -496,7 +496,7 @@ def cancelled(self):
496496
497497
This always returns False. It's not possible to check if a job was
498498
cancelled in the API. This method is here to satisfy the interface
499-
for :class:`google.cloud.future.Future`.
499+
for :class:`google.api.core.future.Future`.
500500
501501
:rtype: bool
502502
:returns: False

bigtable/google/cloud/bigtable/cluster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
import re
1919

20+
from google.api.core import operation
2021
from google.cloud.bigtable._generated import (
2122
instance_pb2 as data_v2_pb2)
2223
from google.cloud.bigtable._generated import (
2324
bigtable_instance_admin_pb2 as messages_v2_pb2)
24-
from google.cloud.future import operation
2525

2626
_CLUSTER_NAME_RE = re.compile(r'^projects/(?P<project>[^/]+)/'
2727
r'instances/(?P<instance>[^/]+)/clusters/'

bigtable/google/cloud/bigtable/instance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import re
1919

20+
from google.api.core import operation
2021
from google.cloud.bigtable._generated import (
2122
instance_pb2 as data_v2_pb2)
2223
from google.cloud.bigtable._generated import (
@@ -26,7 +27,6 @@
2627
from google.cloud.bigtable.cluster import Cluster
2728
from google.cloud.bigtable.cluster import DEFAULT_SERVE_NODES
2829
from google.cloud.bigtable.table import Table
29-
from google.cloud.future import operation
3030

3131

3232
_EXISTING_INSTANCE_LOCATION_ID = 'see-existing-cluster'

bigtable/tests/unit/test_cluster.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ def test_reload(self):
233233
self.assertEqual(cluster.location, LOCATION)
234234

235235
def test_create(self):
236+
from google.api.core import operation
236237
from google.longrunning import operations_pb2
237-
from google.cloud.future import operation
238238
from google.cloud.bigtable._generated import (
239239
bigtable_instance_admin_pb2 as messages_v2_pb2)
240240
from tests.unit._testing import _FakeStub
@@ -275,8 +275,8 @@ def test_create(self):
275275

276276
def test_update(self):
277277
import datetime
278+
from google.api.core import operation
278279
from google.longrunning import operations_pb2
279-
from google.cloud.future import operation
280280
from google.protobuf.any_pb2 import Any
281281
from google.cloud._helpers import _datetime_to_pb_timestamp
282282
from google.cloud.bigtable._generated import (

bigtable/tests/unit/test_instance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,13 @@ def test_reload(self):
232232

233233
def test_create(self):
234234
import datetime
235+
from google.api.core import operation
235236
from google.longrunning import operations_pb2
236237
from google.protobuf.any_pb2 import Any
237238
from google.cloud.bigtable._generated import (
238239
bigtable_instance_admin_pb2 as messages_v2_pb2)
239240
from google.cloud._helpers import _datetime_to_pb_timestamp
240241
from tests.unit._testing import _FakeStub
241-
from google.cloud.future import operation
242242
from google.cloud.bigtable.cluster import DEFAULT_SERVE_NODES
243243

244244
NOW = datetime.datetime.utcnow()
@@ -285,11 +285,11 @@ def test_create(self):
285285
self.assertEqual(kwargs, {})
286286

287287
def test_create_w_explicit_serve_nodes(self):
288+
from google.api.core import operation
288289
from google.longrunning import operations_pb2
289290
from google.cloud.bigtable._generated import (
290291
bigtable_instance_admin_pb2 as messages_v2_pb2)
291292
from tests.unit._testing import _FakeStub
292-
from google.cloud.future import operation
293293

294294
SERVE_NODES = 5
295295

core/google/cloud/future/__init__.py renamed to core/google/api/core/future/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
"""Futures for dealing with asynchronous operations."""
1616

17-
from google.cloud.future.base import Future
17+
from google.api.core.future.base import Future
1818

1919
__all__ = [
2020
'Future',

core/google/cloud/future/polling.py renamed to core/google/api/core/future/polling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import six
2323
import tenacity
2424

25-
from google.cloud.future import _helpers
26-
from google.cloud.future import base
25+
from google.api.core.future import _helpers
26+
from google.api.core.future import base
2727

2828

2929
class PollingFuture(base.Future):

core/google/cloud/future/operation.py renamed to core/google/api/core/operation.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,36 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Futures for long-running operations returned from Google Cloud APIs."""
15+
"""Futures for long-running operations returned from Google Cloud APIs.
16+
17+
These futures can be used to synchronously wait for the result of a
18+
long-running operation using :meth:`Operation.result`:
19+
20+
21+
.. code-block:: python
22+
23+
operation = my_api_client.long_running_method()
24+
result = operation.result()
25+
26+
Or asynchronously using callbacks and :meth:`Operation.add_done_callback`:
27+
28+
.. code-block:: python
29+
30+
operation = my_api_client.long_running_method()
31+
32+
def my_callback(future):
33+
result = future.result()
34+
35+
operation.add_done_callback(my_callback)
36+
37+
"""
1638

1739
import functools
1840
import threading
1941

42+
from google.api.core import exceptions
43+
from google.api.core.future import polling
2044
from google.cloud import _helpers
21-
from google.cloud import exceptions
22-
from google.cloud.future import polling
2345
from google.longrunning import operations_pb2
2446
from google.protobuf import json_format
2547
from google.rpc import code_pb2
@@ -85,12 +107,13 @@ def _set_result_from_operation(self):
85107
self._result_type, self._operation.response)
86108
self.set_result(response)
87109
elif self._operation.< 1CF5 span class=pl-c1>HasField('error'):
88-
exception = exceptions.GoogleCloudError(
110+
exception = exceptions.GoogleAPICallError(
89111
self._operation.error.message,
90-
errors=(self._operation.error))
112+
errors=(self._operation.error),
113+
response=self._operation)
91114
self.set_exception(exception)
92115
else:
93-
exception = exceptions.GoogleCloudError(
116+
exception = exceptions.GoogleAPICallError(
94117
'Unexpected state: Long-running operation had neither '
95118
'response nor error set.')
96119
self.set_exception(exception)

0 commit comments

Comments
 (0)
0