Skip to content

Commit fb6d368

Browse files
committed
Merge branch 'main' of https://github.com/Multiomics-Analytics-Group/vuegen into os_installers
2 parents a13e784 + 99985d5 commit fb6d368

File tree

5 files changed

+56
-80
lines changed

5 files changed

+56
-80
lines changed

src/vuegen/config_manager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ def _create_component_config_fromfile(self, file_path: Path) -> Dict[str, str]:
6363

6464
# Add title, file path, and description
6565
component_config["title"] = self._create_title_fromdir(file_path.name)
66-
component_config["file_path"] = str(file_path.resolve())
66+
component_config["file_path"] = (
67+
file_path.resolve().as_posix()
68+
) # ! needs to be posix for all OS support
6769
component_config["description"] = ""
6870
component_config["caption"] = ""
6971

src/vuegen/quarto_reportview.py

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class QuartoReportView(r.ReportView):
1717
"""
1818

1919
BASE_DIR = "quarto_report"
20-
STATIC_FILES_DIR = os.path.join(BASE_DIR, "static")
20+
STATIC_FILES_DIR = Path(BASE_DIR) / "static"
2121

2222
def __init__(self, report: r.Report, report_type: r.ReportType):
2323
super().__init__(report=report, report_type=report_type)
@@ -132,9 +132,7 @@ def generate_report(
132132
report_formatted_imports = "\n".join(report_unique_imports)
133133

134134
# Write the navigation and general content to a Python file
135-
with open(
136-
os.path.join(output_dir, f"{self.BASE_DIR}.qmd"), "w"
137-
) as quarto_report:
135+
with open(Path(output_dir) / f"{self.BASE_DIR}.qmd", "w") as quarto_report:
138136
quarto_report.write(yaml_header)
139137
quarto_report.write(
140138
f"""\n```{{python}}
@@ -171,7 +169,7 @@ def run_report(self, output_dir: str = BASE_DIR) -> None:
171169
)
172170
if not self.BUNDLED_EXECUTION:
173171
subprocess.run(
174-
args,
172+
["quarto", "render", os.path.join(output_dir, f"{self.BASE_DIR}.qmd")],
175173
check=True,
176174
)
177175
try:
@@ -278,7 +276,7 @@ def _create_yaml_header(self) -> str:
278276
<a href="https://github.com/Multiomics-Analytics-Group/vuegen" target="_blank">
279277
<img src="https://raw.githubusercontent.com/Multiomics-Analytics-Group/vuegen/main/docs/images/vuegen_logo.svg" alt="VueGen" width="65px">
280278
</a>
281-
| © 2025 <a href="https://github.com/Multiomics-Analytics-Group" target="_blank">Multiomics Network Analytics Group (MoNA)</a>
279+
| Copyright 2025 <a href="https://github.com/Multiomics-Analytics-Group" target="_blank">Multiomics Network Analytics Group (MoNA)</a>
282280
</footer>""",
283281
r.ReportType.PDF: """
284282
pdf:
@@ -324,7 +322,7 @@ def _create_yaml_header(self) -> str:
324322
<a href="https://github.com/Multiomics-Analytics-Group/vuegen" target="_blank">
325323
<img src="https://raw.githubusercontent.com/Multiomics-Analytics-Group/vuegen/main/docs/images/vuegen_logo.svg" alt="VueGen" width="65px">
326324
</a>
327-
| © 2025 <a href="https://github.com/Multiomics-Analytics-Group" target="_blank">Multiomics Network Analytics Group (MoNA)</a>
325+
| Copyright 2025 <a href="https://github.com/Multiomics-Analytics-Group" target="_blank">Multiomics Network Analytics Group (MoNA)</a>
328326
</footer>""",
329327
r.ReportType.PPTX: """
330328
pptx:
@@ -355,7 +353,7 @@ def _create_yaml_header(self) -> str:
355353
<a href="https://github.com/Multiomics-Analytics-Group/vuegen" target="_blank">
356354
<img src="../docs/images/vuegen_logo.svg" alt="VueGen" width="65px">
357355
</a>
358-
| © 2025 <a href="https://github.com/Multiomics-Analytics-Group" target="_blank">Multiomics Network Analytics Group (MoNA)</a>
356+
| Copyright 2025 <a href="https://github.com/Multiomics-Analytics-Group" target="_blank">Multiomics Network Analytics Group (MoNA)</a>
359357
</footer>""",
360358
}
361359
# Create a key based on the report type and format
@@ -464,13 +462,9 @@ def _generate_plot_content(
464462

465463
# Define plot path
466464
if is_report_static:
467-
static_plot_path = os.path.join(
468-
static_dir, f"{plot.title.replace(' ', '_')}.png"
469-
)
465+
static_plot_path = Path(static_dir) / f"{plot.title.replace(' ', '_')}.png"
470466
else:
471-
html_plot_file = os.path.join(
472-
static_dir, f"{plot.title.replace(' ', '_')}.html"
473-
)
467+
html_plot_file = Path(static_dir) / f"{plot.title.replace(' ', '_')}.html"
474468

475469
# Add content for the different plot types
476470
try:
@@ -482,7 +476,7 @@ def _generate_plot_content(
482476
plot_content.append(self._generate_plot_code(plot))
483477
if is_report_static:
484478
plot_content.append(
485-
f"""fig_plotly.write_image("{os.path.abspath(static_plot_path)}")\n```\n"""
479+
f"""fig_plotly.write_image("{static_plot_path.resolve()}")\n```\n"""
486480
)
487481
plot_content.append(self._generate_image_content(static_plot_path))
488482
else:
@@ -491,7 +485,7 @@ def _generate_plot_content(
491485
plot_content.append(self._generate_plot_code(plot))
492486
if is_report_static:
493487
plot_content.append(
494-
f"""fig_altair.save("{os.path.abspath(static_plot_path)}")\n```\n"""
488+
f"""fig_altair.save("{static_plot_path.resolve()}")\n```\n"""
495489
)
496490
plot_content.append(self._generate_image_content(static_plot_path))
497491
else:
@@ -564,7 +558,7 @@ def _generate_plot_code(self, plot, output_file="") -> str:
564558
plot_json = response.text\n"""
565559
else: # If it's a local file
566560
plot_code += f"""
567-
with open('{os.path.join("..", plot.file_path)}', 'r') as plot_file:
561+
with open('{Path("..") / plot.file_path}', 'r') as plot_file:
568562
plot_json = plot_file.read()\n"""
569563
# Add specific code for each visualization tool
570564
if plot.plot_type == r.PlotType.PLOTLY:
@@ -578,7 +572,7 @@ def _generate_plot_code(self, plot, output_file="") -> str:
578572
if is_url(plot.file_path) and plot.file_path.endswith(".html"):
579573
iframe_src = output_file
580574
else:
581-
iframe_src = os.path.join("..", output_file)
575+
iframe_src = Path("..") / output_file
582576

583577
# Embed the HTML file in an iframe
584578
plot_code = f"""
@@ -624,7 +618,7 @@ def _generate_dataframe_content(self, dataframe, is_report_static) -> List[str]:
624618
}
625619
try:
626620
# Check if the file extension matches any DataFrameFormat value
627-
file_extension = os.path.splitext(dataframe.file_path)[1].lower()
621+
file_extension = Path(dataframe.file_path).suffix.lower()
628622
if not any(
629623
file_extension == fmt.value_with_dot for fmt in r.DataFrameFormat
630624
):
@@ -636,7 +630,7 @@ def _generate_dataframe_content(self, dataframe, is_report_static) -> List[str]:
636630
file_path = (
637631
dataframe.file_path
638632
if is_url(dataframe.file_path)
639-
else os.path.join("..", dataframe.file_path)
633+
else Path("..") / dataframe.file_path
640634
)
641635

642636
# Load the DataFrame using the correct function
@@ -699,7 +693,7 @@ def _generate_markdown_content(self, markdown) -> List[str]:
699693
else: # If it's a local file
700694
markdown_content.append(
701695
f"""
702-
with open('{os.path.join("..", markdown.file_path)}', 'r') as markdown_file:
696+
with open('{Path("..") / markdown.file_path}', 'r') as markdown_file:
703697
markdown_content = markdown_file.read()\n"""
704698
)
705699

@@ -745,7 +739,7 @@ def _generate_html_content(self, html) -> List[str]:
745739
iframe_src = (
746740
html.file_path
747741
if is_url(html.file_path)
748-
else os.path.join("..", html.file_path)
742+
else Path("..") / html.file_path
749743
)
750744
iframe_code = f"""
751745
<div style="text-align: center;">
@@ -820,11 +814,9 @@ def _show_dataframe(
820814
dataframe_content = []
821815
if is_report_static:
822816
# Generate path for the DataFrame image
823-
df_image = os.path.join(
824-
static_dir, f"{dataframe.title.replace(' ', '_')}.png"
825-
)
817+
df_image = Path(static_dir) / f"{dataframe.title.replace(' ', '_')}.png"
826818
dataframe_content.append(
827-
f"df.dfi.export('{os.path.abspath(df_image)}', max_rows=10, max_cols=5)\n```\n"
819+
f"df.dfi.export('{Path(df_image).resolve()}', max_rows=10, max_cols=5)\n```\n"
828820
)
829821
# Use helper method to add centered image content
830822
dataframe_content.append(self._generate_image_content(df_image))

