Skip to content

Commit c8eac52

Browse files
committed
🚧 start testing of bundeling for quarto
- some form of binaries have to be passed, along addtional dependencies
1 parent 1d23016 commit c8eac52

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/vuegen/quarto_reportview.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import subprocess
3+
import sys
34
from pathlib import Path
45
from typing import List
56

@@ -20,6 +21,12 @@ class QuartoReportView(r.ReportView):
2021

2122
def __init__(self, report: r.Report, report_type: r.ReportType):
2223
super().__init__(report=report, report_type=report_type)
24+
self.BUNDLED_EXECUTION = False
25+
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
26+
self.report.logger.info("running in a PyInstaller bundle")
27+
self.BUNDLED_EXECUTION = True
28+
else:
29+
self.report.logger.info("running in a normal Python process")
2330

2431
def generate_report(
2532
self, output_dir: str = BASE_DIR, static_dir: str = STATIC_FILES_DIR
@@ -155,22 +162,32 @@ def run_report(self, output_dir: str = BASE_DIR) -> None:
155162
The folder where the report was generated (default is 'sections').
156163
"""
157164
try:
158-
subprocess.run(
159-
["quarto", "render", os.path.join(output_dir, f"{self.BASE_DIR}.qmd")],
160-
check=True,
161-
)
162-
if self.report_type == r.ReportType.JUPYTER:
165+
if not self.BUNDLED_EXECUTION:
163166
subprocess.run(
164167
[
165168
"quarto",
166-
"convert",
169+
"render",
167170
os.path.join(output_dir, f"{self.BASE_DIR}.qmd"),
168171
],
169172
check=True,
170173
)
171-
self.report.logger.info(
172-
f"'{self.report.title}' '{self.report_type}' report rendered"
173-
)
174+
if self.report_type == r.ReportType.JUPYTER:
175+
subprocess.run(
176+
[
177+
"quarto",
178+
"convert",
179+
os.path.join(output_dir, f"{self.BASE_DIR}.qmd"),
180+
],
181+
check=True,
182+
)
183+
self.report.logger.info(
184+
f"'{self.report.title}' '{self.report_type}' report rendered"
185+
)
186+
else:
187+
self.report.logger.info(
188+
f"Quarto report '{self.report.title}' '{self.report_type}' cannot "
189+
"be run in a PyInstaller bundle"
190+
)
174191
except subprocess.CalledProcessError as e:
175192
self.report.logger.error(
176193
f"Error running '{self.report.title}' {self.report_type} report: {str(e)}"

0 commit comments

Comments
 (0)