(main_script_path: str)
| 130 | # function will be called to run the script in lieu of the main script. This |
| 131 | # function simulates the v1 setup using the modern v2 commands (st.navigation) |
| 132 | def _mpa_v1(main_script_path: str) -> None: |
| 133 | from pathlib import Path |
| 134 | |
| 135 | from streamlit.commands.navigation import PageType, _navigation |
| 136 | from streamlit.navigation.page import StreamlitPage |
| 137 | |
| 138 | # Select the folder that should be used for the pages: |
| 139 | resolved_main_script_path: Final = Path(main_script_path).resolve() |
| 140 | pages_folder: Final = resolved_main_script_path.parent / "pages" |
| 141 | |
| 142 | # Read out the my_pages folder and create a page for every script: |
| 143 | pages = sorted( |
| 144 | [ |
| 145 | page |
| 146 | for page in pages_folder.glob("*.py") |
| 147 | if page.name.endswith(".py") |
| 148 | and not page.name.startswith(".") |
| 149 | and page.name != "__init__.py" |
| 150 | ], |
| 151 | key=page_sort_key, |
| 152 | ) |
| 153 | |
| 154 | # Use this script as the main page and |
| 155 | main_page = StreamlitPage(resolved_main_script_path, default=True) |
| 156 | all_pages = [main_page] + [ |
| 157 | StreamlitPage(pages_folder / page.name) for page in pages |
| 158 | ] |
| 159 | # Initialize the navigation with all the pages: |
| 160 | position: Literal["sidebar", "hidden", "top"] = ( |
| 161 | "hidden" |
| 162 | if config.get_option("client.showSidebarNavigation") is False |
| 163 | else "sidebar" |
| 164 | ) |
| 165 | page = _navigation( |
| 166 | cast("list[PageType]", all_pages), |
| 167 | position=position, |
| 168 | expanded=False, |
| 169 | ) |
| 170 | |
| 171 | page.run() |
| 172 | |
| 173 | |
| 174 | class ScriptRunner: |
no test coverage detected
searching dependent graphs…