aiecs 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of aiecs might be problematic. Click here for more details.

Files changed (90) hide show
  1. aiecs/__init__.py +75 -0
  2. aiecs/__main__.py +41 -0
  3. aiecs/aiecs_client.py +295 -0
  4. aiecs/application/__init__.py +10 -0
  5. aiecs/application/executors/__init__.py +10 -0
  6. aiecs/application/executors/operation_executor.py +341 -0
  7. aiecs/config/__init__.py +15 -0
  8. aiecs/config/config.py +117 -0
  9. aiecs/config/registry.py +19 -0
  10. aiecs/core/__init__.py +46 -0
  11. aiecs/core/interface/__init__.py +34 -0
  12. aiecs/core/interface/execution_interface.py +150 -0
  13. aiecs/core/interface/storage_interface.py +214 -0
  14. aiecs/domain/__init__.py +20 -0
  15. aiecs/domain/context/__init__.py +28 -0
  16. aiecs/domain/context/content_engine.py +982 -0
  17. aiecs/domain/context/conversation_models.py +306 -0
  18. aiecs/domain/execution/__init__.py +12 -0
  19. aiecs/domain/execution/model.py +49 -0
  20. aiecs/domain/task/__init__.py +13 -0
  21. aiecs/domain/task/dsl_processor.py +460 -0
  22. aiecs/domain/task/model.py +50 -0
  23. aiecs/domain/task/task_context.py +257 -0
  24. aiecs/infrastructure/__init__.py +26 -0
  25. aiecs/infrastructure/messaging/__init__.py +13 -0
  26. aiecs/infrastructure/messaging/celery_task_manager.py +341 -0
  27. aiecs/infrastructure/messaging/websocket_manager.py +289 -0
  28. aiecs/infrastructure/monitoring/__init__.py +12 -0
  29. aiecs/infrastructure/monitoring/executor_metrics.py +138 -0
  30. aiecs/infrastructure/monitoring/structured_logger.py +50 -0
  31. aiecs/infrastructure/monitoring/tracing_manager.py +376 -0
  32. aiecs/infrastructure/persistence/__init__.py +12 -0
  33. aiecs/infrastructure/persistence/database_manager.py +286 -0
  34. aiecs/infrastructure/persistence/file_storage.py +671 -0
  35. aiecs/infrastructure/persistence/redis_client.py +162 -0
  36. aiecs/llm/__init__.py +54 -0
  37. aiecs/llm/base_client.py +99 -0
  38. aiecs/llm/client_factory.py +339 -0
  39. aiecs/llm/custom_callbacks.py +228 -0
  40. aiecs/llm/openai_client.py +125 -0
  41. aiecs/llm/vertex_client.py +186 -0
  42. aiecs/llm/xai_client.py +184 -0
  43. aiecs/main.py +351 -0
  44. aiecs/scripts/DEPENDENCY_SYSTEM_SUMMARY.md +241 -0
  45. aiecs/scripts/README_DEPENDENCY_CHECKER.md +309 -0
  46. aiecs/scripts/README_WEASEL_PATCH.md +126 -0
  47. aiecs/scripts/__init__.py +3 -0
  48. aiecs/scripts/dependency_checker.py +825 -0
  49. aiecs/scripts/dependency_fixer.py +348 -0
  50. aiecs/scripts/download_nlp_data.py +348 -0
  51. aiecs/scripts/fix_weasel_validator.py +121 -0
  52. aiecs/scripts/fix_weasel_validator.sh +82 -0
  53. aiecs/scripts/patch_weasel_library.sh +188 -0
  54. aiecs/scripts/quick_dependency_check.py +269 -0
  55. aiecs/scripts/run_weasel_patch.sh +41 -0
  56. aiecs/scripts/setup_nlp_data.sh +217 -0
  57. aiecs/tasks/__init__.py +2 -0
  58. aiecs/tasks/worker.py +111 -0
  59. aiecs/tools/__init__.py +196 -0
  60. aiecs/tools/base_tool.py +202 -0
  61. aiecs/tools/langchain_adapter.py +361 -0
  62. aiecs/tools/task_tools/__init__.py +82 -0
  63. aiecs/tools/task_tools/chart_tool.py +704 -0
  64. aiecs/tools/task_tools/classfire_tool.py +901 -0
  65. aiecs/tools/task_tools/image_tool.py +397 -0
  66. aiecs/tools/task_tools/office_tool.py +600 -0
  67. aiecs/tools/task_tools/pandas_tool.py +565 -0
  68. aiecs/tools/task_tools/report_tool.py +499 -0
  69. aiecs/tools/task_tools/research_tool.py +363 -0
  70. aiecs/tools/task_tools/scraper_tool.py +548 -0
  71. aiecs/tools/task_tools/search_api.py +7 -0
  72. aiecs/tools/task_tools/stats_tool.py +513 -0
  73. aiecs/tools/temp_file_manager.py +126 -0
  74. aiecs/tools/tool_executor/__init__.py +35 -0
  75. aiecs/tools/tool_executor/tool_executor.py +518 -0
  76. aiecs/utils/LLM_output_structor.py +409 -0
  77. aiecs/utils/__init__.py +23 -0
  78. aiecs/utils/base_callback.py +50 -0
  79. aiecs/utils/execution_utils.py +158 -0
  80. aiecs/utils/logging.py +1 -0
  81. aiecs/utils/prompt_loader.py +13 -0
  82. aiecs/utils/token_usage_repository.py +279 -0
  83. aiecs/ws/__init__.py +0 -0
  84. aiecs/ws/socket_server.py +41 -0
  85. aiecs-1.0.0.dist-info/METADATA +610 -0
  86. aiecs-1.0.0.dist-info/RECORD +90 -0
  87. aiecs-1.0.0.dist-info/WHEEL +5 -0
  88. aiecs-1.0.0.dist-info/entry_points.txt +7 -0
  89. aiecs-1.0.0.dist-info/licenses/LICENSE +225 -0
  90. aiecs-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,825 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Comprehensive dependency checker for AIECS tools.
