@@ -24,9 +24,25 @@ def __init__(
2424 report : r .Report ,
2525 report_type : r .ReportType ,
2626 quarto_checks : bool = False ,
27+ static_dir : str = STATIC_FILES_DIR ,
2728 ):
29+ """_summary_
30+
31+ Parameters
32+ ----------
33+ report : r.Report
34+ Report dataclass with all the information to be included in the report.
35+ Contains sections data needed to write the report python files.
36+ report_type : r.ReportType
37+ Enum of report type as definded by the ReportType Enum.
38+ quarto_checks : bool, optional
39+ Whether to test if all quarto dependencies are installed, by default False
40+ static_dir : str
41+ The folder where the static files will be saved.
42+ """
2843 super ().__init__ (report = report , report_type = report_type )
2944 self .quarto_checks = quarto_checks
45+ self .static_dir = static_dir
3046 # self.BUNDLED_EXECUTION = False
3147 self .quarto_path = "quarto"
3248 # self.env_vars = os.environ.copy()
@@ -48,18 +64,14 @@ def __init__(
4864 r .ReportType .PPTX ,
4965 }
5066
51- def generate_report (
52- self , output_dir : Path = BASE_DIR , static_dir : Path = STATIC_FILES_DIR
53- ) -> None :
67+ def generate_report (self , output_dir : Path = BASE_DIR ) -> None :
5468 """
5569 Generates the qmd file of the quarto report. It creates code for rendering each section and its subsections with all components.
5670
5771 Parameters
5872 ----------
5973 output_dir : Path, optional
6074 The folder where the generated report files will be saved (default is BASE_DIR).
61- static_dir : Path, optional
62- The folder where the static files will be saved (default is STATIC_FILES_DIR).
6375 """
6476 self .report .logger .debug (
6577 f"Generating '{ self .report_type } ' report in directory: '{ output_dir } '"
@@ -74,13 +86,13 @@ def generate_report(
7486 )
7587
7688 # Create the static folder
77- if create_folder (static_dir ):
89+ if create_folder (self . static_dir ):
7890 self .report .logger .info (
79- f"Created output directory for static content: '{ static_dir } '"
91+ f"Created output directory for static content: '{ self . static_dir } '"
8092 )
8193 else :
8294 self .report .logger .info (
83- f"Output directory for static content already existed: '{ static_dir } '"
95+ f"Output directory for static content already existed: '{ self . static_dir } '"
8496 )
8597
8698 try :
@@ -125,7 +137,6 @@ def generate_report(
125137 self ._generate_subsection (
126138 subsection ,
127139 is_report_revealjs ,
128- static_dir = static_dir ,
129140 )
130141 )
131142 qmd_content .extend (subsection_content )
@@ -392,7 +403,6 @@ def _generate_subsection(
392403 self ,
393404 subsection ,
394405 is_report_revealjs ,
395- static_dir : str ,
396406 ) -> tuple [List [str ], List [str ]]:
397407 """
398408 Generate code to render components (plots, dataframes, markdown) in the given subsection,
@@ -404,8 +414,7 @@ def _generate_subsection(
404414 The subsection containing the components.
405415 is_report_revealjs : bool
406416 A boolean indicating whether the report is in revealjs format.
407- static_dir : str
408- The folder where the static files will be saved.
417+
409418 Returns
410419 -------
411420 tuple : (List[str], List[str])
@@ -428,13 +437,9 @@ def _generate_subsection(
428437 subsection_imports .append (component_imports )
429438
430439 if component .component_type == r .ComponentType .PLOT :
431- subsection_content .extend (
432- self ._generate_plot_content (component , static_dir = static_dir )
433- )
440+ subsection_content .extend (self ._generate_plot_content (component ))
434441 elif component .component_type == r .ComponentType .DATAFRAME :
435- subsection_content .extend (
436- self ._generate_dataframe_content (component , static_dir = static_dir )
437- )
442+ subsection_content .extend (self ._generate_dataframe_content (component ))
438443 elif (
439444 component .component_type == r .ComponentType .MARKDOWN
440445 and component .title .lower () != "description"
@@ -458,16 +463,14 @@ def _generate_subsection(
458463 )
459464 return subsection_content , subsection_imports
460465
461- def _generate_plot_content (self , plot , static_dir : str ) -> List [str ]:
466+ def _generate_plot_content (self , plot ) -> List [str ]:
462467 """
463468 Generate content for a plot component based on the report type.
464469
465470 Parameters
466471 ----------
467472 plot : Plot
468473 The plot component to generate content for.
469- static_dir : str
470- The folder where the static files will be saved.
471474
472475 Returns
473476 -------
@@ -480,9 +483,13 @@ def _generate_plot_content(self, plot, static_dir: str) -> List[str]:
480483
481484 # Define plot path
482485 if self .is_report_static :
483- static_plot_path = Path (static_dir ) / f"{ plot .title .replace (' ' , '_' )} .png"
486+ static_plot_path = (
487+ Path (self .static_dir ) / f"{ plot .title .replace (' ' , '_' )} .png"
488+ )
484489 else :
485- html_plot_file = Path (static_dir ) / f"{ plot .title .replace (' ' , '_' )} .html"
490+ html_plot_file = (
491+ Path (self .static_dir ) / f"{ plot .title .replace (' ' , '_' )} .html"
492+ )
486493
487494 # Add content for the different plot types
488495 try :
@@ -610,16 +617,14 @@ def _generate_plot_code(self, plot, output_file="") -> str:
610617</div>\n """
611618 return plot_code
612619
613- def _generate_dataframe_content (self , dataframe , static_dir : str ) -> List [str ]:
620+ def _generate_dataframe_content (self , dataframe ) -> List [str ]:
614621 """
615622 Generate content for a DataFrame component based on the report type.
616623
617624 Parameters
618625 ----------
619626 dataframe : DataFrame
620627 The dataframe component to add to content.
621- static_dir : str
622- The folder where the static files will be saved.
623628
624629 Returns
625630 -------
@@ -669,9 +674,7 @@ def _generate_dataframe_content(self, dataframe, static_dir: str) -> List[str]:
669674 )
670675
671676 # Display the dataframe
672- dataframe_content .extend (
673- self ._show_dataframe (dataframe , static_dir = static_dir )
674- )
677+ dataframe_content .extend (self ._show_dataframe (dataframe ))
675678
676679 except Exception as e :
677680 self .report .logger .error (
@@ -822,16 +825,14 @@ def _generate_image_content(
822825 f"""{{fig-alt={ alt_text } width={ width } height={ height } }}\n """
823826 )
824827
825- def _show_dataframe (self , dataframe , static_dir : str ) -> List [str ]:
828+ def _show_dataframe (self , dataframe ) -> List [str ]:
826829 """
827830 Appends either a static image or an interactive representation of a DataFrame to the content list.
828831
829832 Parameters
830833 ----------
831834 dataframe : DataFrame
832835 The DataFrame object containing the data to display.
833- static_dir : str
834- The folder where the static files will be saved.
835836
836837 Returns
837838 -------
@@ -841,7 +842,9 @@ def _show_dataframe(self, dataframe, static_dir: str) -> List[str]:
841842 dataframe_content = []
842843 if self .is_report_static :
843844 # Generate path for the DataFrame image
844- df_image = Path (static_dir ) / f"{ dataframe .title .replace (' ' , '_' )} .png"
845+ df_image = (
846+ Path (self .static_dir ) / f"{ dataframe .title .replace (' ' , '_' )} .png"
847+ )
845848 dataframe_content .append (
846849 f"df.dfi.export('{ Path (df_image ).resolve ().as_posix ()} ', max_rows=10, max_cols=5, table_conversion='matplotlib')\n ```\n "
847850 )
0 commit comments