pystepmap 0.1.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.
@@ -0,0 +1,198 @@
1
+ """流程(flows.py)、平台接口(api.py)、MCP(mcp_tools.py)共用的小东西:
2
+
3
+ - identity:目录的 (设备, inode);
4
+ - 判断过期要用的、一次分析里不会变的东西(Facts:图里的 file_hashes、file_lines、那次分析用的配置),以及按分析 id
5
+ 缓存它们的 FactsCache。file_hashes 只在图里:从 10 MB 的图里解析一次要零点几秒,所以按分析 id 缓存;file_lines、
6
+ 配置从 analysis_extra 取,不用解析图。这些对同一个分析 id 永远不变(id 不重用),别的进程写库也不会让缓存过时。
7
+ - Uncovered:一次(分析的图,运行的路径)里没走到的结局,算一次、按函数分好(接口的 /uncovered 和 MCP 的
8
+ uncovered_outcomes 用)。core 的 runpath.uncovered_outcomes 对每个函数的判断和功能线无关,一条线只是挑出它涉及的
9
+ 函数、按线上的顺序排;所以算一次全部的,按函数分组,再按每条线的函数顺序拼出来,和逐条线调用的结果一样(测试里
10
+ 对过),不用留着几十 MB 的运行路径。
11
+ - place_run_functions:一次运行里的函数 sid 放到一张图上(core 的 locate_function),一次放一批。
12
+ 这里不是流程代码,不加 pystepkit 标记。
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import dataclasses
18
+ import gzip
19
+ import json
20
+ import os
21
+ import threading
22
+ from collections import OrderedDict
23
+ from dataclasses import dataclass
24
+ from pathlib import Path
25
+
26
+ from pystepmap.model import ProjectGraph, from_json
27
+ from pystepmap.query import line_functions
28
+ from pystepmap.runpath import (
29
+ Outcome,
30
+ RunPaths,
31
+ locate_function,
32
+ run_paths_from_json,
33
+ uncovered_outcomes,
34
+ )
35
+
36
+ from .store import Store
37
+
38
+
39
+ def identity(path: str | Path) -> tuple[int, int] | None:
40
+ """目录的 (设备, inode):大小写不敏感的文件系统上写法不同、或经 /System/Volumes/Data 这类固定链接到达的同一个
41
+ 目录,路径字符串不同,inode 相同。读不到时为 None。"""
42
+ try:
43
+ st = os.stat(path)
44
+ except (OSError, ValueError):
45
+ return None
46
+ return st.st_dev, st.st_ino
47
+
48
+
49
+ @dataclass(frozen=True)
50
+ class Facts:
51
+ """一次分析里不会变的、判断过期要用的东西。"""
52
+
53
+ hashes: dict[str, str] # 图里的 file_hashes
54
+ file_lines: dict | None # 结构版本 1 留下的分析为 None
55
+ config: dict | None # 这次分析用的配置;结构版本 1 留下的分析为 None
56
+
57
+
58
+ NO_FACTS = Facts({}, None, None)
59
+
60
+
61
+ def load_facts(store: Store, analysis_id: int, graph: ProjectGraph | None = None) -> Facts | None:
62
+ """从库里读一次分析的 Facts(不缓存)。graph 是已经解析好的那次分析的图(给了就不再解析图 JSON)。分析不存在
63
+ (已被清理)时 None。"""
64
+ extra = store.analysis_extra(analysis_id)
65
+ if extra is None:
66
+ return None
67
+ if graph is not None:
68
+ hashes = dict(graph.file_hashes)
69
+ else:
70
+ text = store.graph_json(analysis_id)
71
+ if text is None: # 刚被清理掉了
72
+ return None
73
+ hashes = dict(json.loads(text).get("file_hashes", {}))
74
+ return Facts(hashes, extra["file_lines"], extra["config"])
75
+
76
+
77
+ class FactsCache:
78
+ """最近用到的 size 次分析的 Facts。可以在多个线程里同时用。查的分析不存在时 None(不缓存)。"""
79
+
80
+ def __init__(self, store: Store, size: int):
81
+ self._store = store
82
+ self._size = size
83
+ self._items: OrderedDict[int, Facts] = OrderedDict()
84
+ self._lock = threading.Lock()
85
+
86
+ def get(self, analysis_id: int, graph: ProjectGraph | None = None) -> Facts | None:
87
+ with self._lock:
88
+ if analysis_id in self._items:
89
+ self._items.move_to_end(analysis_id)
90
+ return self._items[analysis_id]
91
+ facts = load_facts(self._store, analysis_id, graph)
92
+ if facts is None:
93
+ return None
94
+ with self._lock:
95
+ self._items[analysis_id] = facts
96
+ while len(self._items) > self._size:
97
+ self._items.popitem(last=False)
98
+ return facts
99
+
100
+
101
+ class Uncovered:
102
+ """一次(图,运行路径)的没走到的结局:outcomes(None) 是全部功能线的(同 uncovered_outcomes(graph, paths)),
103
+ outcomes(功能线 sid) 是那一条线的;不是这张图里的功能线时抛 LookupError。只留结果,不留图和路径。
104
+ then:运行时的那张图(graph 是运行之后重新分析的新图时给,见 graph_at_run)——运行之后才有的函数、结局算说不准,
105
+ 不算没走到。known_then:分得出哪些是运行之后才有的(graph 就是运行时的图,或者给了 then)。"""
106
+
107
+ def __init__(self, graph: ProjectGraph, paths: RunPaths, then: ProjectGraph | None = None, *,
108
+ known_then: bool = True):
109
+ self.known_then = known_then
110
+ self._all = uncovered_outcomes(graph, paths, then=then)
111
+ self._by_function: dict[str, list[Outcome]] = {}
112
+ for o in self._all:
113
+ self._by_function.setdefault(o.function, []).append(o)
114
+ self._lines = {(ln.sid or ln.id): [graph.functions[k].sid or k for k in line_functions(graph, ln)]
115
+ for ln in graph.lines}
116
+
117
+ def outcomes(self, line_sid: str | None = None) -> list[Outcome]:
118
+ if line_sid is None:
119
+ return list(self._all)
120
+ if line_sid not in self._lines:
121
+ raise LookupError(line_sid)
122
+ return [o for f in self._lines[line_sid] for o in self._by_function.get(f, ())]
123
+
124
+
125
+ def uncovered_of(store: Store, project_id: str, run_id: int, analysis_id: int, graph: ProjectGraph | None = None
126
+ ) -> Uncovered | None:
127
+ """一次运行叠到 analysis_id 那次分析的图上算出的没走到的结局(graph:已经解析好的那张图,没有时从库里取)。运行
128
+ 用的不是这次分析时,取运行时那次分析的图来分出运行之后才有的函数和结局(清理旧分析时留着最近一次全量运行用的
129
+ 那次,见 Store.prune_analyses);那次分析已经清理掉时分不出来,known_then 为 False。None:分析或运行刚被清理掉了。
130
+ 读不出来的数据抛 OSError / EOFError / ValueError。"""
131
+ run = store.run_info(project_id, run_id)
132
+ gz = store.run_paths_gz(project_id, run_id)
133
+ if graph is None:
134
+ text = store.graph_json(analysis_id)
135
+ graph = None if text is None else from_json(text)
136
+ if run is None or gz is None or graph is None:
137
+ return None
138
+ then, known = None, True
139
+ if run["analysis_id"] != analysis_id:
140
+ text = store.graph_json(run["analysis_id"]) if run["analysis_id"] is not None else None
141
+ then, known = (None, False) if text is None else (from_json(text), True)
142
+ return Uncovered(graph, run_paths_from_json(json.loads(gzip.decompress(gz))), then, known_then=known)
143
+
144
+
145
+ def _base_sid(sid: str) -> str:
146
+ """去掉结尾的重名编号 "#数字"(pystepmap.runpath 模块说明里的 base(sid))。"""
147
+ head, sep, tail = sid.rpartition("#")
148
+ return head if sep and tail.isdigit() else sid
149
+
150
+
151
+ def place_run_functions(graph: ProjectGraph, meta: RunPaths, sids: list[str]) -> list[str | None]:
152
+ """一次运行里的函数 sid 各放到图里的哪个函数(函数 key),放不上为 None——就是 core 的 locate_function(graph,
153
+ paths, sid)。meta 只要运行一级的 shapes、function_dups(tests 可以是空的)。按 core 写下的规则(pystepmap.runpath
154
+ "叠到图上"第 1 条),放一个函数只看图里和它同一个基础 sid 的函数、运行时同一个基础 sid 的 shapes,以及
155
+ function_dups;所以按基础 sid 先分好组,每次只把那一组交给 locate_function(不然每次都要扫一遍整张图、全部 shapes,
156
+ 真实项目几千个函数要几秒)。和逐个对整张图调用的结果一样(测试里对过)。"""
157
+ groups: dict[str, dict[str, object]] = {}
158
+ for key, g in graph.functions.items():
159
+ groups.setdefault(_base_sid(g.sid or key), {})[key] = g
160
+ shapes: dict[str, dict] = {}
161
+ for sid, shape in meta.shapes.items():
162
+ shapes.setdefault(_base_sid(sid), {})[sid] = shape
163
+ out: list[str | None] = []
164
+ for sid in sids:
165
+ base = _base_sid(sid)
166
+ part = dataclasses.replace(graph, functions=groups.get(base, {}), lines=[], sids={})
167
+ fg = locate_function(part, RunPaths([], meta.version, shapes.get(base, {}), meta.function_dups), sid)
168
+ out.append(None if fg is None else fg.key)
169
+ return out
170
+
171
+
172
+ def line_entries(graph: ProjectGraph, line: object) -> frozenset[str]:
173
+ """一条功能线的入口函数:派发树上每个任务的函数(根任务和它派发出去的任务;goto 的不重复算)。一个测试"走过这条
174
+ 线"指它执行过其中至少一个——只执行了线上更深处的函数(共用的登录校验、数据库会话之类,几乎每条线都涉及)不算。"""
175
+ out: set[str] = set()
176
+ stack = [line.root]
177
+ while stack:
178
+ task = stack.pop()
179
+ if task.function in graph.functions:
180
+ out.add(task.function)
181
+ stack += task.children
182
+ return frozenset(out)
183
+
184
+
185
+ def tests_on_line(store: Store, project_id: str, run_id: int, graph: ProjectGraph, line_sid: str) -> list[str] | None:
186
+ """这次运行里走过这条功能线的测试(测试 id,按字母排序;测试之外的执行不算):执行过这条线的入口函数(line_entries)
187
+ 的。线按 graph,运行的函数按 core 的规则放到 graph 上(place_run_functions)——和接口 GET …/runs/{id}?line= 的
188
+ on_line 不为 0 是同一个标准。graph 里没有这条线时抛 LookupError;这次运行没有函数索引、没有路径时 None。"""
189
+ line = next((ln for ln in graph.lines if (ln.sid or ln.id) == line_sid), None)
190
+ if line is None:
191
+ raise LookupError(line_sid)
192
+ index = store.run_function_index(project_id, run_id)
193
+ meta = None if index is None else store.run_paths_meta(project_id, run_id)
194
+ if index is None or meta is None:
195
+ return None
196
+ entries = line_entries(graph, line)
197
+ placed = place_run_functions(graph, run_paths_from_json({**meta, "tests": []}), index["functions"])
198
+ return sorted(test for test, used in index["tests"].items() if test and any(placed[i] in entries for i in used))
@@ -0,0 +1,126 @@
1
+ """读源码片段:给详情栏看节点的源码。规则沿用阶段 3 原型的开发服务器接口 /__source(原型并入平台时已删除):
2
+
3
+ - 只读已添加项目根目录之内的 .py 文件:拒绝空路径、含 NUL、绝对路径(含 Windows 盘符、反斜杠开头)、任何一段是
4
+ ".."、不是 .py、解析后在根目录外面、经符号链接指到根目录外面(或指到非 .py);不存在、不是普通文件的 404;
5
+ - 根目录必须还是添加时的那个真实目录:存下的根是解析后的真实路径,现在解析出来不一样(目录被移走后原地换成了
6
+ 符号链接)或者不再是目录时拒绝(400),不顺着换上的链接读到别处去;根目录不存在了 404;
7
+ - 行号从 1 起、含两端,一次最多 MAX_LINES 行,超出文件末尾的部分不返回;
8
+ - stale:文件内容和生成图时不一样了(按那次分析的图里 file_hashes 的 sha256 比;接口默认用最新一次分析,可以用
9
+ analysis=<id> 指定);图里没有这个文件的指纹时为 None。
10
+
11
+ 分行和解码与引擎一致(只在 \\r\\n、\\r、\\n 处分行,按编码声明解码、去掉 BOM),行号才和图对得上。
12
+ 只读,不执行被分析项目的任何代码。这里不是流程代码,不加 pystepkit 标记。
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import hashlib
18
+ import os
19
+ import re
20
+ from pathlib import Path
21
+
22
+ from pystepmap.index import decode_source, source_lines
23
+
24
+ MAX_LINES = 400
25
+ _LINE_NUMBER = re.compile(r"\d{1,9}")
26
+ _QUERY_HELP = "需要 file、start、end(行号从 1 起,end ≥ start)"
27
+
28
+
29
+ class SourceError(Exception):
30
+ """请求不能满足:status 是 HTTP 状态码(400 / 404),message 是给用户看的中文。"""
31
+
32
+ def __init__(self, status: int, message: str):
33
+ super().__init__(message)
34
+ self.status = status
35
+ self.message = message
36
+
37
+
38
+ REPLACED_ROOT = "项目目录已经不是添加时的那个目录(被移走或换成了符号链接),请删除后重新添加"
39
+
40
+
41
+ def root_problem(root: str) -> tuple[int, str] | None:
42
+ """root 是添加项目时存下的根目录(解析后的真实绝对路径)。它现在还是同一个真实目录时返回 None,否则返回
43
+ (状态码, 中文说明):不存在了 404;解析出来不是它自己(换成了符号链接)或者不再是目录 400。重新分析、过期检查
44
+ (status.staleness)也用它。"""
45
+ if not os.path.isabs(root):
46
+ return 404, "项目根不是绝对路径"
47
+ try:
48
+ real = os.path.realpath(root, strict=True)
49
+ except OSError:
50
+ return 404, f"项目目录不存在了:{root}"
51
+ if real != root or not os.path.isdir(real):
52
+ return 400, f"{REPLACED_ROOT}:{root}"
53
+ return None
54
+
55
+
56
+ def _within(root: str, path: str) -> bool:
57
+ """path 在 root 里面(不等于 root 本身);两个都是解析过的绝对路径。"""
58
+ return path != root and os.path.commonpath([root, path]) == root
59
+
60
+
61
+ def resolve_source_path(root: str, file: str) -> Path:
62
+ """把图里的相对路径解析成 root 下的一个真实的 .py 文件,返回它的真实路径;不行时抛 SourceError。"""
63
+ if not file or "\0" in file:
64
+ raise SourceError(400, "缺少文件路径")
65
+ if os.path.isabs(file) or re.match(r"[a-zA-Z]:", file) or file.startswith("\\"):
66
+ raise SourceError(400, "只接受项目内的相对路径")
67
+ if ".." in re.split(r"[\\/]+", file):
68
+ raise SourceError(400, "路径里不能有 ..")
69
+ if not file.endswith(".py"):
70
+ raise SourceError(400, "只读 .py 文件")
71
+ problem = root_problem(root)
72
+ if problem is not None:
73
+ raise SourceError(*problem)
74
+ real_root = root
75
+ target = os.path.normpath(os.path.join(real_root, file))
76
+ if not _within(real_root, target):
77
+ raise SourceError(400, "路径在项目之外")
78
+ try:
79
+ real = os.path.realpath(target, strict=True)
80
+ except OSError: # 不存在、链接成环、没有权限
81
+ raise SourceError(404, "文件不存在") from None
82
+ if not _within(real_root, real):
83
+ raise SourceError(400, "路径经符号链接指到了项目之外")
84
+ if not real.endswith(".py"):
85
+ raise SourceError(400, "只读 .py 文件")
86
+ if not os.path.isfile(real):
87
+ raise SourceError(404, "不是文件")
88
+ return Path(real)
89
+
90
+
91
+ def _decode(raw: bytes) -> str:
92
+ try:
93
+ return decode_source(raw)
94
+ except (SyntaxError, UnicodeDecodeError, LookupError): # 编码声明不认识、按声明的编码解不开
95
+ return raw.decode("utf-8", errors="replace")
96
+
97
+
98
+ def read_snippet(path: Path, file: str, start: int, end: int, expected_hash: str | None) -> dict:
99
+ """读第 start 到 end 行(start ≥ 1、end ≥ start)。返回 {file, start, end, total, lines, stale}:end 是实际返回到
100
+ 的行,start 超过文件末尾时 lines 为空、end = start - 1;total 是文件一共几行。"""
101
+ raw = Path(path).read_bytes()
102
+ rows = source_lines(_decode(raw))
103
+ total = len(rows)
104
+ last = min(end, start + MAX_LINES - 1, total)
105
+ inside = start <= total
106
+ stale = None if expected_hash is None else hashlib.sha256(raw).hexdigest() != expected_hash
107
+ return {"file": file, "start": start, "end": last if inside else start - 1, "total": total,
108
+ "lines": rows[start - 1:last] if inside else [], "stale": stale}
109
+
110
+
111
+ def _line_number(value: str | None) -> int | None:
112
+ if value is None or not _LINE_NUMBER.fullmatch(value) or int(value) < 1:
113
+ return None
114
+ return int(value)
115
+
116
+
117
+ def get_snippet(root: str, hashes: dict[str, str], file: str | None, start: str | None, end: str | None) -> dict:
118
+ """处理一次读源码请求(参数是查询串里的原文):root 是项目根目录,hashes 是拿来比的那次分析的图里的 file_hashes。"""
119
+ first, last = _line_number(start), _line_number(end)
120
+ if not file or first is None or last is None or last < first:
121
+ raise SourceError(400, _QUERY_HELP)
122
+ path = resolve_source_path(root, file)
123
+ try:
124
+ return read_snippet(path, file, first, last, hashes.get(file))
125
+ except OSError as e:
126
+ raise SourceError(404, f"读不了这个文件:{e.strerror or e}") from None
@@ -0,0 +1,116 @@
1
+ """过期检查:项目目录里的 .py 现在和某次分析时比,哪些改了、新增了、删掉了,哪些功能线因此可能过期。平台接口
2
+ (/api/projects/{id}/status)和 MCP 都用它。只读:按出图时同样的规则(同样的排除目录)重新算每个 .py 的 sha256,
3
+ 不解析源码,不执行任何代码。
4
+
5
+ 先看根目录:已经不是添加时的那个真实目录(被删、被移走或换成符号链接,sources.root_problem)或者读不了时,不去比,
6
+ 返回 {"checked": False, "reason": 中文}——core 的 current_hashes 对这些情形不报错,只会得到"全删掉了"。
7
+
8
+ 读不了的文件单列(unreadable),不算删除也不算改动:core 的 current_hashes 默默跳过读不了的文件(拿去比就显示成
9
+ "删掉了"),所以这里按它同样的口径(同一个 iter_source_files、同样的读法)自己算指纹,另外记下:
10
+ - 读的时候出错的(没有权限等);
11
+ - 分析时有指纹、现在引擎不读的路径(换成了指到项目外的符号链接、FIFO 等;新出现的这种路径不报,分析也不读它们);
12
+ - 分析时有指纹、现在列不出来的:所在的目录进不去或列不出内容(真不存在了的照样算删除)。
13
+ 这里不是流程代码,不加 pystepkit 标记。
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ import hashlib
19
+ import os
20
+ from pathlib import Path
21
+
22
+ from pystepmap.config import ConfigError, ProjectConfig, parse_config
23
+ from pystepmap.index import NOT_SOURCE_REASONS, iter_source_files
24
+ from pystepmap.stale import compare_hashes
25
+
26
+ from .sources import root_problem
27
+
28
+ MAX_FILES = 200 # 每类文件最多列出几个(另带 total 给出总数)
29
+
30
+
31
+ def _lines_of(file_lines: dict, files: list[str]) -> list[str]:
32
+ """涉及这些文件的功能线 sid,去重;按文件路径的顺序,同一文件里按图里功能线的顺序。"""
33
+ out: dict[str, None] = {}
34
+ for f in sorted(files):
35
+ for sid in file_lines.get(f, []):
36
+ out[sid] = None
37
+ return list(out)
38
+
39
+
40
+ def _scan(root: Path, config: ProjectConfig) -> tuple[dict[str, str], dict[str, str]]:
41
+ """(读得出来的文件 → sha256, 读不了的文件 → 原因),各按路径排序。指纹和 core 的 current_hashes 同口径;读不了的
42
+ 包括引擎不读的路径(iter_source_files 给出原因的那些)和读的时候出错的。"""
43
+ hashes: dict[str, str] = {}
44
+ unreadable: dict[str, str] = {}
45
+ for rel, path, reason in iter_source_files(root, config):
46
+ if path is None:
47
+ unreadable[rel] = reason
48
+ continue
49
+ try:
50
+ raw = path.read_bytes()
51
+ except OSError as e:
52
+ unreadable[rel] = e.strerror or str(e)
53
+ continue
54
+ hashes[rel] = hashlib.sha256(raw).hexdigest()
55
+ return dict(sorted(hashes.items())), dict(sorted(unreadable.items()))
56
+
57
+
58
+ def _hidden(root: str, rel: str) -> bool:
59
+ """分析时有、现在列不出来的文件,是不是因为读不了才看不见:路径本身拿不到状态(某一级目录进不去),或者文件在、
60
+ 但某一级目录列不出内容。真不存在了(或者在引擎不进入的地方,比如换成了符号链接的目录)返回 False。"""
61
+ path = os.path.join(root, rel)
62
+ try:
63
+ os.lstat(path)
64
+ except (FileNotFoundError, NotADirectoryError):
65
+ return False
66
+ except OSError: # 没有权限进某一级目录等
67
+ return True
68
+ parent = os.path.dirname(rel)
69
+ while parent:
70
+ if not os.access(os.path.join(root, parent), os.R_OK | os.X_OK):
71
+ return True
72
+ parent = os.path.dirname(parent)
73
+ return False
74
+
75
+
76
+ def staleness(root: str, config: dict, recorded: dict[str, str], file_lines: dict | None) -> dict:
77
+ """root:项目根目录(添加时存下的真实绝对路径);config:那次分析用的配置(引擎的配置 JSON);recorded:那次分析的
78
+ 图里的 file_hashes;file_lines:那次分析的 file_lines(旧版本存的分析没有,为 None)。返回
79
+
80
+ {"checked": True, "stale": bool, "changed": [...], "added": [...], "removed": [...], "unreadable": [...],
81
+ "lines": [功能线 sid…] | None, "total": {"changed": n, "added": n, "removed": n, "unreadable": n}}
82
+ 有读不了的文件时另带 "note": "有 N 个文件读不了,没有比对"
83
+
84
+ 四类文件各按路径排序、最多列 MAX_FILES 个;stale 只看改了、新增、删掉的(读不了的不算);lines 是涉及改了或删掉
85
+ 的文件的功能线(新增的文件不在任何线里),file_lines 为 None 时也为 None。没法检查时返回
86
+ {"checked": False, "reason": 中文}。"""
87
+ problem = root_problem(root)
88
+ if problem is not None:
89
+ return {"checked": False, "reason": problem[1]}
90
+ if not os.access(root, os.R_OK | os.X_OK):
91
+ return {"checked": False, "reason": f"没有权限读取项目目录:{root}"}
92
+ try:
93
+ parsed = parse_config(config)
94
+ except ConfigError as e:
95
+ return {"checked": False, "reason": f"分析配置不合法:{e}"}
96
+ try:
97
+ current, skipped = _scan(Path(root), parsed)
98
+ except OSError as e: # os.walk 自己不报错;兜底
99
+ return {"checked": False, "reason": f"读不了项目目录:{e.strerror or e}:{root}"}
100
+ unreadable = {f for f, why in skipped.items() if f in recorded or why not in NOT_SOURCE_REASONS}
101
+ unreadable |= {f for f in recorded if f not in current and f not in skipped and _hidden(root, f)}
102
+ changes = compare_hashes({f: h for f, h in recorded.items() if f not in unreadable}, current)
103
+ out = {
104
+ "checked": True,
105
+ "stale": changes.any,
106
+ "changed": changes.changed[:MAX_FILES],
107
+ "added": changes.added[:MAX_FILES],
108
+ "removed": changes.removed[:MAX_FILES],
109
+ "unreadable": sorted(unreadable)[:MAX_FILES],
110
+ "lines": None if file_lines is None else _lines_of(file_lines, changes.changed + changes.removed),
111
+ "total": {"changed": len(changes.changed), "added": len(changes.added), "removed": len(changes.removed),
112
+ "unreadable": len(unreadable)},
113
+ }
114
+ if unreadable:
115
+ out["note"] = f"有 {len(unreadable)} 个文件读不了,没有比对"
116
+ return out