src/vuegen/report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def create_and_save_pyvis_network(self, G: nx.Graph, output_file: str) -> Networ
382382
net.show_buttons(filter_=["physics"])
383383

384384
# Save the network as an HTML file
385-
net.save_graph(output_file)
385+
net.save_graph(str(output_file))
386386
self.logger.info(f"PyVis network created and saved as: {output_file}.")
387387
return net
388388

src/vuegen/streamlit_reportview.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import subprocess
33
import sys
4+
from pathlib import Path
45
from typing import List
56

67
import pandas as pd
@@ -16,8 +17,8 @@ class StreamlitReportView(r.WebAppReportView):
1617
"""
1718

1819
BASE_DIR = "streamlit_report"
19-
SECTIONS_DIR = os.path.join(BASE_DIR, "sections")
20-
STATIC_FILES_DIR = os.path.join(BASE_DIR, "static")
20+
SECTIONS_DIR = Path(BASE_DIR) / "sections"
21+
STATIC_FILES_DIR = Path(BASE_DIR) / "static"
2122
REPORT_MANAG_SCRIPT = "report_manager.py"
2223

2324
def __init__(
@@ -101,7 +102,7 @@ def generate_report(
101102
# Create a folder for each section
102103
subsection_page_vars = []
103104
section_name_var = section.title.replace(" ", "_")
104-
section_dir_path = os.path.join(output_dir, section_name_var)
105+
section_dir_path = Path(output_dir) / section_name_var
105106

106107
if create_folder(section_dir_path):
107108
self.report.logger.debug(
@@ -114,9 +115,9 @@ def generate_report(
114115

115116
for subsection in section.subsections:
116117
subsection_name_var = subsection.title.replace(" ", "_")
117-
subsection_file_path = os.path.join(
118-
section_name_var, subsection_name_var + ".py"
119-
)
118+
subsection_file_path = (
119+
Path(section_name_var) / f"{subsection_name_var}.py"
120+
).as_posix() # Make sure it's Posix Paths
120121

121122
# Create a Page object for each subsection and add it to the home page content
122123
report_manag_content.append(
@@ -136,9 +137,7 @@ def generate_report(
136137
)
137138

138139
# Write the navigation and general content to a Python file
139-
with open(
140-
os.path.join(output_dir, self.REPORT_MANAG_SCRIPT), "w"
141-
) as nav_manager:
140+
with open(Path(output_dir) / self.REPORT_MANAG_SCRIPT, "w") as nav_manager:
142141
nav_manager.write("\n".join(report_manag_content))
143142
self.report.logger.info(
144143
f"Created app navigation script: {self.REPORT_MANAG_SCRIPT}"
@@ -207,12 +206,12 @@ def run_report(self, output_dir: str = SECTIONS_DIR) -> None:
207206
f"To run the Streamlit app, use the following command:"
208207
)
209208
self.report.logger.info(
210-
f"streamlit run {os.path.join(output_dir, self.REPORT_MANAG_SCRIPT)}"
209+
f"streamlit run {Path(output_dir) / self.REPORT_MANAG_SCRIPT}"
211210
)
212211
msg = (
213212
f"\nAll the scripts to build the Streamlit app are available at: {output_dir}\n\n"
214213
f"To run the Streamlit app, use the following command:\n\n"
215-
f"\tstreamlit run {os.path.join(output_dir, self.REPORT_MANAG_SCRIPT)}"
214+
f"\tstreamlit run {Path(output_dir) / self.REPORT_MANAG_SCRIPT}"
216215
)
217216
print(msg)
218217

@@ -269,7 +268,7 @@ def _generate_home_section(
269268

270269
try:
271270
# Create folder for the home page
272-
home_dir_path = os.path.join(output_dir, "Home")
271+
home_dir_path = Path(output_dir) / "Home"
273272
if create_folder(home_dir_path):
274273
self.report.logger.debug(f"Created home directory: {home_dir_path}")
275274
else:
@@ -294,14 +293,14 @@ def _generate_home_section(
294293
home_content.append("st.markdown(footer, unsafe_allow_html=True)\n")
295294

296295
# Write the home page content to a Python file
297-
home_page_path = os.path.join(home_dir_path, "Homepage.py")
296+
home_page_path = Path(home_dir_path) / "Homepage.py"
298297
with open(home_page_path, "w") as home_page:
299298
home_page.write("\n".join(home_content))
300299
self.report.logger.info(f"Home page content written to '{home_page_path}'.")
301300

302301
# Add the home page to the report manager content
303302
report_manag_content.append(
304-
f"homepage = st.Page('Home/Homepage.py', title='Homepage')"
303+
f"homepage = st.Page('Home/Homepage.py', title='Homepage')" # ! here Posix Path is hardcoded
305304
)
306305
report_manag_content.append(f"sections_pages['Home'] = [homepage]\n")
307306
self.report.logger.info("Home page added to the report manager content.")
@@ -335,10 +334,10 @@ def _generate_sections(self, output_dir: str) -> None:
335334
)
336335
try:
337336
# Create subsection file
338-
subsection_file_path = os.path.join(
339-
output_dir,
340-
section_name_var,
341-
subsection.title.replace(" ", "_") + ".py",
337+
subsection_file_path = (
338+
Path(output_dir)
339+
/ section_name_var
340+
/ f"{subsection.title.replace(' ', '_')}.py"
342341
)
343342

344343
# Generate content and imports for the subsection
@@ -487,8 +486,8 @@ def _generate_plot_content(
487486
networkx_graph, html_plot_file = networkx_graph
488487
else:
489488
# Otherwise, create and save a new pyvis network from the netowrkx graph
490-
html_plot_file = os.path.join(
491-
static_dir, f"{plot.title.replace(' ', '_')}.html"
489+
html_plot_file = (
490+
Path(static_dir) / f"{plot.title.replace(' ', '_')}.html"
492491
)
493492
pyvis_graph = plot.create_and_save_pyvis_network(
494493
networkx_graph, html_plot_file
@@ -558,7 +557,7 @@ def _generate_plot_code(self, plot) -> str:
558557
plot_json = json.loads(response.text)\n"""
559558
else: # If it's a local file
560559
plot_code = f"""
561-
with open('{os.path.join(plot.file_path)}', 'r') as plot_file:
560+
with open('{Path(plot.file_path)}', 'r') as plot_file:
562561
plot_json = json.load(plot_file)\n"""
563562

