jarvis-ai-assistant 0.1.222__py3-none-any.whl → 0.7.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.
Files changed (162) hide show
  1. jarvis/__init__.py +1 -1
  2. jarvis/jarvis_agent/__init__.py +1143 -245
  3. jarvis/jarvis_agent/agent_manager.py +97 -0
  4. jarvis/jarvis_agent/builtin_input_handler.py +12 -10
  5. jarvis/jarvis_agent/config_editor.py +57 -0
  6. jarvis/jarvis_agent/edit_file_handler.py +392 -99
  7. jarvis/jarvis_agent/event_bus.py +48 -0
  8. jarvis/jarvis_agent/events.py +157 -0
  9. jarvis/jarvis_agent/file_context_handler.py +79 -0
  10. jarvis/jarvis_agent/file_methodology_manager.py +117 -0
  11. jarvis/jarvis_agent/jarvis.py +1117 -147
  12. jarvis/jarvis_agent/main.py +78 -34
  13. jarvis/jarvis_agent/memory_manager.py +195 -0
  14. jarvis/jarvis_agent/methodology_share_manager.py +174 -0
  15. jarvis/jarvis_agent/prompt_manager.py +82 -0
  16. jarvis/jarvis_agent/prompts.py +46 -9
  17. jarvis/jarvis_agent/protocols.py +4 -1
  18. jarvis/jarvis_agent/rewrite_file_handler.py +141 -0
  19. jarvis/jarvis_agent/run_loop.py +146 -0
  20. jarvis/jarvis_agent/session_manager.py +9 -9
  21. jarvis/jarvis_agent/share_manager.py +228 -0
  22. jarvis/jarvis_agent/shell_input_handler.py +23 -3
  23. jarvis/jarvis_agent/stdio_redirect.py +295 -0
  24. jarvis/jarvis_agent/task_analyzer.py +212 -0
  25. jarvis/jarvis_agent/task_manager.py +154 -0
  26. jarvis/jarvis_agent/task_planner.py +496 -0
  27. jarvis/jarvis_agent/tool_executor.py +8 -4
  28. jarvis/jarvis_agent/tool_share_manager.py +139 -0
  29. jarvis/jarvis_agent/user_interaction.py +42 -0
  30. jarvis/jarvis_agent/utils.py +54 -0
  31. jarvis/jarvis_agent/web_bridge.py +189 -0
  32. jarvis/jarvis_agent/web_output_sink.py +53 -0
  33. jarvis/jarvis_agent/web_server.py +751 -0
  34. jarvis/jarvis_c2rust/__init__.py +26 -0
  35. jarvis/jarvis_c2rust/cli.py +613 -0
  36. jarvis/jarvis_c2rust/collector.py +258 -0
  37. jarvis/jarvis_c2rust/library_replacer.py +1122 -0
  38. jarvis/jarvis_c2rust/llm_module_agent.py +1300 -0
  39. jarvis/jarvis_c2rust/optimizer.py +960 -0
  40. jarvis/jarvis_c2rust/scanner.py +1681 -0
  41. jarvis/jarvis_c2rust/transpiler.py +2325 -0
  42. jarvis/jarvis_code_agent/build_validation_config.py +133 -0
  43. jarvis/jarvis_code_agent/code_agent.py +1605 -178
  44. jarvis/jarvis_code_agent/code_analyzer/__init__.py +62 -0
  45. jarvis/jarvis_code_agent/code_analyzer/base_language.py +74 -0
  46. jarvis/jarvis_code_agent/code_analyzer/build_validator/__init__.py +44 -0
  47. jarvis/jarvis_code_agent/code_analyzer/build_validator/base.py +102 -0
  48. jarvis/jarvis_code_agent/code_analyzer/build_validator/cmake.py +59 -0
  49. jarvis/jarvis_code_agent/code_analyzer/build_validator/detector.py +125 -0
  50. jarvis/jarvis_code_agent/code_analyzer/build_validator/fallback.py +69 -0
  51. jarvis/jarvis_code_agent/code_analyzer/build_validator/go.py +38 -0
  52. jarvis/jarvis_code_agent/code_analyzer/build_validator/java_gradle.py +44 -0
  53. jarvis/jarvis_code_agent/code_analyzer/build_validator/java_maven.py +38 -0
  54. jarvis/jarvis_code_agent/code_analyzer/build_validator/makefile.py +50 -0
  55. jarvis/jarvis_code_agent/code_analyzer/build_validator/nodejs.py +93 -0
  56. jarvis/jarvis_code_agent/code_analyzer/build_validator/python.py +129 -0
  57. jarvis/jarvis_code_agent/code_analyzer/build_validator/rust.py +54 -0
  58. jarvis/jarvis_code_agent/code_analyzer/build_validator/validator.py +154 -0
  59. jarvis/jarvis_code_agent/code_analyzer/build_validator.py +43 -0
  60. jarvis/jarvis_code_agent/code_analyzer/context_manager.py +363 -0
  61. jarvis/jarvis_code_agent/code_analyzer/context_recommender.py +18 -0
  62. jarvis/jarvis_code_agent/code_analyzer/dependency_analyzer.py +132 -0
  63. jarvis/jarvis_code_agent/code_analyzer/file_ignore.py +330 -0
  64. jarvis/jarvis_code_agent/code_analyzer/impact_analyzer.py +781 -0
  65. jarvis/jarvis_code_agent/code_analyzer/language_registry.py +185 -0
  66. jarvis/jarvis_code_agent/code_analyzer/language_support.py +89 -0
  67. jarvis/jarvis_code_agent/code_analyzer/languages/__init__.py +31 -0
  68. jarvis/jarvis_code_agent/code_analyzer/languages/c_cpp_language.py +231 -0
  69. jarvis/jarvis_code_agent/code_analyzer/languages/go_language.py +183 -0
  70. jarvis/jarvis_code_agent/code_analyzer/languages/python_language.py +219 -0
  71. jarvis/jarvis_code_agent/code_analyzer/languages/rust_language.py +209 -0
  72. jarvis/jarvis_code_agent/code_analyzer/llm_context_recommender.py +451 -0
  73. jarvis/jarvis_code_agent/code_analyzer/symbol_extractor.py +77 -0
  74. jarvis/jarvis_code_agent/code_analyzer/tree_sitter_extractor.py +48 -0
  75. jarvis/jarvis_code_agent/lint.py +275 -13
  76. jarvis/jarvis_code_agent/utils.py +142 -0
  77. jarvis/jarvis_code_analysis/checklists/loader.py +20 -6
  78. jarvis/jarvis_code_analysis/code_review.py +583 -548
  79. jarvis/jarvis_data/config_schema.json +339 -28
  80. jarvis/jarvis_git_squash/main.py +22 -13
  81. jarvis/jarvis_git_utils/git_commiter.py +171 -55
  82. jarvis/jarvis_mcp/sse_mcp_client.py +22 -15
  83. jarvis/jarvis_mcp/stdio_mcp_client.py +4 -4
  84. jarvis/jarvis_mcp/streamable_mcp_client.py +36 -16
  85. jarvis/jarvis_memory_organizer/memory_organizer.py +753 -0
  86. jarvis/jarvis_methodology/main.py +48 -63
  87. jarvis/jarvis_multi_agent/__init__.py +302 -43
  88. jarvis/jarvis_multi_agent/main.py +70 -24
  89. jarvis/jarvis_platform/ai8.py +40 -23
  90. jarvis/jarvis_platform/base.py +210 -49
  91. jarvis/jarvis_platform/human.py +11 -1
  92. jarvis/jarvis_platform/kimi.py +82 -76
  93. jarvis/jarvis_platform/openai.py +73 -1
  94. jarvis/jarvis_platform/registry.py +8 -15
  95. jarvis/jarvis_platform/tongyi.py +115 -101
  96. jarvis/jarvis_platform/yuanbao.py +89 -63
  97. jarvis/jarvis_platform_manager/main.py +194 -132
  98. jarvis/jarvis_platform_manager/service.py +122 -86
  99. jarvis/jarvis_rag/cli.py +156 -53
  100. jarvis/jarvis_rag/embedding_manager.py +155 -12
  101. jarvis/jarvis_rag/llm_interface.py +10 -13
  102. jarvis/jarvis_rag/query_rewriter.py +63 -12
  103. jarvis/jarvis_rag/rag_pipeline.py +222 -40
  104. jarvis/jarvis_rag/reranker.py +26 -3
  105. jarvis/jarvis_rag/retriever.py +270 -14
  106. jarvis/jarvis_sec/__init__.py +3605 -0
  107. jarvis/jarvis_sec/checkers/__init__.py +32 -0
  108. jarvis/jarvis_sec/checkers/c_checker.py +2680 -0
  109. jarvis/jarvis_sec/checkers/rust_checker.py +1108 -0
  110. jarvis/jarvis_sec/cli.py +116 -0
  111. jarvis/jarvis_sec/report.py +257 -0
  112. jarvis/jarvis_sec/status.py +264 -0
  113. jarvis/jarvis_sec/types.py +20 -0
  114. jarvis/jarvis_sec/workflow.py +219 -0
  115. jarvis/jarvis_smart_shell/main.py +405 -137
  116. jarvis/jarvis_stats/__init__.py +13 -0
  117. jarvis/jarvis_stats/cli.py +387 -0
  118. jarvis/jarvis_stats/stats.py +711 -0
  119. jarvis/jarvis_stats/storage.py +612 -0
  120. jarvis/jarvis_stats/visualizer.py +282 -0
  121. jarvis/jarvis_tools/ask_user.py +1 -0
  122. jarvis/jarvis_tools/base.py +18 -2
  123. jarvis/jarvis_tools/clear_memory.py +239 -0
  124. jarvis/jarvis_tools/cli/main.py +220 -144
  125. jarvis/jarvis_tools/execute_script.py +52 -12
  126. jarvis/jarvis_tools/file_analyzer.py +17 -12
  127. jarvis/jarvis_tools/generate_new_tool.py +46 -24
  128. jarvis/jarvis_tools/read_code.py +277 -18
  129. jarvis/jarvis_tools/read_symbols.py +141 -0
  130. jarvis/jarvis_tools/read_webpage.py +86 -13
  131. jarvis/jarvis_tools/registry.py +294 -90
  132. jarvis/jarvis_tools/retrieve_memory.py +227 -0
  133. jarvis/jarvis_tools/save_memory.py +194 -0
  134. jarvis/jarvis_tools/search_web.py +62 -28
  135. jarvis/jarvis_tools/sub_agent.py +205 -0
  136. jarvis/jarvis_tools/sub_code_agent.py +217 -0
  137. jarvis/jarvis_tools/virtual_tty.py +330 -62
  138. jarvis/jarvis_utils/builtin_replace_map.py +4 -5
  139. jarvis/jarvis_utils/clipboard.py +90 -0
  140. jarvis/jarvis_utils/config.py +607 -50
  141. jarvis/jarvis_utils/embedding.py +3 -0
  142. jarvis/jarvis_utils/fzf.py +57 -0
  143. jarvis/jarvis_utils/git_utils.py +251 -29
  144. jarvis/jarvis_utils/globals.py +174 -17
  145. jarvis/jarvis_utils/http.py +58 -79
  146. jarvis/jarvis_utils/input.py +899 -153
  147. jarvis/jarvis_utils/methodology.py +210 -83
  148. jarvis/jarvis_utils/output.py +220 -137
  149. jarvis/jarvis_utils/utils.py +1906 -135
  150. jarvis_ai_assistant-0.7.0.dist-info/METADATA +465 -0
  151. jarvis_ai_assistant-0.7.0.dist-info/RECORD +192 -0
  152. {jarvis_ai_assistant-0.1.222.dist-info → jarvis_ai_assistant-0.7.0.dist-info}/entry_points.txt +8 -2
  153. jarvis/jarvis_git_details/main.py +0 -265
  154. jarvis/jarvis_platform/oyi.py +0 -357
  155. jarvis/jarvis_tools/edit_file.py +0 -255
  156. jarvis/jarvis_tools/rewrite_file.py +0 -195
  157. jarvis_ai_assistant-0.1.222.dist-info/METADATA +0 -767
  158. jarvis_ai_assistant-0.1.222.dist-info/RECORD +0 -110
  159. /jarvis/{jarvis_git_details → jarvis_memory_organizer}/__init__.py +0 -0
  160. {jarvis_ai_assistant-0.1.222.dist-info → jarvis_ai_assistant-0.7.0.dist-info}/WHEEL +0 -0
  161. {jarvis_ai_assistant-0.1.222.dist-info → jarvis_ai_assistant-0.7.0.dist-info}/licenses/LICENSE +0 -0
  162. {jarvis_ai_assistant-0.1.222.dist-info → jarvis_ai_assistant-0.7.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,330 @@
1
+ """文件忽略工具模块。
2
+
3
+ 提供统一的文件/目录忽略逻辑,用于代码分析、依赖分析等场景。
4
+ """
5
+
6
+ from pathlib import Path
7
+ from typing import List, Set, Optional, Callable
8
+
9
+
10
+ class FileIgnorePatterns:
11
+ """文件忽略模式集合。
12
+
13
+ 定义了各种常见的需要忽略的文件和目录模式。
14
+ """
15
+
16
+ # 隐藏目录/文件(以 . 开头)
17
+ HIDDEN_PATTERNS: Set[str] = {'.git', '.svn', '.hg', '.bzr'}
18
+
19
+ # 版本控制目录
20
+ VCS_DIRS: Set[str] = {'.git', '.svn', '.hg', '.bzr', '.gitignore'}
21
+
22
+ # Python 相关
23
+ PYTHON_DIRS: Set[str] = {
24
+ '__pycache__', '.pytest_cache', '.mypy_cache', '.ruff_cache',
25
+ '.tox', '.coverage', 'htmlcov', '.hypothesis', '.ipynb_checkpoints',
26
+ '.pyre', '.pytype', 'develop-eggs', 'downloads', 'eggs', '.eggs',
27
+ 'lib', 'lib64', 'parts', 'sdist', 'var', 'wheels', 'pip-wheel-metadata',
28
+ 'share', '*.egg-info', '.installed.cfg', 'MANIFEST'
29
+ }
30
+ PYTHON_VENV_DIRS: Set[str] = {'venv', 'env', '.venv', 'virtualenv', 'ENV'}
31
+
32
+ # Rust 相关
33
+ RUST_DIRS: Set[str] = {'target', 'Cargo.lock'}
34
+
35
+ # Go 相关
36
+ GO_DIRS: Set[str] = {'vendor', 'bin', 'coverage.out'}
37
+
38
+ # Node.js 相关
39
+ NODE_DIRS: Set[str] = {
40
+ 'node_modules', '.npm', '.yarn', '.pnpm', '.turbo', '.next', '.nuxt',
41
+ 'out', 'dist', 'coverage', 'build'
42
+ }
43
+
44
+ # Java 相关
45
+ JAVA_DIRS: Set[str] = {'target', '.gradle', 'build', 'out', '*.class'}
46
+
47
+ # C/C++ 相关
48
+ C_CPP_DIRS: Set[str] = {
49
+ 'build', 'cmake-build-*', 'out', 'bin', 'obj', '*.o', '*.a', '*.so',
50
+ '*.obj', '*.dll', '*.dylib', '*.exe', '*.pdb'
51
+ }
52
+
53
+ # .NET 相关
54
+ DOTNET_DIRS: Set[str] = {'bin', 'obj', 'packages'}
55
+
56
+ # 构建产物目录(通用)
57
+ BUILD_DIRS: Set[str] = {
58
+ 'build', 'out', 'target', 'dist', 'bin', 'obj', 'cmake-build-*'
59
+ }
60
+
61
+ # 依赖目录(通用)
62
+ DEPENDENCY_DIRS: Set[str] = {
63
+ 'third_party', 'vendor', 'deps', 'dependencies', 'libs', 'libraries',
64
+ 'external', 'node_modules', 'packages'
65
+ }
66
+
67
+ # 测试目录
68
+ TEST_DIRS: Set[str] = {
69
+ 'test', 'tests', '__tests__', 'spec', 'testsuite', 'testdata',
70
+ 'test_data', 'testdata', 'fixtures', 'mocks'
71
+ }
72
+
73
+ # 性能测试目录
74
+ BENCHMARK_DIRS: Set[str] = {
75
+ 'benchmark', 'benchmarks', 'perf', 'performance', 'bench', 'benches',
76
+ 'profiling', 'profiler'
77
+ }
78
+
79
+ # 示例目录
80
+ EXAMPLE_DIRS: Set[str] = {
81
+ 'example', 'examples', 'samples', 'sample', 'demo', 'demos'
82
+ }
83
+
84
+ # 临时/缓存目录
85
+ TEMP_DIRS: Set[str] = {
86
+ 'tmp', 'temp', 'cache', '.cache', '*.tmp', '*.log', '*.swp', '*.swo'
87
+ }
88
+
89
+ # 文档目录
90
+ DOC_DIRS: Set[str] = {'docs', 'doc', 'documentation'}
91
+
92
+ # 生成代码目录
93
+ GENERATED_DIRS: Set[str] = {'generated', 'gen', 'auto-generated'}
94
+
95
+ # 其他
96
+ OTHER_DIRS: Set[str] = {
97
+ 'playground', 'sandbox', '.idea', '.vscode', '.DS_Store', 'Thumbs.db'
98
+ }
99
+
100
+ # Jarvis 特定
101
+ JARVIS_DIRS: Set[str] = {'.jarvis'}
102
+
103
+ @classmethod
104
+ def get_all_ignore_dirs(cls) -> Set[str]:
105
+ """获取所有需要忽略的目录名称集合。
106
+
107
+ Returns:
108
+ 所有忽略目录名称的集合
109
+ """
110
+ return (
111
+ cls.VCS_DIRS |
112
+ cls.PYTHON_DIRS |
113
+ cls.PYTHON_VENV_DIRS |
114
+ cls.RUST_DIRS |
115
+ cls.GO_DIRS |
116
+ cls.NODE_DIRS |
117
+ cls.JAVA_DIRS |
118
+ cls.C_CPP_DIRS |
119
+ cls.DOTNET_DIRS |
120
+ cls.BUILD_DIRS |
121
+ cls.DEPENDENCY_DIRS |
122
+ cls.TEST_DIRS |
123
+ cls.BENCHMARK_DIRS |
124
+ cls.EXAMPLE_DIRS |
125
+ cls.TEMP_DIRS |
126
+ cls.DOC_DIRS |
127
+ cls.GENERATED_DIRS |
128
+ cls.OTHER_DIRS |
129
+ cls.JARVIS_DIRS
130
+ )
131
+
132
+ @classmethod
133
+ def get_code_analysis_ignore_dirs(cls) -> Set[str]:
134
+ """获取代码分析时应该忽略的目录(不包含测试目录)。
135
+
136
+ Returns:
137
+ 代码分析忽略目录集合
138
+ """
139
+ return (
140
+ cls.VCS_DIRS |
141
+ cls.PYTHON_DIRS |
142
+ cls.PYTHON_VENV_DIRS |
143
+ cls.RUST_DIRS |
144
+ cls.GO_DIRS |
145
+ cls.NODE_DIRS |
146
+ cls.JAVA_DIRS |
147
+ cls.C_CPP_DIRS |
148
+ cls.DOTNET_DIRS |
149
+ cls.BUILD_DIRS |
150
+ cls.DEPENDENCY_DIRS |
151
+ cls.BENCHMARK_DIRS |
152
+ cls.EXAMPLE_DIRS |
153
+ cls.TEMP_DIRS |
154
+ cls.DOC_DIRS |
155
+ cls.GENERATED_DIRS |
156
+ cls.OTHER_DIRS |
157
+ cls.JARVIS_DIRS
158
+ )
159
+
160
+ @classmethod
161
+ def get_dependency_analysis_ignore_dirs(cls) -> Set[str]:
162
+ """获取依赖分析时应该忽略的目录。
163
+
164
+ Returns:
165
+ 依赖分析忽略目录集合
166
+ """
167
+ return (
168
+ cls.VCS_DIRS |
169
+ cls.BUILD_DIRS |
170
+ cls.DEPENDENCY_DIRS |
171
+ cls.TEST_DIRS |
172
+ cls.BENCHMARK_DIRS |
173
+ cls.EXAMPLE_DIRS |
174
+ cls.TEMP_DIRS |
175
+ cls.DOC_DIRS |
176
+ cls.GENERATED_DIRS |
177
+ cls.OTHER_DIRS |
178
+ cls.JARVIS_DIRS
179
+ )
180
+
181
+
182
+ class FileIgnoreFilter:
183
+ """文件忽略过滤器。
184
+
185
+ 提供统一的文件/目录过滤逻辑。
186
+ """
187
+
188
+ def __init__(
189
+ self,
190
+ ignore_dirs: Optional[Set[str]] = None,
191
+ ignore_hidden: bool = True,
192
+ custom_filter: Optional[Callable[[str], bool]] = None,
193
+ ):
194
+ """初始化文件忽略过滤器。
195
+
196
+ Args:
197
+ ignore_dirs: 要忽略的目录名称集合,如果为None则使用默认集合
198
+ ignore_hidden: 是否忽略隐藏目录(以 . 开头)
199
+ custom_filter: 自定义过滤函数,接收目录名,返回True表示忽略
200
+ """
201
+ if ignore_dirs is None:
202
+ ignore_dirs = FileIgnorePatterns.get_code_analysis_ignore_dirs()
203
+
204
+ self.ignore_dirs = ignore_dirs
205
+ self.ignore_hidden = ignore_hidden
206
+ self.custom_filter = custom_filter
207
+
208
+ def should_ignore_dir(self, dir_name: str) -> bool:
209
+ """判断是否应该忽略某个目录。
210
+
211
+ Args:
212
+ dir_name: 目录名称(不包含路径)
213
+
214
+ Returns:
215
+ 如果应该忽略返回True,否则返回False
216
+ """
217
+ # 检查隐藏目录
218
+ if self.ignore_hidden and dir_name.startswith('.'):
219
+ return True
220
+
221
+ # 检查忽略目录集合
222
+ if dir_name in self.ignore_dirs:
223
+ return True
224
+
225
+ # 检查自定义过滤器
226
+ if self.custom_filter and self.custom_filter(dir_name):
227
+ return True
228
+
229
+ return False
230
+
231
+ def should_ignore_path(self, path: str) -> bool:
232
+ """判断是否应该忽略某个路径(文件或目录)。
233
+
234
+ Args:
235
+ path: 文件或目录路径
236
+
237
+ Returns:
238
+ 如果应该忽略返回True,否则返回False
239
+ """
240
+ path_obj = Path(path)
241
+
242
+ # 检查路径中的任何部分是否应该被忽略
243
+ for part in path_obj.parts:
244
+ if self.should_ignore_dir(part):
245
+ return True
246
+
247
+ return False
248
+
249
+ def filter_dirs(self, dirs: List[str]) -> List[str]:
250
+ """过滤目录列表,移除应该忽略的目录。
251
+
252
+ 这个方法可以直接用于 os.walk 的 dirs 列表修改:
253
+ dirs[:] = filter.filter_dirs(dirs)
254
+
255
+ Args:
256
+ dirs: 目录名称列表
257
+
258
+ Returns:
259
+ 过滤后的目录列表
260
+ """
261
+ return [d for d in dirs if not self.should_ignore_dir(d)]
262
+
263
+ def filter_paths(self, paths: List[str]) -> List[str]:
264
+ """过滤路径列表,移除应该忽略的路径。
265
+
266
+ Args:
267
+ paths: 路径列表
268
+
269
+ Returns:
270
+ 过滤后的路径列表
271
+ """
272
+ return [p for p in paths if not self.should_ignore_path(p)]
273
+
274
+
275
+ # 预定义的过滤器实例
276
+ DEFAULT_FILTER = FileIgnoreFilter()
277
+ CODE_ANALYSIS_FILTER = FileIgnoreFilter(
278
+ ignore_dirs=FileIgnorePatterns.get_code_analysis_ignore_dirs()
279
+ )
280
+ DEPENDENCY_ANALYSIS_FILTER = FileIgnoreFilter(
281
+ ignore_dirs=FileIgnorePatterns.get_dependency_analysis_ignore_dirs()
282
+ )
283
+ ALL_IGNORE_FILTER = FileIgnoreFilter(
284
+ ignore_dirs=FileIgnorePatterns.get_all_ignore_dirs()
285
+ )
286
+
287
+
288
+ def should_ignore_dir(dir_name: str, ignore_dirs: Optional[Set[str]] = None) -> bool:
289
+ """便捷函数:判断是否应该忽略目录。
290
+
291
+ Args:
292
+ dir_name: 目录名称
293
+ ignore_dirs: 忽略目录集合,如果为None使用默认集合
294
+
295
+ Returns:
296
+ 如果应该忽略返回True
297
+ """
298
+ if ignore_dirs is None:
299
+ ignore_dirs = FileIgnorePatterns.get_code_analysis_ignore_dirs()
300
+
301
+ # 隐藏目录
302
+ if dir_name.startswith('.'):
303
+ return True
304
+
305
+ # 忽略目录集合
306
+ return dir_name in ignore_dirs
307
+
308
+
309
+ def filter_walk_dirs(dirs: List[str], ignore_dirs: Optional[Set[str]] = None) -> List[str]:
310
+ """便捷函数:过滤 os.walk 的 dirs 列表。
311
+
312
+ 用法:
313
+ for root, dirs, files in os.walk(path):
314
+ dirs[:] = filter_walk_dirs(dirs)
315
+
316
+ Args:
317
+ dirs: os.walk 返回的目录列表
318
+ ignore_dirs: 忽略目录集合,如果为None使用默认集合
319
+
320
+ Returns:
321
+ 过滤后的目录列表
322
+ """
323
+ if ignore_dirs is None:
324
+ ignore_dirs = FileIgnorePatterns.get_code_analysis_ignore_dirs()
325
+
326
+ return [
327
+ d for d in dirs
328
+ if not (d.startswith('.') or d in ignore_dirs)
329
+ ]
330
+