Skip to content

Commit db45bf9

Browse files
committed
šŸ› Fix(config_manager.py): Skipping unsupported files instead of stopping execution when report is created from a directory. Closes: #41
Also, adding validation for json files from plotly and altair using file cntent instead of file name string
1 parent f583816 commit db45bf9

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

ā€Ždocs/example_data/MicW2Graph/MicW2Graph_config.yamlā€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ sections:
1212
components:
1313
- component_type: plot
1414
plot_type: plotly
15-
title: Top Species Plot Biome Plotly
16-
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/docs/example_data/MicW2Graph/1_Exploratory_Data_Analysis/1_Abundance_data/1_top_species_plot_biome_plotly.json
15+
title: Top Species Plot Biome
16+
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/docs/example_data/MicW2Graph/1_Exploratory_Data_Analysis/1_Abundance_data/1_top_species_plot_biome.json
1717
description: ''
1818
- component_type: plot
1919
plot_type: altair
20-
title: Multilineplot Altair
21-
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/docs/example_data/MicW2Graph/1_Exploratory_Data_Analysis/1_Abundance_data/2_multilineplot_altair.json
20+
title: Multilineplot
21+
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/docs/example_data/MicW2Graph/1_Exploratory_Data_Analysis/1_Abundance_data/2_multilineplot.json
2222
description: ''
2323
- component_type: dataframe
2424
file_format: csv

ā€Žvuegen/config_manager.pyā€Ž

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
2-
import os
2+
import os
3+
import json
34
from pathlib import Path
45
from typing import Dict, List, Optional, Tuple, Union
56

@@ -94,23 +95,21 @@ def _create_component_config_fromfile(self, file_path: Path) -> Dict[str, str]:
9495
# Check for interactive plots
9596
elif file_ext == ".json":
9697
component_config ["component_type"] = r.ComponentType.PLOT.value
97-
if "plotly" in file_path.stem.lower():
98-
component_config ["plot_type"] = r.PlotType.PLOTLY.value
99-
elif "altair" in file_path.stem.lower():
100-
component_config ["plot_type"] = r.PlotType.ALTAIR.value
101-
else:
102-
component_config ["plot_type"] = "unknown"
98+
try:
99+
with open(file_path, "r", encoding="utf-8") as f:
100+
json_data = json.load(f)
101+
if "$schema" in json_data:
102+
component_config["plot_type"] = r.PlotType.ALTAIR.value
103+
else:
104+
component_config["plot_type"] = r.PlotType.PLOTLY.value
105+
except Exception as e:
106+
self.logger.warning(f"Could not parse JSON file {file_path}: {e}")
107+
component_config["plot_type"] = "unknown"
103108
elif file_ext == ".md":
104109
component_config ["component_type"] = r.ComponentType.MARKDOWN.value
105110
else:
106-
error_msg = (
107-
f"Unsupported file extension: {file_ext}. "
108-
f"Supported extensions include:\n"
109-
f" - Network formats: {', '.join(fmt.value_with_dot for fmt in r.NetworkFormat)}\n"
110-
f" - DataFrame formats: {', '.join(fmt.value_with_dot for fmt in r.DataFrameFormat)}"
111-
)
112-
#self.logger.error(error_msg)
113-
raise ValueError(error_msg)
111+
self.logger.error(f"Unsupported file extension: {file_ext}. Skipping file: {file_path}\n")
112+
return None
114113

115114
return component_config
116115

@@ -165,6 +164,9 @@ def _create_subsect_config_fromdir(self, subsection_dir_path: Path) -> Dict[str,
165164
for file in sorted_files:
166165
if file.is_file():
167166
component_config = self._create_component_config_fromfile(file)
167+
# Skip unsupported files
168+
if component_config is None:
169+
continue
168170

169171
# Ensure the file path is absolute
170172
file_path = file.resolve()

0 commit comments

Comments
Ā (0)