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

Restore the pyodide-http patch #742

Merged
merged 2 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions packages/kernel/py/stlite-server/stlite_server/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ def _import_pyarrow_interchange():
logger.error("Failed to fix Altair", exc_info=e)


def _fix_requests():
try:
import pyodide_http # type: ignore[import]

pyodide_http.patch_all() # Patch all libraries
except ImportError:
# pyodide_http is not installed. No need to do anything.
pass


def prepare(
main_script_path: str,
args: List[str],
Expand All @@ -156,6 +166,7 @@ def prepare(
_fix_sys_path(main_script_path)
_fix_matplotlib_crash()
_fix_altair()
_fix_requests()
_fix_sys_argv(main_script_path, args)
_fix_pydeck_mapbox_api_warning()
_install_pages_watcher(main_script_path)
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import streamlit as st
from streamlit.hello.utils import show_code

import pyodide.http # We need to use `pyodide.http` in the Pyodide environment for network communications. See https://pyodide.org/en/stable/usage/faq.html#how-can-i-load-external-files-in-pyodide


def mapping_demo():
@st.cache_data
Expand All @@ -31,8 +29,7 @@ def from_data_file(filename):
"https://raw.githubusercontent.com/streamlit/"
"example-data/master/hello/v1/%s" % filename
)
# return pd.read_json(url)
return pd.read_json(pyodide.http.open_url(url))
return pd.read_json(url)

try:
ALL_LAYERS = {
Expand Down
Loading