@@ -37,7 +37,22 @@ def __init__(
3737 report : r .Report ,
3838 report_type : r .ReportType ,
3939 streamlit_autorun : bool = False ,
40+ static_dir : str = STATIC_FILES_DIR ,
4041 ):
42+ """Initialize ReportView with the report and report type.
43+
44+ Parameters
45+ ----------
46+ report : r.Report
47+ Report dataclass with all the information to be included in the report.
48+ Contains sections data needed to write the report python files.
49+ report_type : r.ReportType
50+ Enum of report type as definded by the ReportType Enum.
51+ streamlit_autorun : bool, optional
52+ Wheather streamlit should be started after report generation, by default False
53+ static_dir : str, optional
54+ The folder where the static files will be saved, by default STATIC_FILES_DIR.
55+ """
4156 super ().__init__ (report = report , report_type = report_type )
4257 self .streamlit_autorun = streamlit_autorun
4358 self .BUNDLED_EXECUTION = False
@@ -56,18 +71,16 @@ def __init__(
5671 r .ComponentType .CHATBOT : self ._generate_chatbot_content ,
5772 }
5873
59- def generate_report (
60- self , output_dir : str = SECTIONS_DIR , static_dir : str = STATIC_FILES_DIR
61- ) -> None :
74+ self . static_dir = static_dir
75+
76+ def generate_report ( self , output_dir : str = SECTIONS_DIR ) -> None :
6277 """
6378 Generates the Streamlit report and creates Python files for each section and its subsections and plots.
6479
6580 Parameters
6681 ----------
6782 output_dir : str, optional
6883 The folder where the generated report files will be saved (default is SECTIONS_DIR).
69- static_dir : str, optional
70- The folder where the static files will be saved (default is STATIC_FILES_DIR).
7184 """
7285 self .report .logger .debug (
7386 f"Generating '{ self .report_type } ' report in directory: '{ output_dir } '"
@@ -80,13 +93,13 @@ def generate_report(
8093 self .report .logger .info (f"Output directory already existed: '{ output_dir } '" )
8194
8295 # Create the static folder
83- if create_folder (static_dir ):
96+ if create_folder (self . static_dir ):
8497 self .report .logger .info (
85- f"Created output directory for static content: '{ static_dir } '"
98+ f"Created output directory for static content: '{ self . static_dir } '"
8699 )
87100 else :
88101 self .report .logger .info (
89- f"Output directory for static content already existed: '{ static_dir } '"
102+ f"Output directory for static content already existed: '{ self . static_dir } '"
90103 )
91104
92105 try :
@@ -172,7 +185,7 @@ def generate_report(
172185 )
173186
174187 # Create Python files for each section and its subsections and plots
175- self ._generate_sections (output_dir = output_dir , static_dir = static_dir )
188+ self ._generate_sections (output_dir = output_dir )
176189 except Exception as e :
177190 self .report .logger .error (
178191 f"An error occurred while generating the report: { str (e )} "
@@ -336,16 +349,14 @@ def _generate_home_section(
336349 self .report .logger .error (f"Error generating the home section: { str (e )} " )
337350 raise
338351
339- def _generate_sections (self , output_dir : str , static_dir : str ) -> None :
352+ def _generate_sections (self , output_dir : str ) -> None :
340353 """
341354 Generates Python files for each section in the report, including subsections and its components (plots, dataframes, markdown).
342355
343356 Parameters
344357 ----------
345358 output_dir : str
346359 The folder where section files will be saved.
347- static_dir : str
348- The folder where the static files will be saved.
349360 """
350361 self .report .logger .info ("Starting to generate sections for the report." )
351362
@@ -366,7 +377,8 @@ def _generate_sections(self, output_dir: str, static_dir: str) -> None:
366377 # Iterate through subsections and integrate them into the section file
367378 for subsection in section .subsections :
368379 self .report .logger .debug (
369- f"Processing subsection '{ subsection .id } ': '{ subsection .title } - { len (subsection .components )} component(s)'"
380+ f"Processing subsection '{ subsection .id } ': '{ subsection .title } -"
381+ f" { len (subsection .components )} component(s)'"
370382 )
371383 try :
372384 # Create subsection file
@@ -437,8 +449,6 @@ def _generate_subsection(self, subsection) -> tuple[List[str], List[str]]:
437449 ----------
438450 subsection : Subsection
439451 The subsection containing the components.
440- static_dir : str
441- The folder where the static files will be saved.
442452
443453 Returns
444454 -------
@@ -447,10 +457,6 @@ def _generate_subsection(self, subsection) -> tuple[List[str], List[str]]:
447457 - list of imports for the subsection (List[str])
448458 """
449459 subsection_content = []
450- subsection_imports = []
451-
452- # Track if there's a Chatbot component in this subsection
453- has_chatbot = False
454460
455461 # Add subsection header and description
456462 subsection_content .append (
@@ -477,7 +483,7 @@ def _generate_subsection(self, subsection) -> tuple[List[str], List[str]]:
477483 )
478484 return subsection_content , subsection_imports
479485
480- def _generate_plot_content (self , plot , static_dir : str ) -> List [str ]:
486+ def _generate_plot_content (self , plot ) -> List [str ]:
481487 """
482488 Generate content for a plot component based on the plot type (static or interactive).
483489
@@ -490,8 +496,6 @@ def _generate_plot_content(self, plot, static_dir: str) -> List[str]:
490496 -------
491497 list : List[str]
492498 The list of content lines for the plot.
493- static_dir : str
494- The folder where the static files will be saved.
495499 """
496500 plot_content = []
497501 # Add title
@@ -517,7 +521,7 @@ def _generate_plot_content(self, plot, static_dir: str) -> List[str]:
517521 else :
518522 # Otherwise, create and save a new pyvis network from the netowrkx graph
519523 html_plot_file = (
520- Path (static_dir ) / f"{ plot .title .replace (' ' , '_' )} .html"
524+ Path (self . static_dir ) / f"{ plot .title .replace (' ' , '_' )} .html"
521525 )
522526 pyvis_graph = plot .create_and_save_pyvis_network (
523527 networkx_graph , html_plot_file
0 commit comments