Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.

Commit

Permalink
Refactor references of async to async_ for Python 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
crwilcox committed Mar 10, 2020
1 parent 78d3d68 commit 5fb9a4a
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ matrix:
env: TOX_ENV=py27
- python: 3.5
env: TOX_ENV=py35
- python: 3.7
env: TOX_ENV=py37
- python: 2.7
env: TOX_ENV=flake8
- python: 2.7
Expand Down
4 changes: 2 additions & 2 deletions datalab/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

"""Google Cloud Platform library - Internal Helpers."""

from ._async import async, async_function, async_method
from ._async import async_, async_function, async_method
from ._gcp_job import GCPJob
from ._http import Http, RequestException
from ._iterator import Iterator
Expand All @@ -24,7 +24,7 @@
from ._utils import print_exception_with_last_stack, get_item, compare_datetimes, \
pick_unused_port, is_http_running_on, gcs_copy_file

__all__ = ['async', 'async_function', 'async_method', 'GCPJob', 'Http', 'RequestException',
__all__ = ['async_', 'async_function', 'async_method', 'GCPJob', 'Http', 'RequestException',
'Iterator', 'Job', 'JobError', 'JSONEncoder', 'LRUCache', 'LambdaJob', 'DataflowJob',
'print_exception_with_last_stack', 'get_item', 'compare_datetimes', 'pick_unused_port',
'is_http_running_on', 'gcs_copy_file']
12 changes: 6 additions & 6 deletions datalab/utils/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from future.utils import with_metaclass


class async(with_metaclass(abc.ABCMeta, object)):
class async_(with_metaclass(abc.ABCMeta, object)):
""" Base class for async_function/async_method. Creates a wrapped function/method that will
run the original function/method on a thread pool worker thread and return a Job instance
for monitoring the status of the thread.
Expand Down Expand Up @@ -55,27 +55,27 @@ def __call__(self, *args, **kwargs):
return _job.Job(future=self.executor.submit(self._call, *args, **kwargs))


class async_function(async):
class async_function(async_):
""" This decorator can be applied to any static function that makes blocking calls to create
a modified version that creates a Job and returns immediately; the original
method will be called on a thread pool worker thread.
"""

def _call(self, *args, **kwargs):
# Call the wrapped method.
return self._function(*async._preprocess_args(*args), **async._preprocess_kwargs(**kwargs))
return self._function(*async_._preprocess_args(*args), **async_._preprocess_kwargs(**kwargs))


class async_method(async):
class async_method(async_):
""" This decorator can be applied to any class instance method that makes blocking calls to create
a modified version that creates a Job and returns immediately; the original method will be
called on a thread pool worker thread.
"""

def _call(self, *args, **kwargs):
# Call the wrapped method.
return self._function(self.obj, *async._preprocess_args(*args),
**async._preprocess_kwargs(**kwargs))
return self._function(self.obj, *async_._preprocess_args(*args),
**async_._preprocess_kwargs(**kwargs))

def __get__(self, instance, owner):
# This is important for attribute inheritance and setting self.obj so it can be
Expand Down
2 changes: 1 addition & 1 deletion datalab/utils/_lambda_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, fn, job_id, *args, **kwargs):
job_id: an optional ID for the job. If None, a UUID will be generated.
"""
super(LambdaJob, self).__init__(job_id)
self._future = _async.async.executor.submit(fn, *args, **kwargs)
self._future = _async.async_.executor.submit(fn, *args, **kwargs)

def __repr__(self):
"""Returns a representation for the job for showing in the notebook.
Expand Down
4 changes: 2 additions & 2 deletions google/datalab/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

"""Google Cloud Platform library - Internal Helpers."""

from ._async import async, async_function, async_method
from ._async import async_, async_function, async_method
from ._http import Http, RequestException
from ._iterator import Iterator
from ._json_encoder import JSONEncoder
Expand All @@ -23,7 +23,7 @@
pick_unused_port, is_http_running_on, gcs_copy_file, python_portable_string


__all__ = ['async', 'async_function', 'async_method', 'Http', 'RequestException', 'Iterator',
__all__ = ['async_', 'async_function', 'async_method', 'Http', 'RequestException', 'Iterator',
'JSONEncoder', 'LRUCache', 'LambdaJob', 'DataflowJob',
'print_exception_with_last_stack', 'get_item', 'compare_datetimes', 'pick_unused_port',
'is_http_running_on', 'gcs_copy_file', 'python_portable_string']
12 changes: 6 additions & 6 deletions google/datalab/utils/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from future.utils import with_metaclass


class async(with_metaclass(abc.ABCMeta, object)):
class async_(with_metaclass(abc.ABCMeta, object)):
""" Base class for async_function/async_method. Creates a wrapped function/method that will
run the original function/method on a thread pool worker thread and return a Job instance
for monitoring the status of the thread.
Expand Down Expand Up @@ -55,27 +55,27 @@ def __call__(self, *args, **kwargs):
return Job(future=self.executor.submit(self._call, *args, **kwargs))


class async_function(async):
class async_function(async_):
""" This decorator can be applied to any static function that makes blocking calls to create
a modified version that creates a Job and returns immediately; the original
method will be called on a thread pool worker thread.
"""

def _call(self, *args, **kwargs):
# Call the wrapped method.
return self._function(*async._preprocess_args(*args), **async._preprocess_kwargs(**kwargs))
return self._function(*async_._preprocess_args(*args), **async_._preprocess_kwargs(**kwargs))


class async_method(async):
class async_method(async_):
""" This decorator can be applied to any class instance method that makes blocking calls to create
a modified version that creates a Job and returns immediately; the original method will be
called on a thread pool worker thread.
"""

def _call(self, *args, **kwargs):
# Call the wrapped method.
return self._function(self.obj, *async._preprocess_args(*args),
**async._preprocess_kwargs(**kwargs))
return self._function(self.obj, *async_._preprocess_args(*args),
**async_._preprocess_kwargs(**kwargs))

def __get__(self, instance, owner):
# This is important for attribute inheritance and setting self.obj so it can be
Expand Down
2 changes: 1 addition & 1 deletion google/datalab/utils/_lambda_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, fn, job_id, *args, **kwargs):
job_id: an optional ID for the job. If None, a UUID will be generated.
"""
super(LambdaJob, self).__init__(job_id)
self._future = _async.async.executor.submit(fn, *args, **kwargs)
self._future = _async.async_.executor.submit(fn, *args, **kwargs)

def __repr__(self):
"""Returns a representation for the job for showing in the notebook.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from setuptools import setup

version = '1.1.3'
version = '1.1.5'

setup(
name='datalab',
Expand Down

0 comments on commit 5fb9a4a

Please sign in to comment.