Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the bootstrap Python code to call the customized run() instead of the original bootstrap.run() #181

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion packages/stlite-kernel/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,34 @@ async function loadPyodideAndPackages() {

// Emulate the process in streamlit/web/cli.py
await pyodide.runPythonAsync(`
import asyncio
import os
import streamlit
import streamlit.web.bootstrap as bootstrap
from streamlit.web.server import Server


def _on_server_start(server):
print("Streamlit server started")


# Mimic streamlit.web.bootstrap.run() but exclude some code unnecessary for stlite environment
def run(
main_script_path,
command_line,
args,
flag_options,
) -> None:
bootstrap._fix_sys_path(main_script_path)
bootstrap._fix_sys_argv(main_script_path, args)
bootstrap._fix_pydeck_mapbox_api_warning()
bootstrap._install_pages_watcher(main_script_path)

# Create the server. It won't start running yet.
server = Server(main_script_path, command_line)

# Run the server.
asyncio.get_event_loop().create_task(server.start(_on_server_start))


def _get_command_line_as_string():
Expand All @@ -146,7 +171,7 @@ async function loadPyodideAndPackages() {

# check_credentials() # Disable credential check on Pyodide

bootstrap.run(file, command_line, args, flag_options)
run(file, command_line, args, flag_options) # Call this customized run function instead of the original bootstrap.run.


def main_hello(**kwargs):
Expand Down