@@ -15,8 +15,8 @@ class StreamlitReportView(r.WebAppReportView):
1515 """
1616
1717 BASE_DIR = "streamlit_report"
18- SECTIONS_DIR = os . path . join (BASE_DIR , "sections" )
19- STATIC_FILES_DIR = os . path . join (BASE_DIR , "static" )
18+ SECTIONS_DIR = Path (BASE_DIR ) / "sections"
19+ STATIC_FILES_DIR = Path (BASE_DIR ) / "static"
2020 REPORT_MANAG_SCRIPT = "report_manager.py"
2121
2222 def __init__ (
@@ -94,7 +94,7 @@ def generate_report(
9494 # Create a folder for each section
9595 subsection_page_vars = []
9696 section_name_var = section .title .replace (" " , "_" )
97- section_dir_path = os . path . join (output_dir , section_name_var )
97+ section_dir_path = Path (output_dir ) / section_name_var
9898
9999 if create_folder (section_dir_path ):
100100 self .report .logger .debug (
@@ -130,7 +130,7 @@ def generate_report(
130130
131131 # Write the navigation and general content to a Python file
132132 with open (
133- os . path . join (output_dir , self .REPORT_MANAG_SCRIPT ) , "w"
133+ Path (output_dir ) / self .REPORT_MANAG_SCRIPT , "w"
134134 ) as nav_manager :
135135 nav_manager .write ("\n " .join (report_manag_content ))
136136 self .report .logger .info (
@@ -163,7 +163,7 @@ def run_report(self, output_dir: str = SECTIONS_DIR) -> None:
163163 [
164164 "streamlit" ,
165165 "run" ,
166- os . path . join (output_dir , self .REPORT_MANAG_SCRIPT ) ,
166+ Path (output_dir ) / self .REPORT_MANAG_SCRIPT ,
167167 ],
168168 check = True ,
169169 )
@@ -181,12 +181,12 @@ def run_report(self, output_dir: str = SECTIONS_DIR) -> None:
181181 f"To run the Streamlit app, use the following command:"
182182 )
183183 self .report .logger .info (
184- f"streamlit run { os . path . join (output_dir , self .REPORT_MANAG_SCRIPT ) } "
184+ f"streamlit run { Path (output_dir ) / self .REPORT_MANAG_SCRIPT } "
185185 )
186186 msg = (
187187 f"\n All the scripts to build the Streamlit app are available at: { output_dir } \n \n "
188188 f"To run the Streamlit app, use the following command:\n \n "
189- f"\t streamlit run { os . path . join (output_dir , self .REPORT_MANAG_SCRIPT ) } "
189+ f"\t streamlit run { Path (output_dir ) / self .REPORT_MANAG_SCRIPT } "
190190 )
191191 print (msg )
192192
@@ -243,7 +243,7 @@ def _generate_home_section(
243243
244244 try :
245245 # Create folder for the home page
246- home_dir_path = os . path . join (output_dir , "Home" )
246+ home_dir_path = Path (output_dir ) / "Home"
247247 if create_folder (home_dir_path ):
248248 self .report .logger .debug (f"Created home directory: { home_dir_path } " )
249249 else :
@@ -268,7 +268,7 @@ def _generate_home_section(
268268 home_content .append ("st.markdown(footer, unsafe_allow_html=True)\n " )
269269
270270 # Write the home page content to a Python file
271- home_page_path = os . path . join (home_dir_path , "Homepage.py" )
271+ home_page_path = Path (home_dir_path ) / "Homepage.py"
272272 with open (home_page_path , "w" ) as home_page :
273273 home_page .write ("\n " .join (home_content ))
274274 self .report .logger .info (f"Home page content written to '{ home_page_path } '." )
@@ -309,11 +309,7 @@ def _generate_sections(self, output_dir: str) -> None:
309309 )
310310 try :
311311 # Create subsection file
312- subsection_file_path = os .path .join (
313- output_dir ,
314- section_name_var ,
315- subsection .title .replace (" " , "_" ) + ".py" ,
316- )
312+ subsection_file_path = Path (output_dir ) / section_name_var / f"{ subsection .title .replace (' ' , '_' )} .py"
317313
318314 # Generate content and imports for the subsection
319315 subsection_content , subsection_imports = (
@@ -461,9 +457,7 @@ def _generate_plot_content(
461457 networkx_graph , html_plot_file = networkx_graph
462458 else :
463459 # Otherwise, create and save a new pyvis network from the netowrkx graph
464- html_plot_file = os .path .join (
465- static_dir , f"{ plot .title .replace (' ' , '_' )} .html"
466- )
460+ html_plot_file = Path (static_dir ) / f"{ plot .title .replace (' ' , '_' )} .html"
467461 pyvis_graph = plot .create_and_save_pyvis_network (
468462 networkx_graph , html_plot_file
469463 )
@@ -532,7 +526,7 @@ def _generate_plot_code(self, plot) -> str:
532526plot_json = json.loads(response.text)\n """
533527 else : # If it's a local file
534528 plot_code = f"""
535- with open('{ os . path . join (plot .file_path )} ', 'r') as plot_file:
529+ with open('{ Path (plot .file_path )} ', 'r') as plot_file:
536530 plot_json = json.load(plot_file)\n """
537531
538532 # Add specific code for each visualization tool
@@ -585,7 +579,7 @@ def _generate_dataframe_content(self, dataframe) -> List[str]:
585579
586580 try :
587581 # Check if the file extension matches any DataFrameFormat value
588- file_extension = os . path . splitext (dataframe .file_path )[ 1 ] .lower ()
582+ file_extension = Path (dataframe .file_path ). suffix .lower ()
589583 if not any (
590584 file_extension == fmt .value_with_dot for fmt in r .DataFrameFormat
591585 ):
@@ -675,7 +669,7 @@ def _generate_markdown_content(self, markdown) -> List[str]:
675669 else : # If it's a local file
676670 markdown_content .append (
677671 f"""
678- with open('{ os . path . join (".." , markdown .file_path ) } ', 'r') as markdown_file:
672+ with open('{ Path (".." ) / markdown .file_path } ', 'r') as markdown_file:
679673 markdown_content = markdown_file.read()\n """
680674 )
681675 # Code to display md content
@@ -735,7 +729,7 @@ def _generate_html_content(self, html) -> List[str]:
735729 # If it's a local file
736730 html_content .append (
737731 f"""
738- with open('{ os . path . join (".." , html .file_path ) } ', 'r', encoding='utf-8') as html_file:
732+ with open('{ Path (".." ) / html .file_path } ', 'r', encoding='utf-8') as html_file:
739733 html_content = html_file.read()\n """
740734 )
741735
0 commit comments