Skip to content

Commit

Permalink
Compat 1.38.0 (#233)
Browse files Browse the repository at this point in the history
* Update _compat.py (#232)

* Fix _compat.py

* Add test matrix item

* Fix

* Update mypy

* Improve type annotation and drop Python 3.8 support

---------

Co-authored-by: kai gouthro <[email protected]>
  • Loading branch information
whitphx and kaigouthro authored Oct 23, 2024
1 parent 22a2a20 commit 3b42e85
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 48 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11"]
streamlit-version: [null]
include:
# Test with streamlit <1.4.0 and >=1.4.0. See https://github.com/whitphx/streamlit-server-state/issues/64
Expand All @@ -39,6 +39,9 @@ jobs:
# Test with streamlit >=1.18.0. See https://github.com/whitphx/streamlit-server-state/issues/171
- python-version: 3.9
streamlit-version: 1.18.0
# Test with streamlit >=1.38.0. See https://github.com/whitphx/streamlit-server-state/pull/232
- python-version: 3.9
streamlit-version: 1.38.0

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion app_chat_rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
if "rooms" not in server_state:
server_state["rooms"] = []

rooms = server_state["rooms"]
rooms: list[str] = server_state["rooms"]

room = st.sidebar.radio("Select room", rooms)

Expand Down
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[mypy]
python_version = 3.8
python_version = 3.9
ignore_missing_imports = True
79 changes: 43 additions & 36 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 16 additions & 9 deletions streamlit_server_state/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,36 @@


try:
from streamlit.runtime.scriptrunner.script_run_context import (
from streamlit.runtime.scriptrunner_utils.script_run_context import (
SCRIPT_RUN_CONTEXT_ATTR_NAME,
ScriptRunContext,
)
except ModuleNotFoundError:
# streamlit < 1.12.0
# streamlit < 1.38.0
try:
from streamlit.scriptrunner.script_run_context import ( # type: ignore
from streamlit.runtime.scriptrunner.script_run_context import ( # type: ignore
SCRIPT_RUN_CONTEXT_ATTR_NAME,
ScriptRunContext,
)
except ModuleNotFoundError:
# streamlit < 1.8
# streamlit < 1.12.0
try:
from streamlit.script_run_context import ( # type: ignore
from streamlit.scriptrunner.script_run_context import ( # type: ignore
SCRIPT_RUN_CONTEXT_ATTR_NAME,
ScriptRunContext,
)
except ModuleNotFoundError:
from streamlit.report_thread import ( # type: ignore # isort:skip
REPORT_CONTEXT_ATTR_NAME as SCRIPT_RUN_CONTEXT_ATTR_NAME,
ReportContext as ScriptRunContext,
)
# streamlit < 1.8
try:
from streamlit.script_run_context import ( # type: ignore
SCRIPT_RUN_CONTEXT_ATTR_NAME,
ScriptRunContext,
)
except ModuleNotFoundError:
from streamlit.report_thread import ( # type: ignore # isort:skip
REPORT_CONTEXT_ATTR_NAME as SCRIPT_RUN_CONTEXT_ATTR_NAME,
ReportContext as ScriptRunContext,
)

try:
from streamlit.runtime.scriptrunner import get_script_run_ctx
Expand Down

0 comments on commit 3b42e85

Please sign in to comment.