Skip to content

Commit 715081b

Browse files
sayalaruanoenryH
andauthored
Add Quarto checks and output dire parameters
* 🦺 Refactor: add quarto_checks argument * 🐛 Fix: Correct validation for revelajs and jupyter notebooks * 🎨 Format: add config_path parameter and change the strcuture of the function to print completion message * 🎨 Format: add black format * 🎨 Format: order main imports * 🐛 Fix: fix typo for quarto_checks * 🐛 Fix: add quarto_checks into the report_generator funcrtion * 🎨 Format: apply black format and fix quarto_checks typo * 🐛 Fix: fix quarto_checks typo in quarto_review.py * 🐛 Fix quarto_checks typo * 🐛 Fix: add -qt_checks parameter into the CICD file * 🐛 Fix: add html suffix for jupyter notebook for initial validation * 🐛 fix import and specify that GUI execution checks tinytex and chromium * ✨ Feat: add output_dir as an argument * 🐛 Fix: correct output_dir typo * 🐛 Fix: add -qt_checks parameter in the CICD processs for the pdf report using a config file --------- Co-authored-by: Henry Webel <heweb@dtu.dk>
1 parent 129d762 commit 715081b

File tree

6 files changed

+78
-25
lines changed

6 files changed

+78
-25
lines changed

.github/workflows/cdci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ jobs:
7272
- name: quarto pdf report
7373
run: |
7474
cd docs
75-
vuegen -dir example_data/Earth_microbiome_vuegen_demo_notebook -rt pdf
76-
vuegen -c example_data/Earth_microbiome_vuegen_demo_notebook/Earth_microbiome_vuegen_demo_notebook_config.yaml -rt pdf
75+
vuegen -dir example_data/Earth_microbiome_vuegen_demo_notebook -rt pdf -qt_checks
76+
vuegen -c example_data/Earth_microbiome_vuegen_demo_notebook/Earth_microbiome_vuegen_demo_notebook_config.yaml -rt pdf -qt_checks
7777
- name: quarto docx report
7878
run: |
7979
cd docs

gui/app.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# from vuegen.__main__ import main
3838
from vuegen.report import ReportType
39-
from vuegen.utils import get_logger, print_completion_message
39+
from vuegen.utils import get_completion_message, get_logger
4040

4141
customtkinter.set_appearance_mode("system")
4242
customtkinter.set_default_color_theme("dark-blue")
@@ -159,6 +159,7 @@ def inner():
159159
kwargs["logger"].info("logfile: %s", log_file)
160160
kwargs["logger"].debug("sys.path: %s", sys.path)
161161
kwargs["logger"].debug("PATH (in app): %s ", os.environ["PATH"])
162+
kwargs["quarto_checks"] = True # for gui check local quarto installation
162163
report_dir, gen_config_path = report_generator.get_report(**kwargs)
163164
kwargs["logger"].info("Report generated at %s", report_dir)
164165
messagebox.showinfo(
@@ -169,7 +170,7 @@ def inner():
169170
f"\n\nConfiguration file at:\n{gen_config_path}",
170171
)
171172
global hash_config_app # ! fix this
172-
print_completion_message(report_type.get())
173+
get_completion_message(report_type.get())
173174
if hash(yaml.dump(config_app)) != hash_config_app:
174175
with open(config_file, "w", encoding="utf-8") as f:
175176
yaml.dump(config_app, f)

src/vuegen/__main__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pathlib import Path
33

44
from vuegen import report_generator
5-
from vuegen.utils import get_logger, get_parser, print_completion_message
5+
from vuegen.utils import get_completion_message, get_logger, get_parser
66

77

88
def main():
@@ -14,7 +14,9 @@ def main():
1414
config_path = args.config
1515
dir_path = args.directory
1616
report_type = args.report_type
17+
output_dir = args.output_directory
1718
streamlit_autorun = args.streamlit_autorun
19+
quarto_cheks = args.quarto_checks
1820

1921
# Determine the report name for logger suffix
2022
if config_path:
@@ -38,18 +40,21 @@ def main():
3840
# Initialize logger
3941
logger, logfile = get_logger(f"{logger_suffix}")
4042
logger.info("logfile: %s", logfile)
43+
4144
# Generate the report
4245
_, _ = report_generator.get_report(
4346
report_type=report_type,
4447
logger=logger,
4548
config_path=config_path,
4649
dir_path=dir_path,
50+
output_dir=output_dir,
4751
streamlit_autorun=streamlit_autorun,
52+
quarto_checks=quarto_cheks,
4853
)
4954

5055
# Print completion message
5156
# ! Could use now report_dir and config_path as information
52-
print_completion_message(report_type)
57+
print(get_completion_message(report_type, config_path))
5358

5459

5560
if __name__ == "__main__":

src/vuegen/quarto_reportview.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@ class QuartoReportView(r.ReportView):
2020
BASE_DIR = Path("quarto_report")
2121
STATIC_FILES_DIR = BASE_DIR / "static"
2222

