Skip to content

Commit 81d5a71

Browse files
metrizablecolaboratory-team
authored andcommitted
Internal change
PiperOrigin-RevId: 514821183
1 parent c7b3c99 commit 81d5a71

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+928
-592
lines changed

google/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
# pylint:disable=g-import-not-at-top
1717
try:
1818
import pkg_resources
19+
1920
pkg_resources.declare_namespace(__name__)
2021
except ImportError:
2122
import pkgutil
23+
2224
__path__ = pkgutil.extend_path(__path__, __name__)

google/colab/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,14 @@
3131
from google.colab import widgets
3232

3333
__all__ = [
34-
'auth', 'data_table', 'drive', 'files', 'output', 'runtime', 'snippets',
35-
'widgets'
34+
'auth',
35+
'data_table',
36+
'drive',
37+
'files',
38+
'output',
39+
'runtime',
40+
'snippets',
41+
'widgets',
3642
]
3743

3844
__version__ = '0.0.1a2'

google/colab/_debugpy.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def inspector_thread():
6666
# Need to start this thread after the debugpy.listen() call but before
6767
# the undo_patch_thread_modules().
6868
threading.Thread(
69-
target=inspector_thread, name='_colab_inspector_thread',
70-
daemon=True).start()
69+
target=inspector_thread, name='_colab_inspector_thread', daemon=True
70+
).start()
7171
inspector_thread_started.wait()
7272

7373
# Debugger tracing isn't needed for just tracebacks, but if full debugging
@@ -81,10 +81,12 @@ def inspector_thread():
8181
try:
8282
# Stop debugpy from tracing newly created threads.
8383
from _pydev_bundle import pydev_monkey # pylint: disable=g-import-not-at-top
84+
8485
pydev_monkey.undo_patch_thread_modules()
8586
except ModuleNotFoundError:
8687
# _pydev_bundle may be vendored into either location.
8788
from pydevd._pydev_bundle import pydev_monkey # pylint: disable=g-import-not-at-top
89+
8890
pydev_monkey.undo_patch_thread_modules()
8991

9092
# Clear the trace flag to allow fetching stack traces.

google/colab/_debugpy_repr.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ def get_shape(obj):
5252
if isinstance(obj, collections_abc.Sized):
5353
try:
5454
shape = getattr(obj, 'shape', None)
55-
if (isinstance(shape, tuple) or
56-
hasattr(shape, '__module__') and isinstance(shape.__module__, str) and
57-
'tensorflow.' in shape.__module__):
55+
if (
56+
isinstance(shape, tuple)
57+
or hasattr(shape, '__module__')
58+
and isinstance(shape.__module__, str)
59+
and 'tensorflow.' in shape.__module__
60+
):
5861
return str(shape)
5962
except Exception: # pylint: disable=broad-except
6063
logging.exception('Unexpected exception finding object shape')

