Skip to content

Commit

Permalink
Make colab_run a no-op when not running in colab env
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwillchen committed Jan 29, 2024
1 parent f297409 commit 015551c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions mesop/server/colab_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
from mesop.server.logging import log_startup
from mesop.server.server import configure_flask_app
from mesop.server.static_file_serving import configure_static_file_serving
from mesop.utils.colab_utils import is_running_in_colab


def colab_run():
"""
Typically only used for Colab/Jupyter notebooks, otherwise you'll use the CLI
to execute a Mesop application.
When running in Colab environment, this will launch the web server.
Otherwise, this is a no-op.
"""
if not is_running_in_colab():
print("Not running Colab: `colab_run` is a no-op")
return
flask_app = configure_flask_app()
enable_debug_mode()
configure_static_file_serving(
Expand Down
6 changes: 6 additions & 0 deletions mesop/utils/colab_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import builtins
import sys


def is_running_in_colab() -> bool:
return "google.colab" in sys.modules and hasattr(builtins, "get_ipython")

0 comments on commit 015551c

Please sign in to comment.