Skip to content

Commit

Permalink
fix: address warnings on kernel initialized dispatch (#205)
Browse files Browse the repository at this point in the history
* fix: autorouting should pick up modules that only define routes

Instead of having a Page component, we should also just allow a user
to define a set of routes.
This is what we need for the /apps/scrolling example.

* fix: hot reload was too aggresive (#179)

* test: enable reload tests

* fix: do not reload modules that are not under the app directory

Fixes #177
Fixes #148

* clean up code

* __file__ can be None

* call clear from the test code

* move to subdir so we do not reload the test modules

* also catch AttributeError when app is None during unitesting

* fix: solara patches should have no effect outside a solara context

* pass cls

* fix: ignore typing

* pass cls

* fix: ignore typing

---------

Co-authored-by: Maarten A. Breddels <[email protected]>
  • Loading branch information
lp9052 and maartenbreddels committed Jul 20, 2023
1 parent b6a2958 commit 6005f96
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions solara/server/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,34 +74,38 @@ def set_custom_exc(self, exc_tuple, handler):
pass


kernel_instance_dispatch_initial = ipykernel.kernelbase.Kernel.instance.__func__
Kernel_instance_original = ipykernel.kernelbase.Kernel.instance.__func__ # type: ignore


def kernel_instance_dispatch(cls, *args, **kwargs):
if not app.has_current_context():
return kernel_instance_dispatch_initial(cls, *args, **kwargs)
else:
if app.has_current_context():
context = app.get_current_context()
return context.kernel
else:
return Kernel_instance_original(cls, *args, **kwargs)


Kernel_initialized_initial = ipykernel.kernelbase.Kernel.initialized.__func__ # type: ignore


InteractiveShell_instance_initial = InteractiveShell.instance
def kernel_initialized_dispatch(cls):
if app is None: # python is shutting down, and the comm dtor wants to send a close message
return False
if app.has_current_context():
return True
else:
return Kernel_initialized_initial(cls)


InteractiveShell_instance_initial = InteractiveShell.instance.__func__ # type: ignore


def interactive_shell_instance_dispatch(cls, *args, **kwargs):
if app.has_current_context():
context = app.get_current_context()
return context.kernel.shell
else:
return InteractiveShell_instance_initial(*args, **kwargs)


def kernel_initialized_dispatch(cls):
try:
app.get_current_context()
except RuntimeError:
return False
return True
return InteractiveShell_instance_initial(cls, *args, **kwargs)


def display_solara(
Expand Down

0 comments on commit 6005f96

Please sign in to comment.