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

Update streamlit to 1.35.0 #920

Merged
merged 10 commits into from
May 26, 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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ jobs:
run: |
. .venv/bin/activate
cd packages/kernel/py/stlite-server
poetry run python -m pytest -v tests
poetry run python -m pytest -v

test-mountable:
needs: changes
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ desktop := packages/desktop/build/*
kernel := packages/kernel/dist/*
stlite-server-wheel := packages/kernel/py/stlite-server/dist/stlite_server-0.1.0-py3-none-any.whl
streamlit_proto := streamlit/frontend/lib/src/proto.d.ts
streamlit_wheel := packages/kernel/py/streamlit/lib/dist/streamlit-1.33.0-cp311-none-any.whl
streamlit_wheel := packages/kernel/py/streamlit/lib/dist/streamlit-1.35.0-cp311-none-any.whl
streamlit_frontend_lib_prod := streamlit/frontend/lib/dist/*

.PHONY: all
Expand Down Expand Up @@ -127,7 +127,7 @@ $(streamlit_wheel): venv $(streamlit_proto) streamlit/lib/streamlit/**/*.py stre
exit 1; \
fi && \
cd streamlit && SNOWPARK_CONDA_BUILD=true $(MAKE) distribution && cd .. && \
pyodide py-compile --keep streamlit/lib/dist/streamlit-1.33.0-py2.py3-none-any.whl && \
pyodide py-compile --keep streamlit/lib/dist/streamlit-1.35.0-py2.py3-none-any.whl && \
mkdir -p $(dir $(streamlit_wheel)) && \
cp streamlit/lib/dist/$(notdir $(streamlit_wheel)) $(streamlit_wheel)

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
},
"resolutions": {
"immutable": "4.2.3",
"protobufjs": "7.2.5",
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because a bug introduced in 7.2.6 which have been reported as follows:
protobufjs/protobuf.js#1972
protobufjs/protobuf.js#1975

"webpack": "5.76.0",
"@types/react": "^18.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/common-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"check:prettier": "prettier --check ."
},
"dependencies": {
"@streamlit/lib": "1.33.0"
"@streamlit/lib": "1.35.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.49.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/bin-src/dump_artifacts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async function installPackages(
requirements.push(stliteServerWheel);
const streamlitWheel = await prepareLocalWheel(
pyodide,
path.join(wheelsDir, "streamlit-1.33.0-cp311-none-any.whl")
path.join(wheelsDir, "streamlit-1.35.0-cp311-none-any.whl")
);
requirements.push(streamlitWheel);

Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"@stlite/common": "^0.54.2",
"@stlite/common-react": "^0.54.2",
"@stlite/kernel": "^0.54.2",
"@streamlit/app": "1.33.0",
"@streamlit/app": "1.35.0",
"@testing-library/react": "^14.1.2",
"@testing-library/user-event": "^14.0.0",
"@types/jest": "^27.4.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/scripts/copy_wheels.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function main() {
);
const streamlitWheelPath = path.join(
stliteKernelPyDir,
"streamlit/lib/dist/streamlit-1.33.0-cp311-none-any.whl"
"streamlit/lib/dist/streamlit-1.35.0-cp311-none-any.whl"
);

// Create the `wheels` directory
Expand Down
4 changes: 2 additions & 2 deletions packages/kernel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"dependencies": {
"@jupyterlab/coreutils": "^5.4.2",
"@stlite/common": "^0.54.2",
"@streamlit/app": "1.33.0",
"@streamlit/lib": "1.33.0",
"@streamlit/app": "1.35.0",
"@streamlit/lib": "1.35.0",
"path-browserify": "^1.0.1"
}
}
7 changes: 6 additions & 1 deletion packages/kernel/py/stlite-server/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ check_untyped_defs = true
mypy_path = "../../../../streamlit/lib"

[[tool.mypy.overrides]]
module = ["streamlit", "streamlit.*"]
module = ["streamlit", "streamlit.*", "tests.*"]
ignore_errors = true

[[tool.mypy.overrides]]
module = ["pyodide", "pyodide.*", "matplotlib", "st_aggrid"]
ignore_missing_imports = true

[tool.pytest.ini_options]
testpaths = [
"stlite_server_tests", # To import the `tests` module in the `streamlit/lib` directory, use a different name for a test directory.
]
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _fix_sys_path(main_script_path: str) -> None:
sys.path.insert(0, os.path.dirname(main_script_path))


