@@ -136,7 +136,9 @@ def generate_report(self, output_dir: str = SECTIONS_DIR) -> None:
136136 for section in self .report .sections [1 :]: # skip home section components
137137 # Create a folder for each section
138138 subsection_page_vars = []
139- section_name_var = section .title .replace (" " , "_" )
139+ section_name_var = make_valid_identifier (
140+ section .title .replace (" " , "_" )
141+ )
140142 section_dir_path = Path (output_dir ) / section_name_var
141143
142144 if create_folder (section_dir_path ):
@@ -151,9 +153,9 @@ def generate_report(self, output_dir: str = SECTIONS_DIR) -> None:
151153 if section .components :
152154 subsection_file_path = (
153155 Path (section_name_var )
154- / f"0_overview_{ section .title .lower ()} .py"
156+ / f"0_overview_{ make_valid_identifier ( section .title ) .lower ()} .py"
155157 ).as_posix () # Make sure it's Posix Paths
156-
158+ section . file_path = subsection_file_path
157159 # Create a Page object for each subsection and add it to the home page content
158160 report_manag_content .append (
159161 f"{ section_name_var } _overview = st.Page('{ subsection_file_path } ', title='Overview { section .title } ')"
@@ -173,7 +175,7 @@ def generate_report(self, output_dir: str = SECTIONS_DIR) -> None:
173175 subsection_file_path = (
174176 Path (section_name_var ) / f"{ subsection_name_var } .py"
175177 ).as_posix () # Make sure it's Posix Paths
176-
178+ subsection . file_path = subsection_file_path
177179 # Create a Page object for each subsection and add it to the home page content
178180 report_manag_content .append (
179181 f"{ subsection_name_var } = st.Page('{ subsection_file_path } ', title='{ subsection .title } ')"
@@ -402,16 +404,11 @@ def _generate_sections(self, output_dir: str) -> None:
402404 section_content , section_imports , _ = self ._combine_components (
403405 section .components
404406 )
405- _filepath_overview = (
406- Path (output_dir )
407- / section_name_var
408- / f"0_overview_{ section .title .lower ()} .py"
409- # ! tighly coupled to generate_report fct:
410- # ! check how to pass file names
411- )
412-
407+ assert (
408+ section .file_path is not None
409+ ), "Missing relative file path to overview page in section"
413410 write_python_file (
414- fpath = _filepath_overview ,
411+ fpath = Path ( output_dir ) / section . file_path ,
415412 imports = section_imports ,
416413 contents = section_content ,
417414 )
@@ -433,12 +430,10 @@ def _generate_sections(self, output_dir: str) -> None:
433430 try :
434431 # Create subsection file
435432 _subsection_name = make_valid_identifier (subsection .title )
436- subsection_file_path = (
437- Path (output_dir )
438- / section_name_var
439- / f"{ _subsection_name } .py"
440- )
441-
433+ assert (
434+ subsection .file_path is not None
435+ ), "Missing relative file path to subsection"
436+ subsection_file_path = Path (output_dir ) / subsection .file_path
442437 # Generate content and imports for the subsection
443438 subsection_content , subsection_imports = (
444439 self ._generate_subsection (subsection )
0 commit comments