Skip to content

Commit

Permalink
Removed external library for version checking and made rerun_scope an…
Browse files Browse the repository at this point in the history
… optional Literal parameter
  • Loading branch information
Muhammad Salman Razzaq committed Aug 5, 2024
1 parent 4b4df84 commit 90bf688
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 30 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
streamlit-version: ${{ matrix.streamlit-version }}
importlib-metadata-version: '8.2.0'

- run: playwright install

Expand Down
14 changes: 2 additions & 12 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,12 @@

import requests
import streamlit as st
import importlib_metadata
from streamlit_searchbox import st_searchbox

logging.getLogger("streamlit_searchbox").setLevel(logging.DEBUG)

st.set_page_config(layout="centered", page_title="Searchbox Demo")

# Check the version of Streamlit
def get_streamlit_version():
try:
version = importlib_metadata.version("streamlit")
return version
except importlib_metadata.PackageNotFoundError:
return None

def search_wikipedia_ids(searchterm: str) -> List[tuple[str, Any]]:
"""
function with list of tuples (label:str, value:any)
Expand Down Expand Up @@ -301,9 +292,8 @@ def search_kwargs(searchterm: str, **kwargs) -> List[str]:
st.write(manual)

with fragment_example:
# Only pass scope if the version is >= 1.37
version = get_streamlit_version()
if version and version >= "1.37":
# Only pass scope if the version is >= 1.37
if st.__version__ >= "1.37":


if "app_runs" not in st.session_state:
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# version 1.37 reruns lead to constant iFrame resets
# version 1.35/1.36 also have reset issues but less frequent
"streamlit >= 1.0",
"importlib-metadata"
],
extras_require={
"tests": [
Expand Down
21 changes: 5 additions & 16 deletions streamlit_searchbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import streamlit as st
import streamlit.components.v1 as components
import importlib_metadata


try:
Expand All @@ -21,15 +20,6 @@
# conditional import for streamlit version <1.27
from streamlit import experimental_rerun as rerun # type: ignore

# Check the version of Streamlit
def get_streamlit_version():
try:
version = importlib_metadata.version("streamlit")
return version
except importlib_metadata.PackageNotFoundError:
return None

print("streamlit version:", get_streamlit_version())

# point to build directory
parent_dir = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -89,7 +79,7 @@ def _process_search(
key: str,
searchterm: str,
rerun_on_update: bool,
rerun_scope: str,
rerun_scope: Literal["app", "fragment"] = "app",
**kwargs,
) -> None:
# nothing changed, avoid new search
Expand All @@ -107,8 +97,8 @@ def _process_search(

if rerun_on_update:
# Only pass scope if the version is >= 1.37
version = get_streamlit_version()
if version and version >= "1.37":

if st.__version__ >= "1.37":
rerun(scope=rerun_scope) # Pass scope if present
else:
rerun()
Expand Down Expand Up @@ -194,7 +184,7 @@ def st_searchbox(
style_absolute: bool = False,
style_overrides: StyleOverrides | None = None,
key: str = "searchbox",
rerun_scope: str = "app",
rerun_scope: Literal["app", "fragment"] = "app",
**kwargs,
) -> Any:
"""
Expand Down Expand Up @@ -288,8 +278,7 @@ def st_searchbox(

if rerun_on_update:
# Only pass scope if the version is >= 1.37
version = get_streamlit_version()
if version and version >= "1.37":
if st.__version__ >= "1.37":
rerun(scope=rerun_scope) # Pass scope if present
else:
rerun()
Expand Down

0 comments on commit 90bf688

Please sign in to comment.