def _fix_sys_argv(main_script_path: str, args: List[str]) -> None:
def _fix_sys_argv(main_script_path: str, args: list[str]) -> None:
"""sys.argv needs to exclude streamlit arguments and parameters
and be set to what a user's script may expect.
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import logging
import mimetypes
import os
from typing import Final

from streamlit.components.v1.components import ComponentRegistry
from streamlit.components.types.base_component_registry import BaseComponentRegistry

from .handler import Request, RequestHandler, Response

_LOGGER = logging.getLogger(__name__)
_LOGGER: Final = logging.getLogger(__name__)


# Mimic streamlit.web.server.component_request_handler.ComponentRequestHandler
class ComponentRequestHandler(RequestHandler):
def __init__(self, registry: ComponentRegistry) -> None:
def __init__(self, registry: BaseComponentRegistry) -> None:
self._registry = registry

def get(self, request: Request, path: str) -> Response: # type: ignore[override]
Expand All @@ -27,11 +28,7 @@ def get(self, request: Request, path: str) -> Response: # type: ignore[override
abspath = os.path.realpath(os.path.join(component_root, filename))

# Do NOT expose anything outside of the component root.
if os.path.commonprefix([component_root, abspath]) != component_root or (
not os.path.normpath(abspath).startswith(
component_root
) # this is a recommendation from CodeQL, probably a bit redundant
):
if os.path.commonpath([component_root, abspath]) != component_root:
return Response(status_code=403, headers={}, body="forbidden")

try:
Expand All @@ -54,7 +51,7 @@ def get(self, request: Request, path: str) -> Response: # type: ignore[override
)

@staticmethod
def get_content_type(abspath) -> str:
def get_content_type(abspath: str) -> str:
"""Returns the ``Content-Type`` header to be used for this request.
From tornado.web.StaticFileHandler.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ def get(self, request: Request, path: str) -> Response: # type: ignore[override
# Check that the value can be encoded in latin1. Latin1 is
# the default encoding for headers.
filename.encode("latin1")
file_expr = 'filename="{}"'.format(filename)
file_expr = f'filename="{filename}"'
except UnicodeEncodeError:
file_expr = "filename*=UTF-8''{}".format(quote(filename))
# RFC5987 syntax.
# See: https://datatracker.ietf.org/doc/html/rfc5987
file_expr = f"filename*=utf-8''{quote(filename)}"

headers["Content-Disposition"] = "attachment; " + file_expr

Expand Down
22 changes: 11 additions & 11 deletions packages/kernel/py/stlite-server/stlite_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import Callable, Final, cast

import pyodide
from streamlit.components.v1.components import ComponentRegistry
from streamlit.proto.BackMsg_pb2 import BackMsg
from streamlit.proto.ForwardMsg_pb2 import ForwardMsg
from streamlit.runtime import Runtime, RuntimeConfig, SessionClient
Expand All @@ -23,7 +22,7 @@
from .server_util import make_url_path_regex
from .upload_file_request_handler import UploadFileRequestHandler

LOGGER = logging.getLogger(__name__)
_LOGGER: Final = logging.getLogger(__name__)

# These route definitions are copied from the original impl at https://github.com/streamlit/streamlit/blob/1.27.0/lib/streamlit/web/server/server.py#L83-L92 # noqa: E501
MEDIA_ENDPOINT: Final = "/media"
Expand All @@ -35,7 +34,7 @@
class Server:
_routes: list[tuple[re.Pattern, RequestHandler]] = []

def __init__(self, main_script_path: str, command_line: str | None) -> None:
def __init__(self, main_script_path: str) -> None:
self._main_script_path = main_script_path

self._media_file_storage = MemoryMediaFileStorage(MEDIA_ENDPOINT)
Expand All @@ -45,10 +44,11 @@ def __init__(self, main_script_path: str, command_line: str | None) -> None:
self._runtime = Runtime(
RuntimeConfig(
script_path=main_script_path,
command_line=command_line,
command_line=None,
media_file_storage=self._media_file_storage,
uploaded_file_manager=uploaded_file_mgr,
cache_storage_manager=MemoryCacheStorageManager(),
is_hello=False,
),
)

