Skip to content

Commit 1e14d99

Browse files
committed
✨ add sub-sub components to subsections, add max recursion
- default still on subsection level - could consider to make subsubsections instead of adding components to subsection
1 parent a518051 commit 1e14d99

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

src/vuegen/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def main():
4747
output_dir=args.output_directory,
4848
streamlit_autorun=args.streamlit_autorun,
4949
quarto_checks=args.quarto_checks,
50+
max_depth=args.max_depth,
5051
)
5152

5253
# Print completion message

src/vuegen/config_manager.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,23 @@ class ConfigManager:
1313
Class for handling metadata of reports from YAML config file and creating report objects.
1414
"""
1515

16-
def __init__(self, logger: Optional[logging.Logger] = None):
16+
def __init__(self, logger: Optional[logging.Logger] = None, max_depth: int = 2):
1717
"""
1818
Initializes the ConfigManager with a logger.
1919
2020
Parameters
2121
----------
2222
logger : logging.Logger, optional
2323
A logger instance for the class. If not provided, a default logger will be created.
24+
max_depth : int, optional
25+
The maximum depth of the directory structure to consider when generating the report
26+
config from a directory.
27+
The default is 2, which means it will include sections and subsections.
2428
"""
2529
if logger is None:
2630
logger, _ = get_logger("report")
2731
self.logger = logger
32+
self.max_depth = max_depth
2833

2934
def _create_title_fromdir(self, file_dirname: str) -> str:
3035
"""
@@ -198,7 +203,7 @@ def _read_description_file(self, folder_path: Path) -> str:
198203
return ""
199204

200205
def _create_subsect_config_fromdir(
201-
self, subsection_dir_path: Path
206+
self, subsection_dir_path: Path, level: int = 2
202207
) -> Dict[str, Union[str, List[Dict]]]:
203208
"""
204209
Creates subsection config from a directory.
@@ -217,7 +222,6 @@ def _create_subsect_config_fromdir(
217222
sorted_files = self._sort_paths_by_numprefix(
218223
list(subsection_dir_path.iterdir())
219224
)
220-
221225
components = []
222226
for file in sorted_files:
223227
if file.is_file():
@@ -227,9 +231,17 @@ def _create_subsect_config_fromdir(
227231
continue
228232
# Add component config to list
229233
components.append(component_config)
230-
# ! if folder go into folder and pull files out?
231-
# nesting level already at point 2
232-
# loop of components in a folder
234+
elif file.is_dir():
235+
if level > self.max_depth:
236+
self.logger.warning(
237+
"Subsection nesting level exceeded: %s. Skipping.", file.name
238+
)
239+
continue
240+
# components are added to subsection
241+
# ! Alternatively, one could add (sub-)sections to the subsection
242+
# ? Then one could remove differentiation between sections and subsections
243+
nested_components = self._create_subsect_config_fromdir(file, level + 1)
244+
components.extend(nested_components["components"])
233245

234246
subsection_config = {
235247
"title": self._create_title_fromdir(subsection_dir_path.name),

src/vuegen/report_generator.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def get_report(
1818
streamlit_autorun: bool = False,
1919
quarto_checks: bool = False,
2020
output_dir: Path = None,
21+
max_depth: int = 2, # section and subsection folders
2122
) -> tuple[str, str]:
2223
"""
2324
Generate and run a report based on the specified engine.
@@ -40,6 +41,10 @@ def get_report(
4041
output_dir : Path, optional
4142
The directory where the report folder will be generated.
4243
If not provided, the current directory will be used.
44+
max_depth : int, optional
45+
The maximum depth of the directory structure to consider when generating the report.
46+
The default is 2, which means it will include sections and subsections. The parater
47+
is only used when 'dir_path' is used.
4348
4449
Raises
4550
------
@@ -63,7 +68,7 @@ def get_report(
6368
logger, _ = get_logger("report", folder=_folder)
6469

6570
# Create the config manager object
66-
config_manager = ConfigManager(logger)
71+
config_manager = ConfigManager(logger, max_depth=max_depth)
6772

6873
if dir_path:
6974
# Generate configuration from the provided directory

src/vuegen/utils/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,16 @@ def get_parser(prog_name: str, others: dict = {}) -> argparse.Namespace:
246246
default=False,
247247
help="Check if Quarto is installed and available for report generation.",
248248
)
249+
parser.add_argument(
250+
"-mdep",
251+
"--max_depth",
252+
type=int,
253+
default=2,
254+
help=(
255+
"Maximum depth for the recursive search of files in the input directory. "
256+
"Ignored if a config file is provided."
257+
),
258+
)
249259
# Parse arguments
250260
return parser
251261

0 commit comments

Comments
 (0)