Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/process-flowsheet-studio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
pull_request:
paths:
- "app_navigation.py"
- "experimental_links.py"
- "tests/test_navigation_warm_import.py"
- "home.py"
- "welcome.py"
- "requirements.txt"
Expand Down Expand Up @@ -122,6 +124,7 @@ jobs:
tests/test_subflowsheet_schema.py
- name: Run Studio workspace navigation regressions
run: |
python tests/test_navigation_warm_import.py -v
python tests/test_experimental_links.py -v
python tests/test_app_navigation.py -v
python tests/test_studio_navigation.py -v
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ These links automatically enable Experimental mode before routing to the page;
no query parameter or prior visit to the home page is needed. The toggle can
still be turned off afterward.

If a running Streamlit Cloud instance reports an import error immediately after
an update, **Manage app → Reboot app** restarts its Python process and clears
modules retained from the previous version. Refreshing the browser alone does
not restart that process. Direct-link routing is isolated from the older
navigation module to remain compatible during this update.

## Pipeline Hydraulics

The **Pipeline** page provides two native NeqSim calculation paths:
Expand Down
10 changes: 1 addition & 9 deletions app_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import re
from dataclasses import dataclass
from pathlib import Path
from collections.abc import Iterable
from urllib.parse import unquote, urlsplit
from experimental_links import is_experimental_url


APP_ROOT = Path(__file__).resolve().parent
Expand Down Expand Up @@ -93,10 +92,3 @@ def experimental_page_specs() -> tuple[PageSpec, ...]:
if path not in STABLE_PAGE_PATHS
)


def is_experimental_url(url: str | None, experimental_paths: Iterable[str]) -> bool:
"""Recognize a registered experimental URL, including a deployment base path."""
if not url:
return False
pathname = unquote(urlsplit(url).path).rstrip("/").rsplit("/", 1)[-1]
return bool(pathname) and pathname in experimental_paths
12 changes: 12 additions & 0 deletions experimental_links.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""URL policy isolated from the navigation module cached by older deployments."""

from collections.abc import Iterable
from urllib.parse import unquote, urlsplit


def is_experimental_url(url: str | None, experimental_paths: Iterable[str]) -> bool:
"""Recognize a registered experimental URL, including a deployment base path."""
if not url:
return False
pathname = unquote(urlsplit(url).path).rstrip("/").rsplit("/", 1)[-1]
return bool(pathname) and pathname in experimental_paths
2 changes: 1 addition & 1 deletion tests/test_experimental_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import unittest

from app_navigation import is_experimental_url
from experimental_links import is_experimental_url


class ExperimentalLinkTest(unittest.TestCase):
Expand Down
88 changes: 88 additions & 0 deletions tests/test_navigation_warm_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
"""Router regressions for a deployment with the previous navigation module cached."""

import os
from pathlib import Path
import runpy
import sys
from types import ModuleType, SimpleNamespace
import unittest
from unittest.mock import patch


ROOT = Path(__file__).resolve().parents[1]


class Sidebar:
def __enter__(self):
return self

def __exit__(self, *args):
return False


class WarmNavigationImportTest(unittest.TestCase):
def run_router(self, url, initial_state=None):
# Reproduce the pre-PR-136 public API still held in sys.modules.
old_navigation = ModuleType("app_navigation")
old_navigation.experimental_page_specs = lambda: [
SimpleNamespace(path="pages/100_CO2_mechanisticModel.py", title="CO2")
]
old_navigation.stable_page_specs = lambda: [
SimpleNamespace(path="pages/0_TP_flash.py", title="TP Flash")
]
streamlit = ModuleType("streamlit")
streamlit.session_state = dict(initial_state or {})
streamlit.context = SimpleNamespace(url=url)
streamlit.sidebar = Sidebar()
streamlit.divider = lambda: None
streamlit.caption = lambda *args: None
streamlit.toggle = lambda *args, **kwargs: None
executed = []

def page(path, **kwargs):
route = "" if kwargs.get("default") else (
Path(path).stem.split("_", 1)[1]
)
return SimpleNamespace(
url_path=route, run=lambda: executed.append(path)
)

def navigation(groups):
requested = url.rsplit("/", 1)[-1]
pages = [item for group in groups.values() for item in group]
return next(
(item for item in pages if item.url_path == requested), pages[0]
)

streamlit.Page = page
streamlit.navigation = navigation
with patch.dict(sys.modules, {
"app_navigation": old_navigation, "streamlit": streamlit,
}), patch.dict(os.environ):
runpy.run_path(str(ROOT / "welcome.py"), run_name="__main__")
return streamlit.session_state, executed

def test_direct_co2_link_with_previous_module_cached(self):
state, executed = self.run_router(
"https://neqsim.streamlit.app/CO2_mechanisticModel"
)
self.assertTrue(state["experimental_mode"])
self.assertTrue(state["_experimental_mode_toggle"])
self.assertEqual(executed, ["pages/100_CO2_mechanisticModel.py"])

def test_home_with_previous_module_cached(self):
state, executed = self.run_router("https://neqsim.streamlit.app/")
self.assertFalse(state["experimental_mode"])
self.assertEqual(executed, ["home.py"])

def test_explicit_off_survives_rerun_with_previous_module_cached(self):
state, executed = self.run_router(
"https://neqsim.streamlit.app/CO2_mechanisticModel",
{"experimental_mode": False, "_experimental_mode_toggle": False},
)
self.assertFalse(state["experimental_mode"])
self.assertEqual(executed, ["home.py"])


if __name__ == "__main__":
unittest.main()
5 changes: 4 additions & 1 deletion welcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

from app_navigation import (
experimental_page_specs,
is_experimental_url,
stable_page_specs,
)

# Older live processes may still hold the pre-direct-link app_navigation module.
# Import the new policy from its own module instead of that cached module.
from experimental_links import is_experimental_url


EXPERIMENTAL_MODE_KEY = "experimental_mode"
EXPERIMENTAL_MODE_WIDGET_KEY = "_experimental_mode_toggle"
Expand Down
Loading