Skip to content

Commit 9e63cbe

Browse files
committed
fix(streamlit): read bootstrap settings from secrets and env
1 parent 42799bb commit 9e63cbe

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

streamlit_app.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,27 @@ def _is_truthy(v: str | None) -> bool:
8484
return str(v).strip().lower() in {"1", "true", "yes", "on"}
8585

8686

87+
def _setting(name: str) -> str | None:
88+
# Prefer real environment variables, then Streamlit secrets for Cloud deploys.
89+
raw = os.environ.get(name)
90+
if raw is not None:
91+
return raw
92+
try:
93+
sec = st.secrets.get(name)
94+
except (AttributeError, FileNotFoundError, OSError, RuntimeError):
95+
sec = None
96+
if sec is None:
97+
return None
98+
return str(sec)
99+
100+
87101
def _on_streamlit_cloud() -> bool:
88102
# Streamlit Cloud exposes this in hosted apps.
89103
return _is_truthy(os.environ.get("STREAMLIT_SHARING_MODE"))
90104

91105

92106
def _default_bool_env(name: str, cloud_default: bool, local_default: bool) -> bool:
93-
raw = os.environ.get(name)
107+
raw = _setting(name)
94108
if raw is not None:
95109
return _is_truthy(raw)
96110
return cloud_default if _on_streamlit_cloud() else local_default
@@ -115,7 +129,7 @@ def _bootstrap_resale_if_missing(default_path: str) -> str:
115129
local_default=False,
116130
)
117131
if auto_fetch:
118-
max_rows_raw = os.environ.get("SINGAPORE_EDA_BOOTSTRAP_MAX_ROWS", "20000")
132+
max_rows_raw = _setting("SINGAPORE_EDA_BOOTSTRAP_MAX_ROWS") or "20000"
119133
try:
120134
max_rows = max(1000, int(str(max_rows_raw).strip()))
121135
except ValueError:

0 commit comments

Comments
 (0)