Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 675630891
  • Loading branch information
metrizable authored and colaboratory-team committed Jan 16, 2025
1 parent aedbf94 commit d71e137
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
22 changes: 8 additions & 14 deletions google/colab/_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Kernel(ipkernel.IPythonKernel):
def _shell_class_default(self):
return _shell.Shell

def do_inspect(self, code, cursor_pos, detail_level=0):
def do_inspect(self, code, cursor_pos, detail_level=0, *args, **kwargs):
name = tokenutil.token_at_cursor(code, cursor_pos)
info = self.shell.object_inspect(name)

Expand Down Expand Up @@ -102,23 +102,17 @@ def complete_request(self, stream, ident, parent):

self.session.send(stream, 'complete_reply', matches, parent, ident)

def inspect_request(self, stream, ident, parent):
# TODO: Consider reverting to a `super()` call here once we
# support async.
async def inspect_request(self, stream, ident, parent):
try:
content = parent['content']
reply_content = self.do_inspect(
content['code'], content['cursor_pos'], content.get('detail_level', 0)
)
reply_content = jsonutil.json_clean(reply_content)
await super().inspect_request(stream, ident, parent)
except BaseException as e: # pylint: disable=broad-except
# TODO: Consider returning an error here.
self.log.info('Error caught during object inspection: %s', e)
self.log.warning('Error caught during object inspection: %s', e)
reply_content = '{"status":"ok","found":false}'
msg = self.session.send(
stream, 'inspect_reply', reply_content, parent, ident
)
self.log.debug('%s', msg)
msg = self.session.send(
stream, 'inspect_reply', reply_content, parent, ident
)
self.log.debug('%s', msg)


def _to_primitive(o):
Expand Down
24 changes: 24 additions & 0 deletions google/colab/_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from ipykernel import jsonutil
from ipykernel import zmqshell
from IPython.core import alias
from IPython.core import compilerop
from IPython.core import inputsplitter
from IPython.core import interactiveshell
from IPython.core import oinspect
Expand Down Expand Up @@ -70,6 +71,29 @@ def init_history(self):
self.history_manager = _history.ColabHistoryManager(shell=self, parent=self)
self.configurables.append(self.history_manager)

def init_instance_attrs(self):
"""Initialize instance attributes.
For enhanced debugging, ipykernel compiler defines a new XCachingCompiler:
https://github.com/ipython/ipykernel/blob/v6.17.1/ipykernel/compiler.py#L91
It's used as the default IPythonKernel shell_class' compiler_class:
https://github.com/ipython/ipykernel/blob/v6.17.1/ipykernel/ipkernel.py#L96
This means, functionally, the `code_name` has changed to
something like /tmp/ipykernel_{pid}/{murmurhash}.py, rather than
<ipython-N-XXXXX.py>.
https://github.com/ipython/ipykernel/blob/v6.17.1/ipykernel/compiler.py#L75
Since we implement our own Shell which inherits from
`zmqshell.ZMQInteractiveShell`, which inherits from
`IPython.core.interactiveshell.InteractiveShell`, we pick up this change.
The old code_name (e.g. `ipython-N-XXXXX.py`) is widely used and parsed.
We therefore update our shell to pull in the old behavior.
"""
self.compiler_class = compilerop.CachingCompiler
super().init_instance_attrs()

def _should_use_native_system_methods(self):
# TODO: Update to match intended values, as appropriate.
return bool(os.getenv('USE_NATIVE_IPYTHON_SYSTEM_COMMANDS'))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Note: these dependency versions should be kept in-sync with the versions
# specified in the docker container requirements files.
'google-auth==2.27.0',
'ipykernel==5.5.6',
'ipykernel==6.17.1',
'ipyparallel==8.8.0',
'ipython==7.34.0',
'notebook==6.5.5',
Expand Down

0 comments on commit d71e137

Please sign in to comment.