Skip to content

Commit 79bfbf4

Browse files
Copilotgvegayon
andauthored
fix: address PR review comments from olivia-banks
- Use Pyodide-recommended stlite detection (sys.platform/sys.modules) - Remove duplicate running_in_stlite() definition (F811) - Escape HTML labels with html.escape() in parameter_ui.py - Fix Makefile: UV ?= for env override, smelected typo, inline mkdir - Remove -> None from build_index.py main() - Fix AGENTS.md function contract for render_parameters_with_indent - Fix Excel reset callback to use consistent model_key Agent-Logs-Url: https://github.com/EpiForeSITE/epiworldPythonStreamlit/sessions/60bec289-6a09-4711-a403-13e7f0eb4742 Co-authored-by: gvegayon <893619+gvegayon@users.noreply.github.com>
1 parent 881988e commit 79bfbf4

5 files changed

Lines changed: 13 additions & 15 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ tests.
108108
- `load_model_from_file(filepath: str) -> object`
109109
- `load_model_params(model_file_path: str, uploaded_excel=None) -> dict`
110110
- `flatten_dict(d, level=0)`
111-
- `render_parameters_with_indent(param_dict, params, label_overrides) -> None`
111+
- `render_parameters_with_indent(param_dict, params, model_id) -> None`
112112
- `reset_parameters_to_defaults(param_dict, params, model_id) -> None`
113113
- `render_sections(sections) -> None`
114114

Makefile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
UV := uv
1+
UV ?= uv
22

33
STLITE_VER ?= 0.86.0
44
PORT ?= 8000
@@ -33,7 +33,8 @@ install: ## Install Python dependencies with uv
3333
.PHONY: build-html
3434
build-html: $(INDEX_HTML) ## Generate build/index.html (stlite WASM entry point)
3535

36-
$(INDEX_HTML): $(STLITE_INPUTS) | $(BUILD_DIR)
36+
$(INDEX_HTML): $(STLITE_INPUTS)
37+
@mkdir -p $(BUILD_DIR)
3738
@echo "Generating $(INDEX_HTML) (stlite v$(STLITE_VER))"
3839
$(UV) run python scripts/build_index.py \
3940
--app $(APP_PY) \
@@ -42,14 +43,11 @@ $(INDEX_HTML): $(STLITE_INPUTS) | $(BUILD_DIR)
4243
--js $(STLITE_JS) \
4344
--title "EpiCON Cost Calculator"
4445
@echo "Copying static assets into $(BUILD_DIR)/"
45-
@for dir in utils config styles models smelected examples; do \
46+
@for dir in utils config styles models selected examples; do \
4647
if [ -d "$$dir" ]; then cp -r "$$dir" "$(BUILD_DIR)/$$dir"; fi; \
4748
done
4849
@echo "Build artefacts written to $(BUILD_DIR)/"
4950

50-
$(BUILD_DIR):
51-
mkdir -p $@
52-
5351
.PHONY: dev
5452
dev: ## Run normal Streamlit locally
5553
$(UV) run streamlit run $(APP_PY)

app.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23
import yaml
34
import streamlit as st
45
import inspect
@@ -46,7 +47,7 @@ def normalize_yaml_defaults(raw_yaml: object) -> dict:
4647

4748
def running_in_stlite() -> bool:
4849
"""Return True when the app is running inside stlite/Pyodide."""
49-
return os.path.abspath(__file__).startswith("/home/pyodide/")
50+
return sys.platform == "emscripten" or "pyodide" in sys.modules
5051

5152

5253
def coerce_like_default(value: object, default: object) -> object:
@@ -167,7 +168,7 @@ def normalize_stlite_params(params: dict, defaults: dict) -> dict:
167168

168169
def handle_reset_excel() -> None:
169170
"""Reset Excel parameters and output labels to defaults."""
170-
reset_parameters_to_defaults(editable_defaults, params, uploaded_excel_model.name)
171+
reset_parameters_to_defaults(editable_defaults, params, model_key)
171172
if current_headers:
172173
for col_letter, default_text in current_headers.items():
173174
st.session_state[f"label_override_{col_letter}"] = default_text
@@ -342,7 +343,3 @@ def handle_reset_python() -> None:
342343

343344
sections = model_module.build_sections(results)
344345
render_sections(sections)
345-
346-
def running_in_stlite() -> bool:
347-
"""Return True when the app is running inside stlite/Pyodide."""
348-
return os.path.abspath(__file__).startswith("/home/pyodide/")

scripts/build_index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def build_html(
113113
"""
114114

115115

116-
def main() -> None:
116+
def main():
117117
"""Generate the stlite index.html file."""
118118
args = parse_args()
119119

utils/parameter_ui.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import html
2+
13
import streamlit as st
24

35

@@ -24,10 +26,11 @@ def render_parameters_with_indent(
2426
clean_label = label.lstrip("\t")
2527

2628
if value is None:
29+
safe_label = html.escape(clean_label)
2730
st.sidebar.markdown(
2831
(
2932
f"<div style='margin-left:{indent_level * 1.5}em; "
30-
f"font-weight:600;'>{clean_label}</div>"
33+
f"font-weight:600;'>{safe_label}</div>"
3134
),
3235
unsafe_allow_html=True,
3336
)

0 commit comments

Comments
 (0)