Skip to content

Commit 3df2351

Browse files
committed
refactor(cleanup): 移除未引用代码与冗余逻辑
- 删除未使用的方法/函数与重复实现,减少维护成本 - 清理无用属性、统计字段与辅助函数 - 调整少量模块导入与内部流程以匹配精简后结构
1 parent 9f80fe5 commit 3df2351

13 files changed

Lines changed: 7 additions & 2423 deletions

File tree

src/integrated_script/config/exceptions.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -156,31 +156,3 @@ def __init__(self, message: str = "操作被用户中断", **kwargs):
156156

157157

158158
# 异常映射字典,用于根据错误类型快速创建异常
159-
EXCEPTION_MAP = {
160-
"processing": ProcessingError,
161-
"path": PathError,
162-
"file": FileProcessingError,
163-
"config": ConfigurationError,
164-
"validation": ValidationError,
165-
"dataset": DatasetError,
166-
"interrupt": UserInterruptError,
167-
}
168-
169-
170-
def create_exception(error_type: str, message: str, **kwargs) -> ProcessingError:
171-
"""根据错误类型创建相应的异常实例
172-
173-
Args:
174-
error_type (str): 错误类型
175-
message (str): 错误消息
176-
**kwargs: 其他参数
177-
178-
Returns:
179-
ProcessingError: 相应的异常实例
180-
181-
Example:
182-
>>> exc = create_exception("file", "文件不存在", file_path="/path/to/file")
183-
>>> raise exc
184-
"""
185-
exception_class = EXCEPTION_MAP.get(error_type, ProcessingError)
186-
return exception_class(message, **kwargs)

src/integrated_script/config/settings.py

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ def __init__(self, config_file: Union[str, Path] = None, auto_save: bool = True)
9191
self.config_file = Path(config_file)
9292
self.auto_save = auto_save
9393
self.config_data = self.DEFAULT_CONFIG.copy()
94-
self._last_modified = None
9594

9695
# 创建配置目录
9796
self.config_file.parent.mkdir(parents=True, exist_ok=True)
@@ -129,7 +128,6 @@ def load(self) -> None:
129128

130129
# 合并配置(保留默认值)
131130
self._merge_config(loaded_config)
132-
self._last_modified = self.config_file.stat().st_mtime
133131

