|
1 | 1 | import logging |
2 | | -import os |
| 2 | +import os |
| 3 | +import json |
3 | 4 | from pathlib import Path |
4 | 5 | from typing import Dict, List, Optional, Tuple, Union |
5 | 6 |
|
@@ -94,23 +95,21 @@ def _create_component_config_fromfile(self, file_path: Path) -> Dict[str, str]: |
94 | 95 | # Check for interactive plots |
95 | 96 | elif file_ext == ".json": |
96 | 97 | 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" |
103 | 108 | elif file_ext == ".md": |
104 | 109 | component_config ["component_type"] = r.ComponentType.MARKDOWN.value |
105 | 110 | 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 |
114 | 113 |
|
115 | 114 | return component_config |
116 | 115 |
|
@@ -165,6 +164,9 @@ def _create_subsect_config_fromdir(self, subsection_dir_path: Path) -> Dict[str, |
165 | 164 | for file in sorted_files: |
166 | 165 | if file.is_file(): |
167 | 166 | component_config = self._create_component_config_fromfile(file) |
| 167 | + # Skip unsupported files |
| 168 | + if component_config is None: |
| 169 | + continue |
168 | 170 |
|
169 | 171 | # Ensure the file path is absolute |
170 | 172 | file_path = file.resolve() |
|
0 commit comments