@@ -16,7 +16,7 @@ class QuartoReportView(r.ReportView):
1616 """
1717
1818 BASE_DIR = "quarto_report"
19- STATIC_FILES_DIR = os . path . join (BASE_DIR , "static" )
19+ STATIC_FILES_DIR = Path (BASE_DIR ) / "static"
2020
2121 def __init__ (self , report : r .Report , report_type : r .ReportType ):
2222 super ().__init__ (report = report , report_type = report_type )
@@ -125,7 +125,7 @@ def generate_report(
125125
126126 # Write the navigation and general content to a Python file
127127 with open (
128- os . path . join (output_dir , f"{ self .BASE_DIR } .qmd" ) , "w"
128+ Path (output_dir ) / f"{ self .BASE_DIR } .qmd" , "w"
129129 ) as quarto_report :
130130 quarto_report .write (yaml_header )
131131 quarto_report .write (
@@ -156,15 +156,15 @@ def run_report(self, output_dir: str = BASE_DIR) -> None:
156156 """
157157 try :
158158 subprocess .run (
159- ["quarto" , "render" , os . path . join (output_dir , f"{ self .BASE_DIR } .qmd" ) ],
159+ ["quarto" , "render" , Path (output_dir ) / f"{ self .BASE_DIR } .qmd" ],
160160 check = True ,
161161 )
162162 if self .report_type == r .ReportType .JUPYTER :
163163 subprocess .run (
164164 [
165165 "quarto" ,
166166 "convert" ,
167- os . path . join (output_dir , f"{ self .BASE_DIR } .qmd" ) ,
167+ Path (output_dir ) / f"{ self .BASE_DIR } .qmd" ,
168168 ],
169169 check = True ,
170170 )
@@ -413,13 +413,9 @@ def _generate_plot_content(
413413
414414 # Define plot path
415415 if is_report_static :
416- static_plot_path = os .path .join (
417- static_dir , f"{ plot .title .replace (' ' , '_' )} .png"
418- )
416+ static_plot_path = Path (static_dir ) / f"{ plot .title .replace (' ' , '_' )} .png"
419417 else :
420- html_plot_file = os .path .join (
421- static_dir , f"{ plot .title .replace (' ' , '_' )} .html"
422- )
418+ html_plot_file = Path (static_dir ) / f"{ plot .title .replace (' ' , '_' )} .html"
423419
424420 # Add content for the different plot types
425421 try :
@@ -431,7 +427,7 @@ def _generate_plot_content(
431427 plot_content .append (self ._generate_plot_code (plot ))
432428 if is_report_static :
433429 plot_content .append (
434- f"""fig_plotly.write_image("{ os . path . abspath ( static_plot_path )} ")\n ```\n """
430+ f"""fig_plotly.write_image("{ static_plot_path . resolve ( )} ")\n ```\n """
435431 )
436432 plot_content .append (self ._generate_image_content (static_plot_path ))
437433 else :
@@ -440,7 +436,7 @@ def _generate_plot_content(
440436 plot_content .append (self ._generate_plot_code (plot ))
441437 if is_report_static :
442438 plot_content .append (
443- f"""fig_altair.save("{ os . path . abspath ( static_plot_path )} ")\n ```\n """
439+ f"""fig_altair.save("{ static_plot_path . resolve ( )} ")\n ```\n """
444440 )
445441 plot_content .append (self ._generate_image_content (static_plot_path ))
446442 else :
@@ -513,7 +509,7 @@ def _generate_plot_code(self, plot, output_file="") -> str:
513509plot_json = response.text\n """
514510 else : # If it's a local file
515511 plot_code += f"""
516- with open('{ os . path . join (".." , plot .file_path ) } ', 'r') as plot_file:
512+ with open('{ Path (".." ) / plot .file_path } ', 'r') as plot_file:
517513 plot_json = plot_file.read()\n """
518514 # Add specific code for each visualization tool
519515 if plot .plot_type == r .PlotType .PLOTLY :
@@ -527,7 +523,7 @@ def _generate_plot_code(self, plot, output_file="") -> str:
527523 if is_url (plot .file_path ) and plot .file_path .endswith (".html" ):
528524 iframe_src = output_file
529525 else :
530- iframe_src = os . path . join (".." , output_file )
526+ iframe_src = Path (".." ) / output_file
531527
532528 # Embed the HTML file in an iframe
533529 plot_code = f"""
@@ -573,7 +569,7 @@ def _generate_dataframe_content(self, dataframe, is_report_static) -> List[str]:
573569 }
574570 try :
575571 # Check if the file extension matches any DataFrameFormat value
576- file_extension = os . path . splitext (dataframe .file_path )[ 1 ] .lower ()
572+ file_extension = Path (dataframe .file_path ). suffix .lower ()
577573 if not any (
578574 file_extension == fmt .value_with_dot for fmt in r .DataFrameFormat
579575 ):
@@ -585,7 +581,7 @@ def _generate_dataframe_content(self, dataframe, is_report_static) -> List[str]:
585581 file_path = (
586582 dataframe .file_path
587583 if is_url (dataframe .file_path )
588- else os . path . join (".." , dataframe .file_path )
584+ else Path (".." ) / dataframe .file_path
589585 )
590586
591587 # Load the DataFrame using the correct function
@@ -648,7 +644,7 @@ def _generate_markdown_content(self, markdown) -> List[str]:
648644 else : # If it's a local file
649645 markdown_content .append (
650646 f"""
651- with open('{ os . path . join (".." , markdown .file_path ) } ', 'r') as markdown_file:
647+ with open('{ Path (".." ) / markdown .file_path } ', 'r') as markdown_file:
652648 markdown_content = markdown_file.read()\n """
653649 )
654650
@@ -694,7 +690,7 @@ def _generate_html_content(self, html) -> List[str]:
694690 iframe_src = (
695691 html .file_path
696692 if is_url (html .file_path )
697- else os . path . join (".." , html .file_path )
693+ else Path (".." ) / html .file_path
698694 )
699695 iframe_code = f"""
700696<div style="text-align: center;">
@@ -769,11 +765,9 @@ def _show_dataframe(
769765 dataframe_content = []
770766 if is_report_static :
771767 # Generate path for the DataFrame image
772- df_image = os .path .join (
773- static_dir , f"{ dataframe .title .replace (' ' , '_' )} .png"
774- )
768+ df_image = Path (static_dir ) / f"{ dataframe .title .replace (' ' , '_' )} .png"
775769 dataframe_content .append (
776- f"df.dfi.export('{ os . path . abspath (df_image )} ', max_rows=10, max_cols=5)\n ```\n "
770+ f"df.dfi.export('{ Path (df_image ). resolve ( )} ', max_rows=10, max_cols=5)\n ```\n "
777771 )
778772 # Use helper method to add centered image content
779773 dataframe_content .append (self ._generate_image_content (df_image ))
0 commit comments