Expand All @@ -60,9 +60,9 @@ async def start(self) -> None:
When this returns, Streamlit is ready to accept new sessions.
"""

LOGGER.debug("Starting server...")
_LOGGER.debug("Starting server...")

# In stlite, impl, we deal with WebSocket separately.
# In stlite, we deal with WebSocket separately.
self._websocket_handler = WebSocketHandler(self._runtime)

# Based on the original impl at https://github.com/streamlit/streamlit/blob/1.18.1/lib/streamlit/web/server/server.py#L221 # noqa: E501
Expand Down Expand Up @@ -90,7 +90,7 @@ async def start(self) -> None:
),
(
make_url_path_regex(base, "component/(.*)"),
ComponentRequestHandler(registry=ComponentRegistry.instance()),
ComponentRequestHandler(registry=self._runtime.component_registry),
),
]
self._routes = [(re.compile(pattern), handler) for (pattern, handler) in routes]
Expand All @@ -106,7 +106,7 @@ def receive_websocket_from_js(self, payload_from_js: pyodide.ffi.JsProxy):
payload = payload_from_js.to_bytes()

if not isinstance(payload, bytes):
LOGGER.warning(
_LOGGER.warning(
"The WebSocket payload is not of type bytes, but %s", type(payload)
)
return
Expand Down Expand Up @@ -145,7 +145,7 @@ def receive_http(
body: str | bytes,
on_response: Callable[[int, dict, bytes], None],
):
LOGGER.debug("HTTP request (%s %s %s %s)", method, path, headers, body)
_LOGGER.debug("HTTP request (%s %s %s %s)", method, path, headers, body)

url_parse_result = urllib.parse.urlparse(path)
path = url_parse_result.path
Expand Down Expand Up @@ -271,10 +271,10 @@ def on_message(self, payload: str | bytes) -> None:

msg = BackMsg()
msg.ParseFromString(payload)
LOGGER.debug("Received the following back message:\n%s", msg)
_LOGGER.debug("Received the following back message:\n%s", msg)

except Exception as ex:
LOGGER.error(ex)
_LOGGER.error(ex)
self._runtime.handle_backmsg_deserialization_exception(self._session_id, ex)
return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from streamlit.components.v1.components import declare_component
from streamlit.hello import Hello
from streamlit.runtime.runtime import Runtime
from streamlit.runtime.scriptrunner.script_run_context import add_script_run_ctx
from tests.testutil import create_mock_script_run_ctx

from stlite_server.server import Server

Expand All @@ -36,7 +38,7 @@ def setup_server():

async def init_server():
"""Mimic streamlit.web.bootstrap.run()"""
server = Server(filename, None)
server = Server(filename)
await server.start()
data_from_thread["server"] = server
event.set()
Expand All @@ -59,6 +61,10 @@ def start():
raise exception
server = data_from_thread["server"]

add_script_run_ctx(
threading.current_thread(), create_mock_script_run_ctx()
) # Like https://github.com/streamlit/streamlit/blob/1.35.0/lib/tests/streamlit/runtime/caching/cache_resource_api_test.py#L46-L48 # noqa: E501

yield server

server.stop()
Expand Down
2 changes: 1 addition & 1 deletion packages/kernel/src/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { assertStreamlitConfig } from "./types";
// https://github.com/pyodide/pyodide/pull/1859
// https://pyodide.org/en/stable/project/changelog.html#micropip
import STLITE_SERVER_WHEEL from "!!file-loader?name=pypi/[name].[ext]&context=.!../py/stlite-server/dist/stlite_server-0.1.0-py3-none-any.whl"; // TODO: Extract the import statement to an auto-generated file like `_pypi.ts` in JupyterLite: https://github.com/jupyterlite/jupyterlite/blob/f2ecc9cf7189cb19722bec2f0fc7ff5dfd233d47/packages/pyolite-kernel/src/_pypi.ts
import STREAMLIT_WHEEL from "!!file-loader?name=pypi/[name].[ext]&context=.!../py/streamlit/lib/dist/streamlit-1.33.0-cp311-none-any.whl";
import STREAMLIT_WHEEL from "!!file-loader?name=pypi/[name].[ext]&context=.!../py/streamlit/lib/dist/streamlit-1.35.0-cp311-none-any.whl";

// Ref: https://github.com/streamlit/streamlit/blob/1.12.2/frontend/src/lib/UriUtil.ts#L32-L33
const FINAL_SLASH_RE = /\/+$/;
Expand Down
3 changes: 1 addition & 2 deletions packages/kernel/src/worker-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
loadPyodide = pyodideModule.loadPyodide;
} else {
importScripts(pyodideUrl);
loadPyodide = (self as any).loadPyodide;

Check warning on line 32 in packages/kernel/src/worker-runtime.ts

View workflow job for this annotation

GitHub Actions / test-kernel

Unexpected any. Specify a different type
}
return loadPyodide({ ...loadPyodideOptions, indexURL: indexUrl });
}
Expand Down Expand Up @@ -405,12 +405,11 @@
load_config_options(flag_options)

main_script_path = "${entrypoint}"
command_line = None
args = []

prepare(main_script_path, args)

server = Server(main_script_path, command_line)
server = Server(main_script_path)
server.start()
`);
console.debug("Booted up the Streamlit server");
Expand Down
2 changes: 1 addition & 1 deletion packages/mountable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.3",
"@stlite/common-react": "^0.54.2",
"@stlite/kernel": "^0.54.2",
"@streamlit/app": "1.33.0",
"@streamlit/app": "1.35.0",
"@svgr/webpack": "^8.1.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/sharing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@stlite/common-react": "^0.54.2",
"@stlite/kernel": "^0.54.2",
"@stlite/sharing-common": "^0.54.2",
"@streamlit/app": "1.33.0",
"@streamlit/app": "1.35.0",
"@testing-library/react": "^14.1.2",
"@testing-library/user-event": "^14.0.0",
"@types/jest": "^27.4.3",
Expand Down
2 changes: 1 addition & 1 deletion streamlit
Submodule streamlit updated 1860 files
Loading
Loading