Skip to content

Commit baa0292

Browse files
authored
Merge branch 'main' into test_all_os
2 parents f8cbb6c + 954b838 commit baa0292

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/vuegen/quarto_reportview.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@ class QuartoReportView(r.ReportView):
1515
A ReportView subclass for generating Quarto reports.
1616
"""
1717

18-
BASE_DIR = "quarto_report"
19-
STATIC_FILES_DIR = Path(BASE_DIR) / "static"
18+
BASE_DIR = Path("quarto_report")
19+
STATIC_FILES_DIR = BASE_DIR / "static"
2020

2121
def __init__(self, report: r.Report, report_type: r.ReportType):
2222
super().__init__(report=report, report_type=report_type)
2323

2424
def generate_report(
25-
self, output_dir: str = BASE_DIR, static_dir: str = STATIC_FILES_DIR
25+
self, output_dir: Path = BASE_DIR, static_dir: Path = STATIC_FILES_DIR
2626
) -> None:
2727
"""
2828
Generates the qmd file of the quarto report. It creates code for rendering each section and its subsections with all components.
2929
3030
Parameters
3131
----------
32-
output_dir : str, optional
32+
output_dir : Path, optional
3333
The folder where the generated report files will be saved (default is BASE_DIR).
34-
static_dir : str, optional
34+
static_dir : Path, optional
3535
The folder where the static files will be saved (default is STATIC_FILES_DIR).
3636
"""
3737
self.report.logger.debug(
@@ -154,15 +154,15 @@ def run_report(self, output_dir: str = BASE_DIR) -> None:
154154
"""
155155
try:
156156
subprocess.run(
157-
["quarto", "render", Path(output_dir) / f"{self.BASE_DIR}.qmd"],
157+
["quarto", "render", str(Path(output_dir) / f"{self.BASE_DIR}.qmd")],
158158
check=True,
159159
)
160160
if self.report_type == r.ReportType.JUPYTER:
161161
subprocess.run(
162162
[
163163
"quarto",
164164
"convert",
165-
Path(output_dir) / f"{self.BASE_DIR}.qmd",
165+
str(Path(output_dir) / f"{self.BASE_DIR}.qmd"),
166166
],
167167
check=True,
168168
)
@@ -425,7 +425,7 @@ def _generate_plot_content(
425425
plot_content.append(self._generate_plot_code(plot))
426426
if is_report_static:
427427
plot_content.append(
428-
f"""fig_plotly.write_image("{static_plot_path.resolve()}")\n```\n"""
428+
f"""fig_plotly.write_image("{static_plot_path.resolve().as_posix()}")\n```\n"""
429429
)
430430
plot_content.append(self._generate_image_content(static_plot_path))
431431
else:
@@ -434,7 +434,7 @@ def _generate_plot_content(
434434
plot_content.append(self._generate_plot_code(plot))
435435
if is_report_static:
436436
plot_content.append(
437-
f"""fig_altair.save("{static_plot_path.resolve()}")\n```\n"""
437+
f"""fig_altair.save("{static_plot_path.resolve().as_posix()}")\n```\n"""
438438
)
439439
plot_content.append(self._generate_image_content(static_plot_path))
440440
else:
@@ -507,7 +507,7 @@ def _generate_plot_code(self, plot, output_file="") -> str:
507507
plot_json = response.text\n"""
508508
else: # If it's a local file
509509
plot_code += f"""
510-
with open('{Path("..") / plot.file_path}', 'r') as plot_file:
510+
with open('{(Path("..") / plot.file_path).as_posix()}', 'r') as plot_file:
511511
plot_json = plot_file.read()\n"""
512512
# Add specific code for each visualization tool
513513
if plot.plot_type == r.PlotType.PLOTLY:
@@ -585,7 +585,7 @@ def _generate_dataframe_content(self, dataframe, is_report_static) -> List[str]:
585585
# Load the DataFrame using the correct function
586586
read_function = read_function_mapping[file_extension]
587587
dataframe_content.append(
588-
f"""df = pd.{read_function.__name__}('{file_path}')"""
588+
f"""df = pd.{read_function.__name__}('{file_path.as_posix()}')\n"""
589589
)
590590

591591
# Display the dataframe
@@ -642,7 +642,7 @@ def _generate_markdown_content(self, markdown) -> List[str]:
642642
else: # If it's a local file
643643
markdown_content.append(
644644
f"""
645-
with open('{Path("..") / markdown.file_path}', 'r') as markdown_file:
645+
with open('{(Path("..") / markdown.file_path).as_posix()}', 'r') as markdown_file:
646646
markdown_content = markdown_file.read()\n"""
647647
)
648648

@@ -765,7 +765,7 @@ def _show_dataframe(
765765
# Generate path for the DataFrame image
766766
df_image = Path(static_dir) / f"{dataframe.title.replace(' ', '_')}.png"
767767
dataframe_content.append(
768-
f"df.dfi.export('{Path(df_image).resolve()}', max_rows=10, max_cols=5)\n```\n"
768+
f"df.dfi.export('{Path(df_image).resolve().as_posix()}', max_rows=10, max_cols=5)\n```\n"
769769
)
770770
# Use helper method to add centered image content
771771
dataframe_content.append(self._generate_image_content(df_image))

src/vuegen/streamlit_reportview.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ def _generate_plot_code(self, plot) -> str:
530530
plot_json = json.loads(response.text)\n"""
531531
else: # If it's a local file
532532
plot_code = f"""
533-
with open('{Path(plot.file_path)}', 'r') as plot_file:
533+
with open('{Path(plot.file_path).as_posix()}', 'r') as plot_file:
534534
plot_json = json.load(plot_file)\n"""
535535

536536
# Add specific code for each visualization tool
@@ -594,7 +594,7 @@ def _generate_dataframe_content(self, dataframe) -> List[str]:
594594
# Load the DataFrame using the correct function
595595
read_function = read_function_mapping[file_extension]
596596
dataframe_content.append(
597-
f"""df = pd.{read_function.__name__}('{dataframe.file_path}')"""
597+
f"""df = pd.{read_function.__name__}('{dataframe.file_path}')\n"""
598598
)
599599

600600
# Displays a DataFrame using AgGrid with configurable options.
@@ -673,7 +673,7 @@ def _generate_markdown_content(self, markdown) -> List[str]:
673673
else: # If it's a local file
674674
markdown_content.append(
675675
f"""
676-
with open('{Path("..") / markdown.file_path}', 'r') as markdown_file:
676+
with open('{(Path("..") / markdown.file_path).as_posix()}', 'r') as markdown_file:
677677
markdown_content = markdown_file.read()\n"""
678678
)
679679
# Code to display md content
@@ -733,7 +733,7 @@ def _generate_html_content(self, html) -> List[str]:
733733
# If it's a local file
734734
html_content.append(
735735
f"""
736-
with open('{Path("..") / html.file_path}', 'r', encoding='utf-8') as html_file:
736+
with open('{(Path("..") / html.file_path).as_posix()}', 'r', encoding='utf-8') as html_file:
737737
html_content = html_file.read()\n"""
738738
)
739739

0 commit comments

Comments
 (0)