Skip to content

fix(streamlit): don't require tornado on streamlit >= 1.57 - #744

Open
MohammadHijjawi97 wants to merge 1 commit into
Kanaries:mainfrom
MohammadHijjawi97:fix-streamlit-157-compat
Open

MohammadHijjawi97 wants to merge 1 commit into
Kanaries:mainfrom
MohammadHijjawi97:fix-streamlit-157-compat

Conversation

@MohammadHijjawi97

Copy link
Copy Markdown

Fixes #743

Streamlit 1.57 moved its server to Starlette/uvicorn and dropped its Tornado dependency. Main already handles part of #743: it has a fallback for make_url_path_regex and registers a Starlette route. But pygwalker/communications/streamlit_comm.py still imports tornado unconditionally. With a current Streamlit (e.g. 1.64) and no tornado installed, from pygwalker.api.streamlit import StreamlitRenderer still fails with ModuleNotFoundError: No module named 'tornado'.

Changes:

  • Import tornado optionally, and define PygwalkerHandler only when tornado is available.
  • Without tornado, _register_tornado_handler() returns False, so _hack_streamlit_server_impl falls through to the existing Starlette route registration.
  • Regression test: with tornado blocked, streamlit_comm and pygwalker.api.streamlit import cleanly and the route regex helper produces the expected pattern.

Testing:

  • pytest tests/test_integration_apis.py: 30 passed with streamlit 1.56.0 (tornado installed) and with streamlit 1.64.0 (no tornado). The new test fails without the fix.
  • Ran streamlit run with StreamlitRenderer(df).explorer() on 1.56 and on 1.64. The explorer loads and POST /_stcore/_pygwalker/comm/<gid> returns a successful response in both.
  • ruff check and ruff format --check are clean on the changed files.

Streamlit 1.57 moved its server to Starlette/uvicorn and dropped the
Tornado dependency. streamlit_comm imported tornado unconditionally, so
`from pygwalker.api.streamlit import StreamlitRenderer` still failed on
recent Streamlit (ModuleNotFoundError: tornado) even after the
make_url_path_regex fallback. Import tornado optionally and skip the
Tornado handler registration when it is unavailable, so the existing
Starlette route registration is used instead.

Fixes Kanaries#743
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ImportError: cannot import name 'make_url_path_regex' from 'streamlit.web.server.server_util'

1 participant