google/colab/_history.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ColabHistoryManager(history.HistoryManager):
2626
This allows us to associate code executions with the cell which was executed
2727
in Colab's UI.
2828
"""
29+
2930
_input_hist_cells = [{'code': '', 'cell_id': '', 'start_time': 0}]
3031

3132
def reset(self, new_session=True):
@@ -36,12 +37,16 @@ def reset(self, new_session=True):
3637
def store_inputs(self, line_num, source, source_raw=None):
3738
"""Variant of HistoryManager.store_inputs which also stores the cell ID."""
3839
super(ColabHistoryManager, self).store_inputs(
39-
line_num, source, source_raw=source_raw)
40+
line_num, source, source_raw=source_raw
41+
)
4042

4143
# The parent_header on the shell is the message that resulted in the code
4244
# execution request. Grab the cell ID out of that.
43-
cell_id = self.shell.parent_header.get('metadata',
44-
{}).get('colab', {}).get('cell_id')
45+
cell_id = (
46+
self.shell.parent_header.get('metadata', {})
47+
.get('colab', {})
48+
.get('cell_id')
49+
)
4550

4651
self._input_hist_cells.append({
4752
'code': source_raw,
@@ -76,10 +81,10 @@ def _executed_cells_as_json(self, include_source_hash=False):
7681
if include_source_hash:
7782
# LINT.IfChange(execution_count)
7883
cells[cell['cell_id']] = {
79-
'executionCount':
80-
i,
81-
'sourceHash':
82-
hashlib.md5(cell['code'].encode('utf8')).hexdigest()[:10]
84+
'executionCount': i,
85+
'sourceHash': hashlib.md5(cell['code'].encode('utf8')).hexdigest()[
86+
:10
87+
],
8388
}
8489
# LINT.ThenChange()
8590
else:

google/colab/_import_hooks/_altair.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ class _AltairImportHook:
2424

2525
def find_module(self, fullname, path=None):
2626
if fullname not in [
27-
'altair.vegalite.v2', 'altair.vegalite.v3', 'altair.vegalite.v4'
27+
'altair.vegalite.v2',
28+
'altair.vegalite.v3',
29+
'altair.vegalite.v4',
2830
]:
2931
return None
3032
self.module_info = imp.find_module(fullname.split('.')[-1], path)

google/colab/_import_hooks/_bokeh.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def load_module(self, name):
5151
# output_notebook()
5252
# just works without modification.
5353
_bokeh_io_module.notebook.install_notebook_hook(
54-
'jupyter', _load_notebook, _show_doc, _show_app, overwrite=True)
54+
'jupyter', _load_notebook, _show_doc, _show_app, overwrite=True
55+
)
5556
except: # pylint: disable=bare-except
5657
logging.exception('Error enabling Bokeh Colab rendering.')
5758
os.environ['COLAB_BOKEH_IMPORT_HOOK_EXCEPTION'] = '1'
@@ -77,17 +78,17 @@ def _show_doc(obj, state, notebook_handle):
7778
_bokeh_loaded_in_this_cell = True
7879
IPython.get_ipython().events.register('post_run_cell', _post_execute) # pylint: disable=undefined-variable
7980
_bokeh_io_module.notebook.load_notebook(
80-
resources=_bokeh_resources, hide_banner=True)
81+
resources=_bokeh_resources, hide_banner=True
82+
)
8183

8284
# Call the default bokeh rendering path.
8385
return _bokeh_io_module.notebook.show_doc(obj, state, notebook_handle)
8486

8587

8688
# pylint: disable=unused-argument
87-
def _load_notebook(resources=None,
88-
verbose=False,
89-
hide_banner=False,
90-
load_timeout=5000):
89+
def _load_notebook(
90+
resources=None, verbose=False, hide_banner=False, load_timeout=5000
91+
):
9192
global _bokeh_resources
9293
# In Jupyter this method is called once per notebook launch but with Colab's
9394
# isolated outputframes this loading needs to be done for each outputframe.

google/colab/_import_hooks/_client_info.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def load_module(self, fullname):
3838
3939
Args:
4040
fullname: fullname of the module
41+
4142
Returns:
4243
A modified google.api_core.client_info module.
4344
"""

google/colab/_import_hooks/_cv2.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ class _OpenCVImportHook:
6060
'{0}.imshow() is disabled in Colab, because it causes Jupyter sessions\n'
6161
'to crash; see https://github.com/jupyter/notebook/issues/3935.\n'
6262
'As a substitution, consider using\n'
63-
' from google.colab.patches import {0}_imshow\n')
63+
' from google.colab.patches import {0}_imshow\n'
64+
)
6465
env_var = 'ENABLE_CV2_IMSHOW'
6566

6667
def find_module(self, fullname, path=None):
@@ -82,7 +83,8 @@ def load_module(self, name):
8283
cv_module.imshow,
8384
message=self.message.format(name),
8485
env_var=self.env_var,
85-
name='{}.imshow'.format(name))
86+
name='{}.imshow'.format(name),
87+
)
8688
except: # pylint: disable=bare-except
8789
logging.exception('Error disabling %s.imshow().', name)
8890
os.environ['COLAB_CV2_IMPORT_HOOK_EXCEPTION'] = '1'

google/colab/_import_hooks/_pydrive.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,26 @@ def load_module(self, name):
4343
try:
4444
import httplib2 # pylint:disable=g-import-not-at-top
4545
from oauth2client.contrib.gce import AppAssertionCredentials # pylint:disable=g-import-not-at-top
46-
orig_local_webserver_auth = pydrive_auth_module.GoogleAuth.LocalWebserverAuth
46+
47+
orig_local_webserver_auth = (
48+
pydrive_auth_module.GoogleAuth.LocalWebserverAuth
49+
)
4750

4851
# Capture the environment variable outside of the patched method since
4952
# self will refer to a GoogleAuth object in these cases.
5053
env_var = self.env_var
5154

5255
def PatchedLocalWebServerAuth(self, *args, **kwargs): # pylint:disable=invalid-name
5356
if not os.environ.get(env_var, '') and isinstance(
54-
self.credentials, AppAssertionCredentials):
57+
self.credentials, AppAssertionCredentials
58+
):
5559
self.credentials.refresh(httplib2.Http())
5660
return
5761
return orig_local_webserver_auth(self, *args, **kwargs)
5862

59-
pydrive_auth_module.GoogleAuth.LocalWebserverAuth = PatchedLocalWebServerAuth
63+
pydrive_auth_module.GoogleAuth.LocalWebserverAuth = (
64+
PatchedLocalWebServerAuth
65+
)
6066
except: # pylint: disable=bare-except
6167
logging.exception('Error patching PyDrive')
6268

0 commit comments

Comments
 (0)