23-
def __init__(self, report: r.Report, report_type: r.ReportType):
23+
def __init__(
24+
self,
25+
report: r.Report,
26+
report_type: r.ReportType,
27+
quarto_checks: bool = False,
28+
):
2429
super().__init__(report=report, report_type=report_type)
30+
self.quarto_checks = quarto_checks
2531
self.BUNDLED_EXECUTION = False
2632
self.quarto_path = "quarto"
2733
# self.env_vars = os.environ.copy()
@@ -186,11 +192,15 @@ def run_report(self, output_dir: str = BASE_DIR) -> None:
186192
self.report.logger.info(
187193
f"Running '{self.report.title}' '{self.report_type}' report with {args!r}"
188194
)
189-
if self.report_type in [
190-
r.ReportType.PDF,
191-
r.ReportType.DOCX,
192-
r.ReportType.ODT,
193-
]:
195+
if (
196+
self.report_type
197+
in [
198+
r.ReportType.PDF,
199+
r.ReportType.DOCX,
200+
r.ReportType.ODT,
201+
]
202+
and self.quarto_checks
203+
):
194204
subprocess.run(
195205
[self.quarto_path, "install", "tinytex", "--no-prompt"],
196206
check=True,
@@ -204,11 +214,17 @@ def run_report(self, output_dir: str = BASE_DIR) -> None:
204214
args,
205215
check=True,
206216
)
207-
out_path = file_path_to_qmd.with_suffix(f".{self.report_type.lower()}")
208-
if self.report_type in [r.ReportType.REVEALJS, r.ReportType.JUPYTER]:
217+
if self.report_type == r.ReportType.REVEALJS:
218+
out_path = file_path_to_qmd.with_name(
219+
f"{file_path_to_qmd.stem}_revealjs.html"
220+
)
221+
elif self.report_type == r.ReportType.JUPYTER:
209222
out_path = file_path_to_qmd.with_suffix(".html")
223+
else:
224+
out_path = file_path_to_qmd.with_suffix(f".{self.report_type.lower()}")
210225
if not out_path.exists():
211226
raise FileNotFoundError(f"Report file could not be created: {out_path}")
227+
212228
if self.report_type == r.ReportType.JUPYTER:
213229
args = [self.quarto_path, "convert", str(file_path_to_qmd)]
214230
subprocess.run(

src/vuegen/report_generator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def get_report(
1616
config_path: str = None,
1717
dir_path: str = None,
1818
streamlit_autorun: bool = False,
19+
quarto_checks: bool = False,
1920
output_dir: Path = None,
2021
) -> tuple[str, str]:
2122
"""
@@ -97,7 +98,9 @@ def get_report(
9798
)
9899
report_dir = output_dir / "quarto_report"
99100
static_files_dir = report_dir / "static"
100-
quarto_report = QuartoReportView(report=report, report_type=report_type)
101+
quarto_report = QuartoReportView(
102+
report=report, report_type=report_type, quarto_checks=quarto_checks
103+
)
101104
quarto_report.generate_report(
102105
output_dir=report_dir, static_dir=static_files_dir
103106
)

src/vuegen/utils.py

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,27 @@ def get_parser(prog_name: str, others: dict = {}) -> argparse.Namespace:
225225
default="streamlit",
226226
help="Type of the report to generate (streamlit, html, pdf, docx, odt, revealjs, pptx, or jupyter).",
227227
)
228+
parser.add_argument(
229+
"-output_dir",
230+
"--output_directory",
231+
type=str,
232+
default=None,
233+
help="Path to the output directory for the generated report.",
234+
)
228235
parser.add_argument(
229236
"-st_autorun",
230237
"--streamlit_autorun",
231238
action="store_true", # Automatically sets True if the flag is passed
232239
default=False,
233240
help="Automatically run the Streamlit app after report generation.",
234241
)
235-
242+
parser.add_argument(
243+
"-qt_checks",
244+
"--quarto_checks",
245+
action="store_true", # Automatically sets True if the flag is passed
246+
default=False,
247+
help="Check if Quarto is installed and available for report generation.",
248+
)
236249
# Parse arguments
237250
return parser
238251

@@ -731,14 +744,26 @@ def get_logger(
731744
return logger, log_file
732745

733746

734-
def print_completion_message(report_type: str):
747+
def get_completion_message(report_type: str, config_path: str) -> str:
735748
"""
736-
Prints a formatted completion message after report generation.
749+
Generate a formatted completion message after report generation.
750+
751+
Parameters
752+
----------
753+
report_type : str
754+
The type of report generated (e.g., "streamlit", "html").
755+
config_path : str
756+
The path to the configuration file used for generating the report.
757+
758+
Returns
759+
-------
760+
str
761+
A formatted string containing the completion message.
737762
"""
738763
border = "─" * 65 # Creates a separator line
764+
739765
if report_type == "streamlit":
740-
print(
741-
"""🚀 Streamlit Report Generated!
766+
message = f"""🚀 Streamlit Report Generated!
742767
743768
📂 All scripts to build the Streamlit app are available at:
744769
streamlit_report/sections
@@ -750,11 +775,12 @@ def print_completion_message(report_type: str):
750775
751776
🛠️ Advanced users can modify the Python scripts directly in:
752777
streamlit_report/sections
778+
779+
⚙️ Configuration file used:
780+
{config_path}
753781
"""
754-
)
755782
else:
756-
print(
757-
f"""🚀 {report_type.capitalize()} Report Generated!
783+
message = f"""🚀 {report_type.capitalize()} Report Generated!
758784
759785
📂 Your {report_type} report is available at:
760786
quarto_report
@@ -763,10 +789,12 @@ def print_completion_message(report_type: str):
763789
764790
🛠️ Advanced users can modify the report template directly in:
765791
quarto_report/quarto_report.qmd
792+
793+
⚙️ Configuration file used:
794+
{config_path}
766795
"""
767-
)
768796

769-
print(border)
797+
return f"{message}\n{border}"
770798

771799

772800
## REPORT FORMATTING

0 commit comments

Comments
 (0)