Skip to content

Commit d874d39

Browse files
committed
✨ start streamlit without subprocess - runs from self-contained app
1 parent 9bc0177 commit d874d39

File tree

1 file changed

+17
-55
lines changed

1 file changed

+17
-55
lines changed

src/vuegen/streamlit_reportview.py

Lines changed: 17 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,12 @@
44
from typing import List
55

66
import pandas as pd
7-
from streamlit.web.cli import _main_run as streamlit_run
7+
from streamlit.web import cli as stcli
88

99
from . import report as r
1010
from .utils import create_folder, generate_footer, is_url
1111

1212

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-
3513
class StreamlitReportView(r.WebAppReportView):
3614
"""
3715
A Streamlit-based implementation of the WebAppReportView abstract base class.
@@ -184,44 +162,28 @@ def run_report(self, output_dir: str = SECTIONS_DIR) -> None:
184162
self.report.logger.debug(
185163
f"Running Streamlit report from directory: {output_dir}"
186164
)
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)
196168
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
203170
target_file = os.path.join(output_dir, self.REPORT_MANAG_SCRIPT)
204171
self.report.logger.debug(
205172
f"Running Streamlit report from file: {target_file}"
206173
)
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())
220182
except KeyboardInterrupt:
221183
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
225187
else:
226188
# If autorun is False, print instructions for manual execution
227189
self.report.logger.info(
@@ -1003,6 +965,6 @@ def _generate_component_imports(self, component: r.Component) -> List[str]:
1003965
component_imports.append("df_index = 1")
1004966

1005967
# Return the list of import statements
1006-
return component_imports
968+
return component_imports
1007969

1008970
return component_imports

0 commit comments

Comments
 (0)