564563
# Add specific code for each visualization tool
@@ -611,7 +610,7 @@ def _generate_dataframe_content(self, dataframe) -> List[str]:
611610

612611
try:
613612
# Check if the file extension matches any DataFrameFormat value
614-
file_extension = os.path.splitext(dataframe.file_path)[1].lower()
613+
file_extension = Path(dataframe.file_path).suffix.lower()
615614
if not any(
616615
file_extension == fmt.value_with_dot for fmt in r.DataFrameFormat
617616
):
@@ -701,7 +700,7 @@ def _generate_markdown_content(self, markdown) -> List[str]:
701700
else: # If it's a local file
702701
markdown_content.append(
703702
f"""
704-
with open('{os.path.join("..", markdown.file_path)}', 'r') as markdown_file:
703+
with open('{Path("..") / markdown.file_path}', 'r') as markdown_file:
705704
markdown_content = markdown_file.read()\n"""
706705
)
707706
# Code to display md content
@@ -761,7 +760,7 @@ def _generate_html_content(self, html) -> List[str]:
761760
# If it's a local file
762761
html_content.append(
763762
f"""
764-
with open('{os.path.join("..", html.file_path)}', 'r', encoding='utf-8') as html_file:
763+
with open('{Path("..") / html.file_path}', 'r', encoding='utf-8') as html_file:
765764
html_content = html_file.read()\n"""
766765
)
767766

0 commit comments

Comments
 (0)