4
+
5
+ This script checks all system dependencies, Python packages, and model files
6
+ required by various AIECS tools and provides detailed status reports and
7
+ installation instructions.
8
+ """
9
+
10
+ import os
11
+ import sys
12
+ import subprocess
13
+ import platform
14
+ import shutil
15
+ import logging
16
+ from pathlib import Path
17
+ from typing import Dict, List, Tuple, Optional, Any
18
+ from dataclasses import dataclass
19
+ from enum import Enum
20
+
21
+
22
+ class DependencyStatus(Enum):
23
+ """Status of a dependency check."""
24
+ AVAILABLE = "available"
25
+ MISSING = "missing"
26
+ PARTIAL = "partial"
27
+ ERROR = "error"
28
+
29
+
30
+ @dataclass
31
+ class DependencyInfo:
32
+ """Information about a dependency."""
33
+ name: str
34
+ status: DependencyStatus
35
+ description: str
36
+ install_command: Optional[str] = None
37
+ install_url: Optional[str] = None
38
+ impact: str = ""
39
+ is_critical: bool = True
40
+
41
+
42
+ @dataclass
43
+ class ToolDependencies:
44
+ """Dependencies for a specific tool."""
45
+ tool_name: str
46
+ system_deps: List[DependencyInfo]
47
+ python_deps: List[DependencyInfo]
48
+ model_deps: List[DependencyInfo]
49
+ optional_deps: List[DependencyInfo]
50
+
51
+
52
+ class DependencyChecker:
53
+ """Main dependency checker class."""
54
+
55
+ def __init__(self):
56
+ self.logger = self._setup_logging()
57
+ self.system = platform.system().lower()
58
+ self.architecture = platform.machine().lower()
59
+ self.python_version = f"{sys.version_info.major}.{sys.version_info.minor}"
60
+
61
+ def _setup_logging(self) -> logging.Logger:
62
+ """Setup logging configuration."""
63
+ logging.basicConfig(
64
+ level=logging.INFO,
65
+ format='%(asctime)s - %(levelname)s - %(message)s',
66
+ handlers=[
67
+ logging.StreamHandler(sys.stdout),
68
+ logging.FileHandler('dependency_check.log')
69
+ ]
70
+ )
71
+ return logging.getLogger(__name__)
72
+
73
+ def check_system_command(self, command: str, version_flag: str = "--version") -> DependencyStatus:
74
+ """Check if a system command is available."""
75
+ try:
76
+ result = subprocess.run(
77
+ [command, version_flag],
78
+ capture_output=True,
79
+ text=True,
80
+ timeout=10
81
+ )
82
+ if result.returncode == 0:
83
+ return DependencyStatus.AVAILABLE
84
+ else:
85
+ return DependencyStatus.MISSING
86
+ except (subprocess.TimeoutExpired, FileNotFoundError, subprocess.CalledProcessError):
87
+ return DependencyStatus.MISSING
88
+
89
+ def check_python_package(self, package_name: str) -> DependencyStatus:
90
+ """Check if a Python package is installed."""
91
+ try:
92
+ __import__(package_name)
93
+ return DependencyStatus.AVAILABLE
94
+ except ImportError:
95
+ return DependencyStatus.MISSING
96
+
97
+ def check_file_exists(self, file_path: str) -> DependencyStatus:
98
+ """Check if a file exists."""
99
+ if os.path.exists(file_path):
100
+ return DependencyStatus.AVAILABLE
101
+ else:
102
+ return DependencyStatus.MISSING
103
+
104
+ def check_directory_exists(self, dir_path: str) -> DependencyStatus:
105
+ """Check if a directory exists."""
106
+ if os.path.isdir(dir_path):
107
+ return DependencyStatus.AVAILABLE
108
+ else:
109
+ return DependencyStatus.MISSING
110
+
111
+ def get_system_package_manager(self) -> str:
112
+ """Get the appropriate package manager for the system."""
113
+ if self.system == "linux":
114
+ if shutil.which("apt-get"):
115
+ return "apt-get"
116
+ elif shutil.which("yum"):
117
+ return "yum"
118
+ elif shutil.which("dnf"):
119
+ return "dnf"
120
+ elif shutil.which("pacman"):
121
+ return "pacman"
122
+ elif self.system == "darwin":
123
+ if shutil.which("brew"):
124
+ return "brew"
125
+ elif self.system == "windows":
126
+ return "chocolatey"
127
+ return "unknown"
128
+
129
+ def check_image_tool_dependencies(self) -> ToolDependencies:
130
+ """Check dependencies for Image Tool."""
131
+ system_deps = []
132
+ python_deps = []
133
+ model_deps = []
134
+ optional_deps = []
135
+
136
+ # Tesseract OCR
137
+ tesseract_status = self.check_system_command("tesseract")
138
+ system_deps.append(DependencyInfo(
139
+ name="Tesseract OCR",
140
+ status=tesseract_status,
141
+ description="OCR engine for text extraction from images",
142
+ install_command=self._get_tesseract_install_command(),
143
+ impact="OCR functionality will be unavailable",
144
+ is_critical=True
145
+ ))
146
+
147
+ # Pillow system dependencies
148
+ pillow_status = self._check_pillow_system_deps()
149
+ system_deps.append(DependencyInfo(
150
+ name="Pillow System Libraries",
151
+ status=pillow_status,
152
+ description="Image processing system libraries (libjpeg, libpng, etc.)",
153
+ install_command=self._get_pillow_system_deps_command(),
154
+ impact="Image processing may fail or be limited",
155
+ is_critical=True
156
+ ))
157
+
158
+ # Python packages
159
+ python_packages = ["PIL", "pytesseract"]
160
+ for pkg in python_packages:
161
+ status = self.check_python_package(pkg)
162
+ python_deps.append(DependencyInfo(
163
+ name=pkg,
164
+ status=status,
165
+ description=f"Python package: {pkg}",
166
+ install_command=f"pip install {pkg}",
167
+ impact=f"{pkg} functionality will be unavailable",
168
+ is_critical=True
169
+ ))
170
+
171
+ # Tesseract language packs
172
+ lang_packs = ["eng", "chi_sim", "chi_tra", "fra", "deu", "jpn", "kor", "rus", "spa"]
173
+ for lang in lang_packs:
174
+ status = self._check_tesseract_lang_pack(lang)
175
+ model_deps.append(DependencyInfo(
176
+ name=f"Tesseract {lang}",
177
+ status=status,
178
+ description=f"Tesseract language pack for {lang}",
179
+ install_command=self._get_tesseract_lang_install_command(lang),
180
+ impact=f"OCR in {lang} language will be unavailable",
181
+ is_critical=False
182
+ ))
183
+
184
+ return ToolDependencies(
185
+ tool_name="Image Tool",
186
+ system_deps=system_deps,
187
+ python_deps=python_deps,
188
+ model_deps=model_deps,
189
+ optional_deps=optional_deps
190
+ )
191
+
192
+ def check_classfire_tool_dependencies(self) -> ToolDependencies:
193
+ """Check dependencies for ClassFire Tool."""
194
+ system_deps = []
195
+ python_deps = []
196
+ model_deps = []
197
+ optional_deps = []
198
+
199
+ # Python packages
200
+ python_packages = ["spacy", "transformers", "nltk", "rake_nltk", "spacy_pkuseg"]
201
+ for pkg in python_packages:
202
+ status = self.check_python_package(pkg)
203
+ is_critical = pkg != "spacy_pkuseg" # spacy_pkuseg is optional
204
+ python_deps.append(DependencyInfo(
205
+ name=pkg,
206
+ status=status,
207
+ description=f"Python package: {pkg}",
208
+ install_command=f"pip install {pkg}",
209
+ impact=f"{pkg} functionality will be unavailable",
210
+ is_critical=is_critical
211
+ ))
212
+
213
+ # spaCy models
214
+ spacy_models = ["en_core_web_sm", "zh_core_web_sm"]
215
+ for model in spacy_models:
216
+ status = self._check_spacy_model(model)
217
+ is_critical = model == "en_core_web_sm" # Only English model is critical
218
+ model_deps.append(DependencyInfo(
219
+ name=f"spaCy {model}",
220
+ status=status,
221
+ description=f"spaCy model: {model}",
222
+ install_command=f"python -m spacy download {model}",
223
+ impact=f"Text processing in {model.split('_')[0]} language will be unavailable",
224
+ is_critical=is_critical
225
+ ))
226
+
227
+ # spaCy PKUSeg model (optional Chinese segmentation)
228
+ pkuseg_status = self._check_spacy_pkuseg_model()
229
+ model_deps.append(DependencyInfo(
230
+ name="spaCy PKUSeg",
231
+ status=pkuseg_status,
232
+ description="Chinese text segmentation model for spaCy",
233
+ install_command="pip install spacy_pkuseg",
234
+ impact="Advanced Chinese text segmentation will be unavailable",
235
+ is_critical=False
236
+ ))
237
+
238
+ # Transformers models
239
+ transformers_models = ["facebook/bart-large-cnn", "t5-base"]
240
+ for model in transformers_models:
241
+ status = self._check_transformers_model(model)
242
+ model_deps.append(DependencyInfo(
243
+ name=f"Transformers {model}",
244
+ status=status,
245
+ description=f"Transformers model: {model}",
246
+ install_command="Models download automatically on first use",
247
+ impact=f"Text summarization with {model} will be unavailable",
248
+ is_critical=False
249
+ ))
250
+
251
+ # NLTK data
252
+ nltk_data = ["stopwords", "punkt", "wordnet", "averaged_perceptron_tagger"]
253
+ for data in nltk_data:
254
+ status = self._check_nltk_data(data)
255
+ model_deps.append(DependencyInfo(
256
+ name=f"NLTK {data}",
257
+ status=status,
258
+ description=f"NLTK data: {data}",
259
+ install_command=f"python -c \"import nltk; nltk.download('{data}')\"",
260
+ impact=f"NLTK {data} functionality will be unavailable",
261
+ is_critical=True
262
+ ))
263
+
264
+ return ToolDependencies(
265
+ tool_name="ClassFire Tool",
266
+ system_deps=system_deps,
267
+ python_deps=python_deps,
268
+ model_deps=model_deps,
269
+ optional_deps=optional_deps
270
+ )
271
+
272
+ def check_office_tool_dependencies(self) -> ToolDependencies:
273
+ """Check dependencies for Office Tool."""
274
+ system_deps = []
275
+ python_deps = []
276
+ model_deps = []
277
+ optional_deps = []
278
+
279
+ # Java Runtime Environment
280
+ java_status = self.check_system_command("java", "-version")
281
+ system_deps.append(DependencyInfo(
282
+ name="Java Runtime Environment",
283
+ status=java_status,
284
+ description="Java runtime for Apache Tika document parsing",
285
+ install_command=self._get_java_install_command(),
286
+ impact="Document parsing with Tika will be unavailable",
287
+ is_critical=True
288
+ ))
289
+
290
+ # Tesseract OCR
291
+ tesseract_status = self.check_system_command("tesseract")
292
+ system_deps.append(DependencyInfo(
293
+ name="Tesseract OCR",
294
+ status=tesseract_status,
295
+ description="OCR engine for image text extraction",
296
+ install_command=self._get_tesseract_install_command(),
297
+ impact="OCR functionality will be unavailable",
298
+ is_critical=False
299
+ ))
300
+
301
+ # Python packages
302
+ python_packages = ["tika", "python-docx", "python-pptx", "openpyxl", "pdfplumber", "pytesseract", "PIL"]
303
+ for pkg in python_packages:
304
+ status = self.check_python_package(pkg)
305
+ python_deps.append(DependencyInfo(
306
+ name=pkg,
307
+ status=status,
308
+ description=f"Python package: {pkg}",
309
+ install_command=f"pip install {pkg}",
310
+ impact=f"{pkg} functionality will be unavailable",
311
+ is_critical=True
312
+ ))
313
+
314
+ return ToolDependencies(
315
+ tool_name="Office Tool",
316
+ system_deps=system_deps,
317
+ python_deps=python_deps,
318
+ model_deps=model_deps,
319
+ optional_deps=optional_deps
320
+ )
321
+
322
+ def check_stats_tool_dependencies(self) -> ToolDependencies:
323
+ """Check dependencies for Stats Tool."""
324
+ system_deps = []
325
+ python_deps = []
326
+ model_deps = []
327
+ optional_deps = []
328
+
329
+ # pyreadstat system dependencies
330
+ pyreadstat_status = self._check_pyreadstat_system_deps()
331
+ system_deps.append(DependencyInfo(
332
+ name="libreadstat",
333
+ status=pyreadstat_status,
334
+ description="System library for reading SAS, SPSS, Stata files",
335
+ install_command=self._get_pyreadstat_install_command(),
336
+ impact="SAS, SPSS, Stata file reading will be unavailable",
337
+ is_critical=False
338
+ ))
339
+
340
+ # Excel system dependencies
341
+ excel_status = self._check_excel_system_deps()
342
+ system_deps.append(DependencyInfo(
343
+ name="Excel System Libraries",
344
+ status=excel_status,
345
+ description="System libraries for Excel file processing",
346
+ install_command=self._get_excel_system_deps_command(),
347
+ impact="Excel file processing may be limited",
348
+ is_critical=False
349
+ ))
350
+
351
+ # Python packages
352
+ python_packages = ["pandas", "numpy", "scipy", "scikit-learn", "statsmodels", "pyreadstat", "openpyxl"]
353
+ for pkg in python_packages:
354
+ status = self.check_python_package(pkg)
355
+ python_deps.append(DependencyInfo(
356
+ name=pkg,
357
+ status=status,
358
+ description=f"Python package: {pkg}",
359
+ install_command=f"pip install {pkg}",
360
+ impact=f"{pkg} functionality will be unavailable",
361
+ is_critical=True
362
+ ))
363
+
364
+ return ToolDependencies(
365
+ tool_name="Stats Tool",
366
+ system_deps=system_deps,
367
+ python_deps=python_deps,
368
+ model_deps=model_deps,
369
+ optional_deps=optional_deps
370
+ )
371
+
372
+ def check_report_tool_dependencies(self) -> ToolDependencies:
373
+ """Check dependencies for Report Tool."""
374
+ system_deps = []
375
+ python_deps = []
376
+ model_deps = []
377
+ optional_deps = []
378
+
379
+ # WeasyPrint system dependencies
380
+ weasyprint_status = self._check_weasyprint_system_deps()
381
+ system_deps.append(DependencyInfo(
382
+ name="WeasyPrint System Libraries",
383
+ status=weasyprint_status,
384
+ description="System libraries for PDF generation (cairo, pango, etc.)",
385
+ install_command=self._get_weasyprint_install_command(),
386
+ impact="PDF generation will be unavailable",
387
+ is_critical=False
388
+ ))
389
+
390
+ # Matplotlib system dependencies
391
+ matplotlib_status = self._check_matplotlib_system_deps()
392
+ system_deps.append(DependencyInfo(
393
+ name="Matplotlib System Libraries",
394
+ status=matplotlib_status,
395
+ description="System libraries for chart generation",
396
+ install_command=self._get_matplotlib_system_deps_command(),
397
+ impact="Chart generation may be limited",
398
+ is_critical=False
399
+ ))
400
+
401
+ # Python packages
402
+ python_packages = ["jinja2", "matplotlib", "weasyprint", "bleach", "markdown", "pandas", "openpyxl", "python-docx", "python-pptx"]
403
+ for pkg in python_packages:
404
+ status = self.check_python_package(pkg)
405
+ python_deps.append(DependencyInfo(
406
+ name=pkg,
407
+ status=status,
408
+ description=f"Python package: {pkg}",
409
+ install_command=f"pip install {pkg}",
410
+ impact=f"{pkg} functionality will be unavailable",
411
+ is_critical=True
412
+ ))
413
+
414
+ return ToolDependencies(
415
+ tool_name="Report Tool",
416
+ system_deps=system_deps,
417
+ python_deps=python_deps,
418
+ model_deps=model_deps,
419
+ optional_deps=optional_deps
420
+ )
421
+
422
+ def check_scraper_tool_dependencies(self) -> ToolDependencies:
423
+ """Check dependencies for Scraper Tool."""
424
+ system_deps = []
425
+ python_deps = []
426
+ model_deps = []
427
+ optional_deps = []
428
+
429
+ # Playwright browsers
430
+ playwright_status = self._check_playwright_browsers()
431
+ system_deps.append(DependencyInfo(
432
+ name="Playwright Browsers",
433
+ status=playwright_status,
434
+ description="Browser binaries for JavaScript rendering",
435
+ install_command="playwright install",
436
+ impact="JavaScript rendering will be unavailable",
437
+ is_critical=False
438
+ ))
439
+
440
+ # Playwright system dependencies
441
+ playwright_deps_status = self._check_playwright_system_deps()
442
+ system_deps.append(DependencyInfo(
443
+ name="Playwright System Dependencies",
444
+ status=playwright_deps_status,
445
+ description="System libraries for browser automation",
446
+ install_command="playwright install-deps",
447
+ impact="Browser automation may fail",
448
+ is_critical=False
449
+ ))
450
+
451
+ # Python packages
452
+ python_packages = ["playwright", "scrapy", "httpx", "beautifulsoup4", "lxml"]
453
+ for pkg in python_packages:
454
+ status = self.check_python_package(pkg)
455
+ python_deps.append(DependencyInfo(
456
+ name=pkg,
457
+ status=status,
458
+ description=f"Python package: {pkg}",
459
+ install_command=f"pip install {pkg}",
460
+ impact=f"{pkg} functionality will be unavailable",
461
+ is_critical=True
462
+ ))
463
+
464
+ return ToolDependencies(
465
+ tool_name="Scraper Tool",
466
+ system_deps=system_deps,
467
+ python_deps=python_deps,
468
+ model_deps=model_deps,
469
+ optional_deps=optional_deps
470
+ )
471
+
472
+ def _check_pillow_system_deps(self) -> DependencyStatus:
473
+ """Check Pillow system dependencies."""
474
+ try:
475
+ from PIL import Image
476
+ # Try to create a simple image to test system libraries
477
+ img = Image.new('RGB', (10, 10), color='red')
478
+ img.save('/tmp/test_pillow.png')
479
+ os.remove('/tmp/test_pillow.png')
480
+ return DependencyStatus.AVAILABLE
481
+ except Exception:
482
+ return DependencyStatus.MISSING
483
+
484
+ def _check_tesseract_lang_pack(self, lang: str) -> DependencyStatus:
485
+ """Check if a Tesseract language pack is installed."""
486
+ try:
487
+ result = subprocess.run(
488
+ ["tesseract", "--list-langs"],
489
+ capture_output=True,
490
+ text=True,
491
+ timeout=10
492
+ )
493
+ if result.returncode == 0 and lang in result.stdout:
494
+ return DependencyStatus.AVAILABLE
495
+ else:
496
+ return DependencyStatus.MISSING
497
+ except Exception:
498
+ return DependencyStatus.MISSING
499
+
500
+ def _check_spacy_model(self, model: str) -> DependencyStatus:
501
+ """Check if a spaCy model is installed."""
502
+ try:
503
+ import spacy
504
+ spacy.load(model)
505
+ return DependencyStatus.AVAILABLE
506
+ except OSError:
507
+ return DependencyStatus.MISSING
508
+ except Exception:
509
+ return DependencyStatus.ERROR
510
+
511
+ def _check_transformers_model(self, model: str) -> DependencyStatus:
512
+ """Check if a Transformers model is available."""
513
+ try:
514
+ from transformers import pipeline
515
+ # Try to load the model (this will download if not present)
516
+ pipe = pipeline("summarization", model=model)
517
+ return DependencyStatus.AVAILABLE
518
+ except Exception:
519
+ return DependencyStatus.MISSING
520
+
521
+ def _check_nltk_data(self, data: str) -> DependencyStatus:
522
+ """Check if NLTK data is available."""
523
+ try:
524
+ import nltk
525
+ nltk.data.find(f'corpora/{data}')
526
+ return DependencyStatus.AVAILABLE
527
+ except LookupError:
528
+ return DependencyStatus.MISSING
529
+ except Exception:
530
+ return DependencyStatus.ERROR
531
+
532
+ def _check_spacy_pkuseg_model(self) -> DependencyStatus:
533
+ """Check if spaCy PKUSeg model is available."""
534
+ try:
535
+ import spacy_pkuseg
536
+ # Test basic functionality
537
+ seg = spacy_pkuseg.pkuseg()
538
+ test_result = list(seg.cut("测试"))
539
+ return DependencyStatus.AVAILABLE
540
+ except ImportError:
541
+ return DependencyStatus.MISSING
542
+ except Exception:
543
+ return DependencyStatus.ERROR
544
+
545
+ def _check_pyreadstat_system_deps(self) -> DependencyStatus:
546
+ """Check pyreadstat system dependencies."""
547
+ try:
548
+ import pyreadstat
549
+ return DependencyStatus.AVAILABLE
550
+ except ImportError:
551
+ return DependencyStatus.MISSING
552
+ except Exception:
553
+ return DependencyStatus.ERROR
554
+
555
+ def _check_excel_system_deps(self) -> DependencyStatus:
556
+ """Check Excel system dependencies."""
557
+ try:
558
+ import openpyxl
559
+ return DependencyStatus.AVAILABLE
560
+ except ImportError:
561
+ return DependencyStatus.MISSING
562
+ except Exception:
563
+ return DependencyStatus.ERROR
564
+
565
+ def _check_weasyprint_system_deps(self) -> DependencyStatus:
566
+ """Check WeasyPrint system dependencies."""
567
+ try:
568
+ import weasyprint
569
+ return DependencyStatus.AVAILABLE
570
+ except ImportError:
571
+ return DependencyStatus.MISSING
572
+ except Exception:
573
+ return DependencyStatus.ERROR
574
+
575
+ def _check_matplotlib_system_deps(self) -> DependencyStatus:
576
+ """Check Matplotlib system dependencies."""
577
+ try:
578
+ import matplotlib.pyplot as plt
579
+ plt.figure()
580
+ return DependencyStatus.AVAILABLE
581
+ except Exception:
582
+ return DependencyStatus.MISSING
583
+
584
+ def _check_playwright_browsers(self) -> DependencyStatus:
585
+ """Check if Playwright browsers are installed."""
586
+ browsers_dir = Path.home() / ".cache" / "ms-playwright"
587
+ if browsers_dir.exists() and any(browsers_dir.iterdir()):
588
+ return DependencyStatus.AVAILABLE
589
+ else:
590
+ return DependencyStatus.MISSING
591
+
592
+ def _check_playwright_system_deps(self) -> DependencyStatus:
593
+ """Check Playwright system dependencies."""
594
+ try:
595
+ from playwright.sync_api import sync_playwright
596
+ with sync_playwright() as p:
597
+ browser = p.chromium.launch(headless=True)
598
+ browser.close()
599
+ return DependencyStatus.AVAILABLE
600
+ except Exception:
601
+ return DependencyStatus.MISSING
602
+
603
+ def _get_tesseract_install_command(self) -> str:
604
+ """Get Tesseract installation command for current system."""
605
+ if self.system == "linux":
606
+ return "sudo apt-get install tesseract-ocr tesseract-ocr-eng"
607
+ elif self.system == "darwin":
608
+ return "brew install tesseract"
609
+ elif self.system == "windows":
610
+ return "choco install tesseract"
611
+ return "Please install Tesseract OCR manually"
612
+
613
+ def _get_pillow_system_deps_command(self) -> str:
614
+ """Get Pillow system dependencies installation command."""
615
+ if self.system == "linux":
616
+ return "sudo apt-get install libjpeg-dev zlib1g-dev libpng-dev libtiff-dev libwebp-dev libopenjp2-7-dev"
617
+ elif self.system == "darwin":
618
+ return "brew install libjpeg zlib libpng libtiff webp openjpeg"
619
+ return "Please install image processing libraries manually"
620
+
621
+ def _get_tesseract_lang_install_command(self, lang: str) -> str:
622
+ """Get Tesseract language pack installation command."""
623
+ if self.system == "linux":
624
+ return f"sudo apt-get install tesseract-ocr-{lang}"
625
+ elif self.system == "darwin":
626
+ return f"brew install tesseract-lang-{lang}"
627
+ return f"Please install Tesseract {lang} language pack manually"
628
+
629
+ def _get_java_install_command(self) -> str:
630
+ """Get Java installation command."""
631
+ if self.system == "linux":
632
+ return "sudo apt-get install openjdk-11-jdk"
633
+ elif self.system == "darwin":
634
+ return "brew install openjdk@11"
635
+ elif self.system == "windows":
636
+ return "choco install openjdk11"
637
+ return "Please install Java 11 or later manually"
638
+
639
+ def _get_pyreadstat_install_command(self) -> str:
640
+ """Get pyreadstat installation command."""
641
+ if self.system == "linux":
642
+ return "sudo apt-get install libreadstat-dev && pip install pyreadstat"
643
+ elif self.system == "darwin":
644
+ return "brew install readstat && pip install pyreadstat"
645
+ return "Please install libreadstat and pyreadstat manually"
646
+
647
+ def _get_excel_system_deps_command(self) -> str:
648
+ """Get Excel system dependencies installation command."""
649
+ if self.system == "linux":
650
+ return "sudo apt-get install libxml2-dev libxslt1-dev"
651
+ elif self.system == "darwin":
652
+ return "brew install libxml2 libxslt"
653
+ return "Please install XML processing libraries manually"
654
+
655
+ def _get_weasyprint_install_command(self) -> str:
656
+ """Get WeasyPrint installation command."""
657
+ if self.system == "linux":
658
+ return "sudo apt-get install libcairo2-dev libpango1.0-dev libgdk-pixbuf2.0-dev libffi-dev shared-mime-info"
659
+ elif self.system == "darwin":
660
+ return "brew install cairo pango gdk-pixbuf libffi"
661
+ return "Please install WeasyPrint dependencies manually"
662
+
663
+ def _get_matplotlib_system_deps_command(self) -> str:
664
+ """Get Matplotlib system dependencies installation command."""
665
+ if self.system == "linux":
666
+ return "sudo apt-get install libfreetype6-dev libpng-dev libjpeg-dev libtiff-dev libwebp-dev"
667
+ elif self.system == "darwin":
668
+ return "brew install freetype libpng libjpeg libtiff webp"
669
+ return "Please install image processing libraries manually"
670
+
671
+ def check_all_dependencies(self) -> Dict[str, ToolDependencies]:
672
+ """Check all tool dependencies."""
673
+ self.logger.info("Starting comprehensive dependency check...")
674
+
675
+ tools = {
676
+ "image": self.check_image_tool_dependencies(),
677
+ "classfire": self.check_classfire_tool_dependencies(),
678
+ "office": self.check_office_tool_dependencies(),
679
+ "stats": self.check_stats_tool_dependencies(),
680
+ "report": self.check_report_tool_dependencies(),
681
+ "scraper": self.check_scraper_tool_dependencies(),
682
+ }
683
+
684
+ return tools
685
+
686
+ def generate_report(self, tools: Dict[str, ToolDependencies]) -> str:
687
+ """Generate a comprehensive dependency report."""
688
+ report = []
689
+ report.append("=" * 80)
690
+ report.append("AIECS DEPENDENCY CHECK REPORT")
691
+ report.append("=" * 80)
692
+ report.append(f"System: {self.system.title()} {self.architecture}")
693
+ report.append(f"Python: {self.python_version}")
694
+ report.append(f"Package Manager: {self.get_system_package_manager()}")
695
+ report.append("")
696
+
697
+ total_issues = 0
698
+ critical_issues = 0
699
+
700
+ for tool_name, tool_deps in tools.items():
701
+ report.append(f"šŸ”§ {tool_deps.tool_name.upper()}")
702
+ report.append("-" * 40)
703
+
704
+ # System dependencies
705
+ if tool_deps.system_deps:
706
+ report.append("šŸ“¦ System Dependencies:")
707
+ for dep in tool_deps.system_deps:
708
+ status_icon = "āœ…" if dep.status == DependencyStatus.AVAILABLE else "āŒ" if dep.is_critical else "āš ļø"
709
+ report.append(f" {status_icon} {dep.name}: {dep.status.value}")
710
+ if dep.status != DependencyStatus.AVAILABLE:
711
+ total_issues += 1
712
+ if dep.is_critical:
713
+ critical_issues += 1
714
+ if dep.install_command:
715
+ report.append(f" Install: {dep.install_command}")
716
+ if dep.impact:
717
+ report.append(f" Impact: {dep.impact}")
718
+ report.append("")
719
+
720
+ # Python dependencies
721
+ if tool_deps.python_deps:
722
+ report.append("šŸ Python Dependencies:")
723
+ for dep in tool_deps.python_deps:
724
+ status_icon = "āœ…" if dep.status == DependencyStatus.AVAILABLE else "āŒ"
725
+ report.append(f" {status_icon} {dep.name}: {dep.status.value}")
726
+ if dep.status != DependencyStatus.AVAILABLE:
727
+ total_issues += 1
728
+ critical_issues += 1
729
+ if dep.install_command:
730
+ report.append(f" Install: {dep.install_command}")
731
+ if dep.impact:
732
+ report.append(f" Impact: {dep.impact}")
733
+ report.append("")
734
+
735
+ # Model dependencies
736
+ if tool_deps.model_deps:
737
+ report.append("šŸ¤– Model Dependencies:")
738
+ for dep in tool_deps.model_deps:
739
+ status_icon = "āœ…" if dep.status == DependencyStatus.AVAILABLE else "āŒ" if dep.is_critical else "āš ļø"
740
+ report.append(f" {status_icon} {dep.name}: {dep.status.value}")
741
+ if dep.status != DependencyStatus.AVAILABLE:
742
+ total_issues += 1
743
+ if dep.is_critical:
744
+ critical_issues += 1
745
+ if dep.install_command:
746
+ report.append(f" Install: {dep.install_command}")
747
+ if dep.impact:
748
+ report.append(f" Impact: {dep.impact}")
749
+ report.append("")
750
+
751
+ # Optional dependencies
752
+ if tool_deps.optional_deps:
753
+ report.append("šŸ”§ Optional Dependencies:")
754
+ for dep in tool_deps.optional_deps:
755
+ status_icon = "āœ…" if dep.status == DependencyStatus.AVAILABLE else "āš ļø"
756
+ report.append(f" {status_icon} {dep.name}: {dep.status.value}")
757
+ if dep.status != DependencyStatus.AVAILABLE and dep.install_command:
758
+ report.append(f" Install: {dep.install_command}")
759
+ report.append("")
760
+
761
+ # Summary
762
+ report.append("=" * 80)
763
+ report.append("SUMMARY")
764
+ report.append("=" * 80)
765
+ report.append(f"Total Issues: {total_issues}")
766
+ report.append(f"Critical Issues: {critical_issues}")
767
+ report.append(f"Optional Issues: {total_issues - critical_issues}")
768
+
769
+ if critical_issues == 0:
770
+ report.append("")
771
+ report.append("šŸŽ‰ All critical dependencies are available!")
772
+ report.append("AIECS is ready to use with full functionality.")
773
+ else:
774
+ report.append("")
775
+ report.append("āš ļø Some critical dependencies are missing.")
776
+ report.append("Please install the missing dependencies to enable full functionality.")
777
+
778
+ return "\n".join(report)
779
+
780
+ def save_report(self, report: str, filename: str = "dependency_report.txt"):
781
+ """Save the report to a file."""
782
+ with open(filename, 'w', encoding='utf-8') as f:
783
+ f.write(report)
784
+ self.logger.info(f"Report saved to {filename}")
785
+
786
+
787
+ def main():
788
+ """Main function."""
789
+ checker = DependencyChecker()
790
+
791
+ print("šŸ” Checking AIECS dependencies...")
792
+ print("This may take a few minutes for model checks...")
793
+ print()
794
+
795
+ # Check all dependencies
796
+ tools = checker.check_all_dependencies()
797
+
798
+ # Generate and display report
799
+ report = checker.generate_report(tools)
800
+ print(report)
801
+
802
+ # Save report
803
+ checker.save_report(report)
804
+
805
+ # Return exit code based on critical issues
806
+ critical_issues = sum(
807
+ 1 for tool_deps in tools.values()
808
+ for dep in tool_deps.system_deps + tool_deps.python_deps + tool_deps.model_deps
809
+ if dep.status != DependencyStatus.AVAILABLE and dep.is_critical
810
+ )
811
+
812
+ if critical_issues == 0:
813
+ print("\nāœ… All critical dependencies are available!")
814
+ return 0
815
+ else:
816
+ print(f"\nāŒ {critical_issues} critical dependencies are missing.")
817
+ return 1
818
+
819
+
820
+ if __name__ == "__main__":
821
+ sys.exit(main())
822
+
823
+
824
+
825
+