134132
except (json.JSONDecodeError, yaml.YAMLError) as e:
135133
raise ConfigurationError(
@@ -171,7 +169,6 @@ def save(self) -> None:
171169
else:
172170
json.dump(save_data, f, ensure_ascii=False, indent=2)
173171

174-
self._last_modified = self.config_file.stat().st_mtime
175172

176173
except Exception as e:
177174
raise FileProcessingError(
@@ -336,22 +333,6 @@ def validate(self) -> bool:
336333

337334
return True
338335

339-
def reload_if_changed(self) -> bool:
340-
"""如果文件已更改则重新加载
341-
342-
Returns:
343-
bool: 是否重新加载了配置
344-
"""
345-
if not self.config_file.exists():
346-
return False
347-
348-
current_mtime = self.config_file.stat().st_mtime
349-
if self._last_modified is None or current_mtime > self._last_modified:
350-
self.load()
351-
return True
352-
353-
return False
354-
355336
def _merge_config(self, new_config: Dict[str, Any]) -> None:
356337
"""合并配置字典
357338
@@ -382,35 +363,6 @@ def get_all(self) -> Dict[str, Any]:
382363
"""
383364
return self.config_data.copy()
384365

385-
def export(self, export_file: Union[str, Path], format_type: str = "json") -> None:
386-
"""导出配置到文件
387-
388-
Args:
389-
export_file: 导出文件路径
390-
format_type: 导出格式 ('json' 或 'yaml')
391-
"""
392-
export_path = Path(export_file)
393-
export_path.parent.mkdir(parents=True, exist_ok=True)
394-
395-
try:
396-
with open(export_path, "w", encoding="utf-8") as f:
397-
if format_type.lower() == "yaml":
398-
yaml.dump(
399-
self.config_data,
400-
f,
401-
default_flow_style=False,
402-
allow_unicode=True,
403-
indent=2,
404-
)
405-
else:
406-
json.dump(self.config_data, f, ensure_ascii=False, indent=2)
407-
except Exception as e:
408-
raise FileProcessingError(
409-
f"导出配置失败: {str(e)}",
410-
file_path=str(export_path),
411-
operation="export",
412-
)
413-
414366
def __str__(self) -> str:
415367
return f"ConfigManager(file={self.config_file}, auto_save={self.auto_save})"
416368

src/integrated_script/core/base.py

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from abc import ABC, abstractmethod
1212
from pathlib import Path
13-
from typing import Any, Dict, List, Optional, Union
13+
from typing import Any, List, Optional, Union
1414

1515
from ..config.exceptions import PathError, ProcessingError
1616
from ..config.settings import ConfigManager
@@ -42,8 +42,6 @@ def __init__(self, config: Optional[ConfigManager] = None, name: str = None):
4242
# 初始化状态
4343
self._initialized = False
4444
self._processing = False
45-
self._results = {}
46-
4745
# 执行初始化
4846
self._initialize()
4947

@@ -146,25 +144,11 @@ def run(self, *args, **kwargs) -> Any:
146144
# 执行处理
147145
result = self.process(*args, **kwargs)
148146

149-
# 保存结果
150-
self._results = {
151-
"success": True,
152-
"result": result,
153-
"processor": self.name,
154-
"timestamp": self._get_timestamp(),
155-
}
156-
157147
self.logger.info(f"处理器 {self.name} 运行完成")
158148
return result
159149

160150
except Exception as e:
161151
self.logger.error(f"处理器 {self.name} 运行失败: {str(e)}")
162-
self._results = {
163-
"success": False,
164-
"error": str(e),
165-
"processor": self.name,
166-
"timestamp": self._get_timestamp(),
167-
}
168152
raise
169153

170154
finally:
@@ -174,30 +158,6 @@ def run(self, *args, **kwargs) -> Any:
174158
except Exception as e:
175159
self.logger.warning(f"清理资源时出错: {str(e)}")
176160

177-
def get_results(self) -> Dict[str, Any]:
178-
"""获取处理结果
179-
180-
Returns:
181-
dict: 处理结果字典
182-
"""
183-
return self._results.copy()
184-
185-
def is_initialized(self) -> bool:
186-
"""检查是否已初始化
187-
188-
Returns:
189-
bool: 是否已初始化
190-
"""
191-
return self._initialized
192-
193-
def is_processing(self) -> bool:
194-
"""检查是否正在处理
195-
196-
Returns:
197-
bool: 是否正在处理
198-
"""
199-
return self._processing
200-
201161
def get_config(self, key: str, default: Any = None) -> Any:
202162
"""获取配置值
203163
@@ -210,15 +170,6 @@ def get_config(self, key: str, default: Any = None) -> Any:
210170
"""
211171
return self.config.get(key, default)
212172

213-
def set_config(self, key: str, value: Any) -> None:
214-
"""设置配置值
215-
216-
Args:
217-
key: 配置键
218-
value: 配置值
219-
"""
220-
self.config.set(key, value)
221-
222173
def validate_path(
223174
self,
224175
path: Union[str, Path],
@@ -286,16 +237,6 @@ def get_file_list(
286237

287238
return sorted(files)
288239

289-
def _get_timestamp(self) -> str:
290-
"""获取当前时间戳
291-
292-
Returns:
293-
str: ISO格式的时间戳
294-
"""
295-
from datetime import datetime
296-
297-
return datetime.now().isoformat()
298-
299240
def __str__(self) -> str:
300241
return f"{self.__class__.__name__}(name={self.name}, initialized={self._initialized})"
301242

0 commit comments

Comments
 (0)