|
4 | 4 | from typing import List |
5 | 5 |
|
6 | 6 | import pandas as pd |
7 | | -from streamlit.web.cli import _main_run as streamlit_run |
| 7 | +from streamlit.web import cli as stcli |
8 | 8 |
|
9 | 9 | from . import report as r |
10 | 10 | from .utils import create_folder, generate_footer, is_url |
11 | 11 |
|
12 | 12 |
|
13 | | -def streamlit_run( |
14 | | - file, |
15 | | - args=None, |
16 | | - flag_options=None, |
17 | | - **kwargs |
18 | | -) -> None: |
19 | | - if args is None: |
20 | | - args = [] |
21 | | - |
22 | | - if flag_options is None: |
23 | | - flag_options = {} |
24 | | - |
25 | | - import streamlit.web.bootstrap as bootstrap |
26 | | - from streamlit.runtime.credentials import check_credentials |
27 | | - |
28 | | - bootstrap.load_config_options(flag_options=kwargs) |
29 | | - |
30 | | - check_credentials() |
31 | | - |
32 | | - bootstrap.run(file, False, args, flag_options) |
33 | | - |
34 | | - |
35 | 13 | class StreamlitReportView(r.WebAppReportView): |
36 | 14 | """ |
37 | 15 | A Streamlit-based implementation of the WebAppReportView abstract base class. |
@@ -184,44 +162,28 @@ def run_report(self, output_dir: str = SECTIONS_DIR) -> None: |
184 | 162 | self.report.logger.debug( |
185 | 163 | f"Running Streamlit report from directory: {output_dir}" |
186 | 164 | ) |
187 | | - # command = [ |
188 | | - # sys.executable, # ! will be vuegen main script, not the Python Interpreter |
189 | | - # "-m", |
190 | | - # "streamlit", |
191 | | - # "run", |
192 | | - # os.path.join(output_dir, self.REPORT_MANAG_SCRIPT), |
193 | | - # ] |
194 | | - self.report.logger.debug(sys.executable) |
195 | | - self.report.logger.debug(sys.path) |
| 165 | + # ! using pyinstaller: vuegen main script as executable, not the Python Interpreter |
| 166 | + msg = f"{sys.executable = }" |
| 167 | + self.report.logger.debug(msg) |
196 | 168 | try: |
197 | | - # ! streamlit is not known in packaged app |
198 | | - # self.report.logger.debug(f"Running command: {' '.join(command)}") |
199 | | - # subprocess.run( |
200 | | - # command, |
201 | | - # check=True, |
202 | | - # ) |
| 169 | + # ! streamlit command option is not known in packaged app |
203 | 170 | target_file = os.path.join(output_dir, self.REPORT_MANAG_SCRIPT) |
204 | 171 | self.report.logger.debug( |
205 | 172 | f"Running Streamlit report from file: {target_file}" |
206 | 173 | ) |
207 | | - streamlit_run(target_file) |
208 | | - self.report.logger.info( |
209 | | - f"Running '{self.report.title}' {self.report_type} report." |
210 | | - ) |
211 | | - try: |
212 | | - subprocess.run( |
213 | | - [ |
214 | | - "streamlit", |
215 | | - "run", |
216 | | - os.path.join(output_dir, self.REPORT_MANAG_SCRIPT), |
217 | | - ], |
218 | | - check=True, |
219 | | - ) |
| 174 | + args = [ |
| 175 | + "streamlit", |
| 176 | + "run", |
| 177 | + target_file, |
| 178 | + ] |
| 179 | + sys.argv = args |
| 180 | + |
| 181 | + sys.exit(stcli.main()) |
220 | 182 | except KeyboardInterrupt: |
221 | 183 | print("Streamlit process interrupted.") |
222 | | - except subprocess.CalledProcessError as e: |
223 | | - self.report.logger.error(f"Error running Streamlit report: {str(e)}") |
224 | | - raise |
| 184 | + # except subprocess.CalledProcessError as e: |
| 185 | + # self.report.logger.error(f"Error running Streamlit report: {str(e)}") |
| 186 | + # raise |
225 | 187 | else: |
226 | 188 | # If autorun is False, print instructions for manual execution |
227 | 189 | self.report.logger.info( |
@@ -1003,6 +965,6 @@ def _generate_component_imports(self, component: r.Component) -> List[str]: |
1003 | 965 | component_imports.append("df_index = 1") |
1004 | 966 |
|
1005 | 967 | # Return the list of import statements |
1006 | | - return component_imports |
| 968 | + return component_imports |
1007 | 969 |
|
1008 | 970 | return component_imports |
0 commit comments