diffcone 0.6.0__tar.gz → 0.7.0__tar.gz
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.
- {diffcone-0.6.0 → diffcone-0.7.0}/PKG-INFO +1 -1
- {diffcone-0.6.0 → diffcone-0.7.0}/pyproject.toml +2 -2
- {diffcone-0.6.0 → diffcone-0.7.0}/pyproject.toml.orig +2 -2
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/cache.py +89 -12
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/check.py +17 -11
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/child.py +213 -8
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/ci_report.py +57 -2
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/classify.py +58 -18
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/cli.py +103 -35
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/collect.py +396 -67
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/declarations.py +115 -7
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/discovery/pytest_static.py +2 -2
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/discovery/session_state.py +2 -1
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/evidence.py +186 -26
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/evidence_plan.py +431 -38
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/execution.py +18 -5
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/indexer/__init__.py +7 -3
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/indexer/aliases.py +63 -1
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/indexer/core.py +415 -83
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/indexer/facts.py +51 -7
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/indexer/literals.py +99 -1
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/indexer/references.py +622 -134
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/indexer/resolver.py +64 -0
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/indexer/scopes.py +6 -0
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/indexer/state.py +6 -0
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/indexer/symbols.py +4 -0
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/indexer/writes.py +144 -9
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/model.py +232 -3
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/planner.py +540 -108
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/report.py +103 -7
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/selection.py +32 -6
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/snapshot.py +85 -37
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/testing.py +47 -11
- {diffcone-0.6.0 → diffcone-0.7.0}/LICENSE +0 -0
- {diffcone-0.6.0 → diffcone-0.7.0}/README.md +0 -0
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/__init__.py +0 -0
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/cython.py +0 -0
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/discovery/__init__.py +0 -0
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/discovery/asv_static.py +0 -0
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/discovery/common.py +0 -0
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/indexer/definitions.py +0 -0
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/indexer/dynamics.py +0 -0
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/indexer/lazy.py +0 -0
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/indexer/patches.py +0 -0
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/indexer/process.py +0 -0
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/indexer/scripts.py +0 -0
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/indexer/syntax.py +0 -0
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/indexer/uses.py +0 -0
- {diffcone-0.6.0 → diffcone-0.7.0}/src/diffcone/manifest.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: diffcone
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: Static-first, function-level change-impact engine for Python: which tests and benchmarks a change can affect, and why
|
|
5
5
|
Keywords: test selection,test impact analysis,change impact,pytest,asv,ci
|
|
6
6
|
Author: Bearing Research
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "diffcone"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.7.0"
|
|
4
4
|
description = "Static-first, function-level change-impact engine for Python: which tests and benchmarks a change can affect, and why"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -42,7 +42,7 @@ Issues = "https://github.com/bearing-research/diffcone/issues"
|
|
|
42
42
|
Changelog = "https://github.com/bearing-research/diffcone/blob/main/CHANGELOG.md"
|
|
43
43
|
|
|
44
44
|
[project.scripts]
|
|
45
|
-
diffcone = "diffcone.cli:
|
|
45
|
+
diffcone = "diffcone.cli:entry"
|
|
46
46
|
|
|
47
47
|
[build-system]
|
|
48
48
|
requires = ["uv_build>=0.8,<1"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "diffcone"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.7.0"
|
|
4
4
|
description = "Static-first, function-level change-impact engine for Python: which tests and benchmarks a change can affect, and why"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -33,7 +33,7 @@ Issues = "https://github.com/bearing-research/diffcone/issues"
|
|
|
33
33
|
Changelog = "https://github.com/bearing-research/diffcone/blob/main/CHANGELOG.md"
|
|
34
34
|
|
|
35
35
|
[project.scripts]
|
|
36
|
-
diffcone = "diffcone.cli:
|
|
36
|
+
diffcone = "diffcone.cli:entry"
|
|
37
37
|
|
|
38
38
|
[build-system]
|
|
39
39
|
requires = ["uv_build>=0.8,<1"]
|
|
@@ -31,7 +31,10 @@ import re
|
|
|
31
31
|
import sqlite3
|
|
32
32
|
import sys
|
|
33
33
|
import tempfile
|
|
34
|
-
from
|
|
34
|
+
from collections import defaultdict
|
|
35
|
+
from dataclasses import asdict, dataclass, fields
|
|
36
|
+
from functools import cache
|
|
37
|
+
from operator import attrgetter
|
|
35
38
|
from pathlib import Path
|
|
36
39
|
from typing import Any
|
|
37
40
|
|
|
@@ -44,6 +47,7 @@ from diffcone.model import (
|
|
|
44
47
|
AnalysisError,
|
|
45
48
|
Edge,
|
|
46
49
|
EdgeKind,
|
|
50
|
+
EdgeSet,
|
|
47
51
|
ExternalReference,
|
|
48
52
|
SnapshotInfo,
|
|
49
53
|
SnapshotKind,
|
|
@@ -87,6 +91,14 @@ from diffcone.model import (
|
|
|
87
91
|
# read for what follows it, and the receiver of a call naming its
|
|
88
92
|
# attributes literally (``monkeypatch.setattr(m.sys, "x", v)``) for those
|
|
89
93
|
# attributes only (audit round 8, V30);
|
|
94
|
+
# 74: conanfile.py under a root is a build script;
|
|
95
|
+
# 75: a whole index stores each edge as a [source, target, kind, detail] list;
|
|
96
|
+
# 76: ... and the mutated_by edges of writers sharing one set of states as one
|
|
97
|
+
# [states, writers] record (writes_hubs);
|
|
98
|
+
# 77: ... read into an EdgeSet as hubs, edges at a log-callbacks node kept apart;
|
|
99
|
+
# 78: escaped_classes follows what is handed on through names, holders
|
|
100
|
+
# (attributes, module variables, returns), containers and fixtures
|
|
101
|
+
# (audit round 9, Y25);
|
|
90
102
|
# 59: a class attribute bound once to a value that cannot change in place
|
|
91
103
|
# is no root of its class (audit round 6, T24); an instance holds the
|
|
92
104
|
# arguments its constructor was handed, and only a write that may reach
|
|
@@ -145,7 +157,7 @@ from diffcone.model import (
|
|
|
145
157
|
# and modules (indexer.uses); 28: __subclasses__ reads; 27: type
|
|
146
158
|
# parameters, unnameable build scripts as other files; 26: escaped values;
|
|
147
159
|
# 25: external sites; 24: docstring decorators; 23: open classes
|
|
148
|
-
INDEX_FORMAT =
|
|
160
|
+
INDEX_FORMAT = 78
|
|
149
161
|
|
|
150
162
|
|
|
151
163
|
def _indexer_fingerprint() -> str:
|
|
@@ -192,7 +204,7 @@ def _write_json_atomic(path: Path, data: Any) -> None:
|
|
|
192
204
|
make_own_dir(path.parent)
|
|
193
205
|
fd, tmp = tempfile.mkstemp(dir=path.parent, suffix=".tmp")
|
|
194
206
|
with os.fdopen(fd, "w", encoding="utf-8") as f:
|
|
195
|
-
|
|
207
|
+
_dump(data, f)
|
|
196
208
|
os.replace(tmp, path)
|
|
197
209
|
except (OSError, TypeError, ValueError):
|
|
198
210
|
if tmp is not None:
|
|
@@ -202,6 +214,49 @@ def _write_json_atomic(path: Path, data: Any) -> None:
|
|
|
202
214
|
pass
|
|
203
215
|
|
|
204
216
|
|
|
217
|
+
_CHUNK = 10_000
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def _dump(data: Any, f: Any) -> None:
|
|
221
|
+
"""``json.dump(data, f)``, byte for byte, through the C encoder:
|
|
222
|
+
``json.dump`` encodes in Python (a pandas index took minutes), and
|
|
223
|
+
``json.dumps`` of the whole would hold the text a second time. A
|
|
224
|
+
top-level list is encoded a chunk of items at a time."""
|
|
225
|
+
if not isinstance(data, dict):
|
|
226
|
+
f.write(json.dumps(data))
|
|
227
|
+
return
|
|
228
|
+
f.write("{")
|
|
229
|
+
for i, (key, value) in enumerate(data.items()):
|
|
230
|
+
f.write((", " if i else "") + json.dumps(key) + ": ")
|
|
231
|
+
if isinstance(value, list) and len(value) > _CHUNK:
|
|
232
|
+
f.write("[")
|
|
233
|
+
for j in range(0, len(value), _CHUNK):
|
|
234
|
+
f.write((", " if j else "") + json.dumps(value[j : j + _CHUNK])[1:-1])
|
|
235
|
+
f.write("]")
|
|
236
|
+
else:
|
|
237
|
+
f.write(json.dumps(value))
|
|
238
|
+
f.write("}")
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
@cache
|
|
242
|
+
def _field_names(cls: Any) -> tuple[str, ...]: # a dataclass type
|
|
243
|
+
return tuple(f.name for f in fields(cls))
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def _record(obj: Any) -> dict[str, Any]:
|
|
247
|
+
"""A flat dataclass record as a dict of its fields: what ``asdict`` gives
|
|
248
|
+
in JSON, without its deep copy of every value (tuples stay tuples)."""
|
|
249
|
+
return {name: getattr(obj, name) for name in _field_names(type(obj))}
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
# Edge's own order (dataclass order compares the fields as a tuple), with the
|
|
253
|
+
# tuples compared in C rather than through a generated ``__lt__`` per pair.
|
|
254
|
+
_EDGE_ORDER = attrgetter("source", "target", "kind", "detail")
|
|
255
|
+
# The members by value: what ``EdgeKind(k)`` gives, without an enum call per
|
|
256
|
+
# edge (50 million on a pandas plan's two indexes).
|
|
257
|
+
_EDGE_KINDS = {kind.value: kind for kind in EdgeKind}
|
|
258
|
+
|
|
259
|
+
|
|
205
260
|
def default_cache_dir(repo: Path) -> Path:
|
|
206
261
|
return repo / ".diffcone" / "cache"
|
|
207
262
|
|
|
@@ -211,10 +266,34 @@ def index_key(commit: str, source_roots: list[str]) -> str:
|
|
|
211
266
|
return hashlib.sha256(material.encode()).hexdigest()
|
|
212
267
|
|
|
213
268
|
|
|
269
|
+
def _edges_to_dict(edges: EdgeSet) -> dict[str, list]:
|
|
270
|
+
"""The edges as lists, but those a hub of the set stands for
|
|
271
|
+
(model.EdgeSet: writers sharing their states): one ``[states, writers]``
|
|
272
|
+
record per shared set (``writes_hubs``). On pandas 9 370 writers write
|
|
273
|
+
the same 2 225 classes: 25 million edges, most of a 4 GB file, as 0.7
|
|
274
|
+
million."""
|
|
275
|
+
groups: dict[frozenset[str], list[str]] = defaultdict(list)
|
|
276
|
+
for writer, states in edges.hubs.items():
|
|
277
|
+
groups[states].append(writer)
|
|
278
|
+
return {
|
|
279
|
+
"edges": [list(_EDGE_ORDER(e)) for e in sorted(edges.plain, key=_EDGE_ORDER)],
|
|
280
|
+
"writes_hubs": sorted([sorted(st), sorted(ws)] for st, ws in groups.items()),
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def _edges_from_dict(data: dict) -> EdgeSet:
|
|
285
|
+
hubs: dict[str, frozenset[str]] = {}
|
|
286
|
+
for states, writers in data["writes_hubs"]:
|
|
287
|
+
shared = frozenset(states)
|
|
288
|
+
for writer in writers:
|
|
289
|
+
hubs[writer] = shared
|
|
290
|
+
return EdgeSet((Edge(s, t, _EDGE_KINDS[k], d) for s, t, k, d in data["edges"]), hubs)
|
|
291
|
+
|
|
292
|
+
|
|
214
293
|
def index_to_dict(index: SourceIndex) -> dict:
|
|
215
294
|
return {
|
|
216
295
|
"format": INDEX_FORMAT,
|
|
217
|
-
"snapshot":
|
|
296
|
+
"snapshot": _record(index.snapshot),
|
|
218
297
|
"modules": sorted(index.modules),
|
|
219
298
|
"failed_modules": sorted(index.failed_modules),
|
|
220
299
|
"escaped_classes": sorted(index.escaped_classes),
|
|
@@ -227,11 +306,11 @@ def index_to_dict(index: SourceIndex) -> dict:
|
|
|
227
306
|
"open_installs": {n: [list(w) for w in v] for n, v in sorted(index.open_installs.items())},
|
|
228
307
|
"other_files": dict(sorted(index.other_files.items())),
|
|
229
308
|
"file_modes": dict(sorted(index.file_modes.items())),
|
|
230
|
-
"symbols": [
|
|
231
|
-
|
|
232
|
-
"unresolved": [
|
|
233
|
-
"external": [
|
|
234
|
-
"errors": [
|
|
309
|
+
"symbols": [_record(index.symbols[s]) for s in sorted(index.symbols)],
|
|
310
|
+
**_edges_to_dict(index.edges),
|
|
311
|
+
"unresolved": [_record(u) for u in sorted(index.unresolved)],
|
|
312
|
+
"external": [_record(x) for x in sorted(index.external)],
|
|
313
|
+
"errors": [_record(e) for e in sorted(index.errors)],
|
|
235
314
|
"reflection": sorted(list(r) for r in index.reflection),
|
|
236
315
|
"external_sites": [[s, d, list(w)] for (s, d), w in sorted(index.external_sites.items())],
|
|
237
316
|
"table_imports": [
|
|
@@ -284,9 +363,7 @@ def index_from_dict(data: dict) -> SourceIndex:
|
|
|
284
363
|
),
|
|
285
364
|
modules=set(data["modules"]),
|
|
286
365
|
symbols=symbols,
|
|
287
|
-
edges=
|
|
288
|
-
Edge(e["source"], e["target"], EdgeKind(e["kind"]), e["detail"]) for e in data["edges"]
|
|
289
|
-
},
|
|
366
|
+
edges=_edges_from_dict(data),
|
|
290
367
|
unresolved={
|
|
291
368
|
UnresolvedReference(u["symbol"], UnresolvedKind(u["kind"]), u["name"], u["detail"])
|
|
292
369
|
for u in data["unresolved"]
|
|
@@ -191,6 +191,9 @@ class Failure:
|
|
|
191
191
|
kind: str # test, collection (a file failed to collect) or unknown (no target)
|
|
192
192
|
selected: bool
|
|
193
193
|
already: bool # the baseline run failed it too
|
|
194
|
+
# Where its first broken case stands in the full run (0 for the first
|
|
195
|
+
# case): the record action re-runs misses' modules in the run's order.
|
|
196
|
+
position: int = 0
|
|
194
197
|
|
|
195
198
|
|
|
196
199
|
# The ``--run`` name of diffcone's own selective run: its misses fail the check.
|
|
@@ -274,13 +277,13 @@ class CheckReport:
|
|
|
274
277
|
)
|
|
275
278
|
|
|
276
279
|
|
|
277
|
-
def _broken(cases: list[Case], targets: _Targets) -> dict[str, tuple[str, str, set[str]]]:
|
|
278
|
-
"""Test -> (outcome, kind, broken case keys
|
|
279
|
-
target where one matches. The keys keep a
|
|
280
|
-
parameters: a baseline failure of ``test_x[a]``
|
|
281
|
-
``test_x[b]``."""
|
|
282
|
-
out: dict[str, tuple[str, str, set[str]]] = {}
|
|
283
|
-
for case in cases:
|
|
280
|
+
def _broken(cases: list[Case], targets: _Targets) -> dict[str, tuple[str, str, set[str], int]]:
|
|
281
|
+
"""Test -> (outcome, kind, broken case keys, position of the first) for
|
|
282
|
+
every broken case, by target where one matches. The keys keep a
|
|
283
|
+
parametrized case's parameters: a baseline failure of ``test_x[a]``
|
|
284
|
+
says nothing about ``test_x[b]``."""
|
|
285
|
+
out: dict[str, tuple[str, str, set[str], int]] = {}
|
|
286
|
+
for position, case in enumerate(cases):
|
|
284
287
|
if case.outcome not in BROKEN:
|
|
285
288
|
continue
|
|
286
289
|
matched = targets.match(case)
|
|
@@ -293,7 +296,7 @@ def _broken(cases: list[Case], targets: _Targets) -> dict[str, tuple[str, str, s
|
|
|
293
296
|
else:
|
|
294
297
|
tests, kind = [case.key], "unknown"
|
|
295
298
|
for test in tests:
|
|
296
|
-
out.setdefault(test, (case.outcome, kind, set()))[2].add(case.key)
|
|
299
|
+
out.setdefault(test, (case.outcome, kind, set(), position))[2].add(case.key)
|
|
297
300
|
return out
|
|
298
301
|
|
|
299
302
|
|
|
@@ -328,7 +331,9 @@ def check(
|
|
|
328
331
|
before = _broken(baseline, targets) if baseline is not None else {}
|
|
329
332
|
# Already failing: every case that broke also broke at the baseline.
|
|
330
333
|
already = {
|
|
331
|
-
test
|
|
334
|
+
test
|
|
335
|
+
for test, (_, _, keys, _) in broken.items()
|
|
336
|
+
if test in before and keys <= before[test][2]
|
|
332
337
|
}
|
|
333
338
|
|
|
334
339
|
def selected(test: str, kind: str) -> bool:
|
|
@@ -337,8 +342,8 @@ def check(
|
|
|
337
342
|
return test in targets.selected
|
|
338
343
|
|
|
339
344
|
failures = [
|
|
340
|
-
Failure(test, outcome, kind, selected(test, kind), test in already)
|
|
341
|
-
for test, (outcome, kind, _) in sorted(broken.items())
|
|
345
|
+
Failure(test, outcome, kind, selected(test, kind), test in already, position)
|
|
346
|
+
for test, (outcome, kind, _, position) in sorted(broken.items())
|
|
342
347
|
]
|
|
343
348
|
new = {f.test for f in failures if not f.already}
|
|
344
349
|
run_reports = []
|
|
@@ -434,6 +439,7 @@ def to_dict(report: CheckReport) -> dict:
|
|
|
434
439
|
"kind": f.kind,
|
|
435
440
|
"selected": f.selected,
|
|
436
441
|
"already_failing": f.already,
|
|
442
|
+
"position": f.position,
|
|
437
443
|
}
|
|
438
444
|
for f in report.failures
|
|
439
445
|
],
|
|
@@ -93,6 +93,9 @@ LAUNCHERS = (("uv", ("run",)),)
|
|
|
93
93
|
# compiled extensions from the checkout's sources (pandas): it runs no
|
|
94
94
|
# Python of the project, and a change to those sources is planned by the
|
|
95
95
|
# compiled-source rules; a Python process it starts (Cython) is followed.
|
|
96
|
+
# Only that ``ninja``: the recorders flag any other as it starts
|
|
97
|
+
# (``unexempt``, ``meson_rebuild``), and any of these programs pointed at
|
|
98
|
+
# the checkout (``pointed``).
|
|
96
99
|
TOOLS = (
|
|
97
100
|
("ninja", ()),
|
|
98
101
|
("uv", ("sync",)),
|
|
@@ -121,13 +124,19 @@ def system_query(argv: list[str] | None) -> bool:
|
|
|
121
124
|
maps: projects testing locale handling ask at import (pandas'
|
|
122
125
|
``get_locales``, while its test modules are collected). ``ps``, which
|
|
123
126
|
lists processes (shellingham's shell detection, run at import by
|
|
124
|
-
typer's tests).
|
|
125
|
-
|
|
126
|
-
|
|
127
|
+
typer's tests). ``fc-list``, which lists the fonts the machine's
|
|
128
|
+
fontconfig names (matplotlib builds its font cache on first use, so on a
|
|
129
|
+
fresh machine, a CI runner, a test module importing it runs ``fc-list``
|
|
130
|
+
as it is collected); building fontconfig's cache is ``fc-cache``'s, not
|
|
131
|
+
a query. And ``git`` asking about the repository rather than its files
|
|
132
|
+
(``git_query``: pytest-benchmark tags benchmarks with the commit as it
|
|
133
|
+
adds its options, in every run). By the command line only: the
|
|
134
|
+
recorders flag a query whose environment or directory points it at the
|
|
135
|
+
checkout as it starts (``pointed``)."""
|
|
127
136
|
if not argv:
|
|
128
137
|
return False
|
|
129
138
|
name = os.path.basename(argv[0]).lower().removesuffix(".exe")
|
|
130
|
-
if name in ("uname", "ps"):
|
|
139
|
+
if name in ("uname", "ps", "fc-list"):
|
|
131
140
|
return True
|
|
132
141
|
if name == "git":
|
|
133
142
|
return git_query(argv[1:])
|
|
@@ -196,6 +205,181 @@ def git_query(args: list[str]) -> bool:
|
|
|
196
205
|
return False
|
|
197
206
|
|
|
198
207
|
|
|
208
|
+
# Variables that point a machine query, or ``ninja``, at files of their
|
|
209
|
+
# choosing: fontconfig's configuration and font directories, git's
|
|
210
|
+
# repository, work tree, objects and configuration, ``file``'s magic
|
|
211
|
+
# database, the locales ``locale -a`` lists, and where all of them look by
|
|
212
|
+
# default (``HOME``, the XDG directories). Values are paths or lists of
|
|
213
|
+
# them (``os.pathsep``); a relative one is the spawn's working directory's.
|
|
214
|
+
_POINTING_ENV = (
|
|
215
|
+
"FONTCONFIG_FILE",
|
|
216
|
+
"FONTCONFIG_PATH",
|
|
217
|
+
"FONTCONFIG_SYSROOT",
|
|
218
|
+
"GIT_DIR",
|
|
219
|
+
"GIT_WORK_TREE",
|
|
220
|
+
"GIT_COMMON_DIR",
|
|
221
|
+
"GIT_INDEX_FILE",
|
|
222
|
+
"GIT_OBJECT_DIRECTORY",
|
|
223
|
+
"GIT_ALTERNATE_OBJECT_DIRECTORIES",
|
|
224
|
+
"GIT_CONFIG",
|
|
225
|
+
"GIT_CONFIG_GLOBAL",
|
|
226
|
+
"GIT_CONFIG_SYSTEM",
|
|
227
|
+
"GIT_EXEC_PATH",
|
|
228
|
+
"MAGIC",
|
|
229
|
+
"LOCPATH",
|
|
230
|
+
"HOME",
|
|
231
|
+
"XDG_CONFIG_HOME",
|
|
232
|
+
"XDG_DATA_HOME",
|
|
233
|
+
"XDG_CACHE_HOME",
|
|
234
|
+
"XDG_CONFIG_DIRS",
|
|
235
|
+
"XDG_DATA_DIRS",
|
|
236
|
+
)
|
|
237
|
+
# Configuration given in the environment itself, whose values may name any
|
|
238
|
+
# file or program: what the query then reads is unknown.
|
|
239
|
+
_CONFIGURING_ENV = ("GIT_CONFIG_PARAMETERS", "GIT_CONFIG_COUNT")
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def exempt_program(argv: list[str] | None) -> bool:
|
|
243
|
+
"""Whether the spawn accounting takes ``argv`` at its word as a program
|
|
244
|
+
that runs nothing of the project: a system query, or a build tool."""
|
|
245
|
+
return _matches(argv, TOOLS) or system_query(argv)
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def _in_checkout(path: str, roots: tuple[str, ...], owned: tuple[str, ...]) -> bool:
|
|
249
|
+
"""Whether the absolute ``path`` is a file or directory of the checkout,
|
|
250
|
+
its root included: not the repository's own ``.git``, nor what an
|
|
251
|
+
environment inside the checkout owns (installed code)."""
|
|
252
|
+
real = os.path.normcase(os.path.realpath(path)) + os.sep
|
|
253
|
+
for root in roots:
|
|
254
|
+
if not real.startswith(root):
|
|
255
|
+
continue
|
|
256
|
+
rel = real[len(root) :]
|
|
257
|
+
if rel.startswith(".git" + os.sep):
|
|
258
|
+
return False
|
|
259
|
+
return not any(rel.startswith(o) or rel == o + os.sep for o in owned)
|
|
260
|
+
return False
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def pointed(
|
|
264
|
+
argv: list[str],
|
|
265
|
+
executable: Any,
|
|
266
|
+
cwd: Any,
|
|
267
|
+
env: Any,
|
|
268
|
+
roots: tuple[str, ...],
|
|
269
|
+
owned: tuple[str, ...] = (),
|
|
270
|
+
) -> str | None:
|
|
271
|
+
"""Why an exempt program (``exempt_program``) is not what its name says
|
|
272
|
+
here, or None: the program found is a file of the checkout (a test's
|
|
273
|
+
stand-in on ``PATH``); a variable of its environment points it at files
|
|
274
|
+
of the checkout (``FONTCONFIG_FILE``, ``GIT_DIR``, ``HOME``, ...), or
|
|
275
|
+
configures it some way nothing here reads (``GIT_CONFIG_PARAMETERS``);
|
|
276
|
+
or ``git`` runs anywhere but the checkout root (its working directory,
|
|
277
|
+
``-C``: a repository the tests keep as data). ``env`` None is this
|
|
278
|
+
process's environment, ``cwd`` None its working directory; ``roots``
|
|
279
|
+
end in a separator; ``owned``: what environments inside the checkout
|
|
280
|
+
own (``environments``). A program that cannot be found starts nothing."""
|
|
281
|
+
try:
|
|
282
|
+
environ = os.environ if env is None else env
|
|
283
|
+
base = os.path.abspath(os.getcwd() if cwd is None else os.fsdecode(os.fspath(cwd)))
|
|
284
|
+
|
|
285
|
+
def inside(path: str) -> bool:
|
|
286
|
+
return _in_checkout(os.path.join(base, path), roots, owned)
|
|
287
|
+
|
|
288
|
+
name = os.path.basename(argv[0])
|
|
289
|
+
program = os.fsdecode(executable) if executable is not None else argv[0]
|
|
290
|
+
if os.sep in program or (os.altsep and os.altsep in program):
|
|
291
|
+
found: str | None = program
|
|
292
|
+
else:
|
|
293
|
+
import shutil
|
|
294
|
+
|
|
295
|
+
found = shutil.which(program, path=environ.get("PATH"))
|
|
296
|
+
if found is None:
|
|
297
|
+
return None
|
|
298
|
+
if inside(found):
|
|
299
|
+
return f"{name} is {found}, a file of the checkout"
|
|
300
|
+
for variable in _CONFIGURING_ENV:
|
|
301
|
+
if variable in environ:
|
|
302
|
+
return f"{name} ran with {variable} set"
|
|
303
|
+
for variable in _POINTING_ENV:
|
|
304
|
+
value = environ.get(variable)
|
|
305
|
+
if not value:
|
|
306
|
+
continue
|
|
307
|
+
for part in os.fsdecode(value).split(os.pathsep):
|
|
308
|
+
if part and inside(part):
|
|
309
|
+
return f"{name} ran with {variable}={part}, in the checkout"
|
|
310
|
+
if name.lower().removesuffix(".exe") == "git":
|
|
311
|
+
directory = base
|
|
312
|
+
rest = argv[1:]
|
|
313
|
+
while len(rest) > 1 and rest[0] == "-C":
|
|
314
|
+
directory = os.path.join(directory, rest[1])
|
|
315
|
+
rest = rest[2:]
|
|
316
|
+
if os.path.normcase(os.path.realpath(directory)) + os.sep not in roots:
|
|
317
|
+
return f"git ran in {directory}, not the checkout's root"
|
|
318
|
+
except (TypeError, ValueError, OSError) as exc:
|
|
319
|
+
return f"{argv[0]}: {type(exc).__name__}: {exc}"
|
|
320
|
+
return None
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
# meson-python's editable loader rebuilds the project's compiled extensions
|
|
324
|
+
# as it is imported (``_<dist>_editable_loader.py``, a copy of
|
|
325
|
+
# ``mesonpy/_editable.py`` installed in site-packages): ``MesonpyMetaFinder``
|
|
326
|
+
# runs its build command (``[ninja, *compile args]``; ``-n`` added for its
|
|
327
|
+
# dry run) in its build directory, from ``_rebuild`` or ``_work_to_do``.
|
|
328
|
+
_MESON_LOADER_METHODS = frozenset({"_rebuild", "_work_to_do"})
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
def meson_rebuild(
|
|
332
|
+
argv: list[str], cwd: Any, frame: Any, roots: tuple[str, ...], owned: tuple[str, ...] = ()
|
|
333
|
+
) -> bool:
|
|
334
|
+
"""Whether ``ninja`` is started by meson-python's editable loader: a
|
|
335
|
+
frame on the stack from ``frame`` up is ``MesonpyMetaFinder._rebuild``
|
|
336
|
+
or ``_work_to_do`` in a module named ``_<dist>_editable_loader`` outside
|
|
337
|
+
the checkout, and the command line is the finder's own build command
|
|
338
|
+
(or its dry run), run in the finder's build directory."""
|
|
339
|
+
for _ in range(32):
|
|
340
|
+
if frame is None:
|
|
341
|
+
return False
|
|
342
|
+
code = frame.f_code
|
|
343
|
+
if code.co_name in _MESON_LOADER_METHODS:
|
|
344
|
+
module = str(frame.f_globals.get("__name__", ""))
|
|
345
|
+
finder = frame.f_locals.get("self")
|
|
346
|
+
if (
|
|
347
|
+
module.startswith("_")
|
|
348
|
+
and module.endswith("_editable_loader")
|
|
349
|
+
and type(finder).__name__ == "MesonpyMetaFinder"
|
|
350
|
+
and not _in_checkout(os.path.abspath(code.co_filename), roots, owned)
|
|
351
|
+
):
|
|
352
|
+
command = list(getattr(finder, "_build_cmd", None) or ())
|
|
353
|
+
path = getattr(finder, "_build_path", None)
|
|
354
|
+
if not command or path is None or cwd is None:
|
|
355
|
+
return False
|
|
356
|
+
same_dir = os.path.realpath(os.fsdecode(cwd)) == os.path.realpath(path)
|
|
357
|
+
return same_dir and list(argv) in (command, [*command, "-n"])
|
|
358
|
+
frame = frame.f_back
|
|
359
|
+
return False
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
def unexempt(
|
|
363
|
+
event_args: Any, roots: tuple[str, ...], owned: tuple[str, ...], frame: Any
|
|
364
|
+
) -> str | None:
|
|
365
|
+
"""For a ``subprocess.Popen`` audit event (``executable, args, cwd,
|
|
366
|
+
env``) of a program the spawn accounting exempts by its name
|
|
367
|
+
(``exempt_program``), why the exemption does not hold here (``pointed``;
|
|
368
|
+
``ninja`` not started by meson-python's editable loader, a test driving
|
|
369
|
+
a build of its own), else None."""
|
|
370
|
+
argv = argv_of(event_args)
|
|
371
|
+
if not argv or not exempt_program(argv):
|
|
372
|
+
return None
|
|
373
|
+
executable = event_args[0] if len(event_args) > 0 else None
|
|
374
|
+
cwd = event_args[2] if len(event_args) > 2 else None
|
|
375
|
+
env = event_args[3] if len(event_args) > 3 else None
|
|
376
|
+
if os.path.basename(argv[0]).lower().removesuffix(".exe") == "ninja":
|
|
377
|
+
if not meson_rebuild(argv, cwd, frame, roots, owned):
|
|
378
|
+
return f"{' '.join(argv)[:200]}: ninja not started by meson-python's editable loader"
|
|
379
|
+
return None
|
|
380
|
+
return pointed(argv, executable, cwd, env, roots, owned)
|
|
381
|
+
|
|
382
|
+
|
|
199
383
|
# --------------------------------------------------------------------------- spawn accounting
|
|
200
384
|
|
|
201
385
|
|
|
@@ -670,10 +854,26 @@ def sqlite_path(database: Any) -> str | None:
|
|
|
670
854
|
# (``pkgutil.get_data``, ``importlib.resources``), not to import a module.
|
|
671
855
|
DATA_READERS = frozenset({"get_data", "open_resource", "read_binary", "read_text"})
|
|
672
856
|
# Starts that raise no audit event: ``multiprocessing``'s spawn and
|
|
673
|
-
# forkserver children (through ``_posixsubprocess.fork_exec``), and
|
|
674
|
-
#
|
|
675
|
-
#
|
|
676
|
-
|
|
857
|
+
# forkserver children (through ``_posixsubprocess.fork_exec``), and code
|
|
858
|
+
# run in a subinterpreter, which this interpreter's monitoring does not
|
|
859
|
+
# see: creating one, and every call that runs code in one, wherever it was
|
|
860
|
+
# created (an earlier test's, a fixture's, an ``InterpreterPoolExecutor``'s
|
|
861
|
+
# warm worker): ``_interpreters`` (Python 3.13+, behind
|
|
862
|
+
# ``concurrent.interpreters``) and ``_xxsubinterpreters`` (3.12).
|
|
863
|
+
# (module, function) pairs.
|
|
864
|
+
UNAUDITED_STARTS = (
|
|
865
|
+
("multiprocessing.util", "spawnv_passfds"),
|
|
866
|
+
("_interpreters", "create"),
|
|
867
|
+
("_interpreters", "exec"),
|
|
868
|
+
("_interpreters", "call"),
|
|
869
|
+
("_interpreters", "run_string"),
|
|
870
|
+
("_interpreters", "run_func"),
|
|
871
|
+
("_xxsubinterpreters", "create"),
|
|
872
|
+
("_xxsubinterpreters", "run_string"),
|
|
873
|
+
("_xxsubinterpreters", "run_func"),
|
|
874
|
+
)
|
|
875
|
+
# Of those, the ones that return the pid of a process they started.
|
|
876
|
+
PID_STARTS = frozenset({("multiprocessing.util", "spawnv_passfds")})
|
|
677
877
|
|
|
678
878
|
|
|
679
879
|
def environments(roots: tuple[str, ...]) -> tuple[str, ...]:
|
|
@@ -943,6 +1143,11 @@ def _audit(event: str, args: Any) -> None:
|
|
|
943
1143
|
# A fork goes on recording here (_forked); an exec after it flags.
|
|
944
1144
|
if event not in ("os.fork", "os.forkpty") and not in_popen(event, args):
|
|
945
1145
|
_flag(f"started a process another way ({event})")
|
|
1146
|
+
elif event == "subprocess.Popen":
|
|
1147
|
+
# A program taken at its name, pointed at the checkout.
|
|
1148
|
+
why = unexempt(args, _roots, _environments, sys._getframe(1))
|
|
1149
|
+
if why:
|
|
1150
|
+
_flag(why)
|
|
946
1151
|
elif event == "exec":
|
|
947
1152
|
caller = sys._getframe().f_back
|
|
948
1153
|
reads = annotation_reads(args[0], caller, _code_path) if args else None
|
|
@@ -13,7 +13,8 @@ uploaded, downloaded into one directory per workflow run::
|
|
|
13
13
|
|
|
14
14
|
and reports, per artifact name (one job, or one cell of a job's matrix):
|
|
15
15
|
pull-request runs (selected share, plans made from the code instead of a
|
|
16
|
-
recording and why, refusals
|
|
16
|
+
recording and why, refusals, selected tests that did not run, the paths
|
|
17
|
+
``[build] reads`` set aside) and checked pushes (checked or not and why,
|
|
17
18
|
new failures, flaky re-runs, confirmed misses), then each confirmed miss.
|
|
18
19
|
It reads files only and runs nothing, like ``check``.
|
|
19
20
|
|
|
@@ -84,6 +85,9 @@ class CellReport:
|
|
|
84
85
|
refused: int = 0
|
|
85
86
|
plan_failed: int = 0
|
|
86
87
|
not_collected: int = 0 # runs where pytest did not collect selected tests
|
|
88
|
+
# Paths ``[build] reads`` set aside (changed, outside the roots, named by
|
|
89
|
+
# no pattern), with the runs whose plan set each aside.
|
|
90
|
+
set_aside: Counter[str] = field(default_factory=Counter)
|
|
87
91
|
# Runs whose ``diffcone run`` failed after a good plan (exit 2 or more,
|
|
88
92
|
# other than 3: it refused, or pytest was interrupted or could not start).
|
|
89
93
|
run_failed: int = 0
|
|
@@ -165,6 +169,14 @@ def _plan_read(plan: dict[str, Any] | None) -> dict[str, Any] | None:
|
|
|
165
169
|
out["analysis"] = analysis
|
|
166
170
|
if "evidence_not_used" in plan:
|
|
167
171
|
out["evidence_not_used"] = plan["evidence_not_used"]
|
|
172
|
+
reads = plan.get("build_reads")
|
|
173
|
+
if isinstance(reads, dict):
|
|
174
|
+
out["build_reads"] = {"set_aside": reads.get("set_aside")}
|
|
175
|
+
elif "build_reads" in plan:
|
|
176
|
+
out["build_reads"] = reads
|
|
177
|
+
if "run" in plan:
|
|
178
|
+
# What ``run -o`` adds: the selected targets pytest did not collect.
|
|
179
|
+
out["run"] = plan["run"]
|
|
168
180
|
unselected = plan.get("unselected_targets")
|
|
169
181
|
if isinstance(unselected, list):
|
|
170
182
|
out["unselected_targets"] = [
|
|
@@ -340,6 +352,30 @@ def _unselected_reason(plan: dict[str, Any] | None, test: str) -> str | None:
|
|
|
340
352
|
return None
|
|
341
353
|
|
|
342
354
|
|
|
355
|
+
def _not_collected(plan: dict[str, Any] | None) -> bool:
|
|
356
|
+
"""Whether the plan ``run -o`` wrote says selected targets did not run:
|
|
357
|
+
pytest did not collect some, or no process loaded the selection plugin."""
|
|
358
|
+
run = (plan or {}).get("run")
|
|
359
|
+
if run is None:
|
|
360
|
+
return False
|
|
361
|
+
if not isinstance(run, dict):
|
|
362
|
+
raise TypeError(f"not a run record: {run!r}")
|
|
363
|
+
missing = run.get("not_collected") or []
|
|
364
|
+
if not isinstance(missing, list):
|
|
365
|
+
raise TypeError(f"not a list of tests: {missing!r}")
|
|
366
|
+
return bool(missing) or bool(run.get("selection_plugin_missing"))
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
def _set_aside(plan: dict[str, Any] | None) -> list[str]:
|
|
370
|
+
reads = (plan or {}).get("build_reads")
|
|
371
|
+
if reads is None:
|
|
372
|
+
return []
|
|
373
|
+
paths = reads.get("set_aside") or []
|
|
374
|
+
if not isinstance(paths, list) or not all(isinstance(p, str) for p in paths):
|
|
375
|
+
raise TypeError(f"not a list of paths: {paths!r}")
|
|
376
|
+
return paths
|
|
377
|
+
|
|
378
|
+
|
|
343
379
|
def _count(value: Any) -> int:
|
|
344
380
|
"""A count from a context: a non-negative integer, or ``ValueError``."""
|
|
345
381
|
if value is None or value == "":
|
|
@@ -389,6 +425,7 @@ def _add(art: Artifact, context: dict[str, Any], cell: CellReport, totals: _Tota
|
|
|
389
425
|
)
|
|
390
426
|
)
|
|
391
427
|
cell.from_code[str(note)] += 1
|
|
428
|
+
cell.set_aside.update(set(_set_aside(art.plan)))
|
|
392
429
|
plan_exit = context.get("plan_exit")
|
|
393
430
|
refused = (
|
|
394
431
|
plan_exit == 3
|
|
@@ -402,9 +439,11 @@ def _add(art: Artifact, context: dict[str, Any], cell: CellReport, totals: _Tota
|
|
|
402
439
|
elif refused:
|
|
403
440
|
cell.refused += 1
|
|
404
441
|
totals.refused += 1
|
|
405
|
-
elif context.get("run_exit") == 3:
|
|
442
|
+
elif context.get("run_exit") == 3 or _not_collected(art.plan):
|
|
406
443
|
# ``run`` exits 3 when pytest did not collect selected targets,
|
|
407
444
|
# or no process loaded the selection plugin: they did not run.
|
|
445
|
+
# Its ``-o`` plan says so too, whatever the exit (an older
|
|
446
|
+
# ``run`` exited with pytest's failure when a test failed too).
|
|
408
447
|
cell.not_collected += 1
|
|
409
448
|
totals.not_collected += 1
|
|
410
449
|
elif context.get("run_exit") not in (0, 1):
|
|
@@ -527,6 +566,7 @@ def to_dict(report: Report) -> dict[str, Any]:
|
|
|
527
566
|
"plan_failed": c.plan_failed,
|
|
528
567
|
"not_collected": c.not_collected,
|
|
529
568
|
"run_failed": c.run_failed,
|
|
569
|
+
"set_aside": dict(sorted(c.set_aside.items())),
|
|
530
570
|
},
|
|
531
571
|
"pushes": {
|
|
532
572
|
"runs": c.pushes,
|
|
@@ -684,6 +724,21 @@ def to_markdown(report: Report) -> str:
|
|
|
684
724
|
f"{c.not_collected} |"
|
|
685
725
|
)
|
|
686
726
|
lines.append("")
|
|
727
|
+
aside = [c for c in report.cells if c.set_aside]
|
|
728
|
+
if aside:
|
|
729
|
+
lines += [
|
|
730
|
+
"**Set aside by `[build] reads`**: changed paths outside the source roots that "
|
|
731
|
+
"no pattern of the table names, so the plans selected nothing for them. If a "
|
|
732
|
+
"test reads one, the table is wrong and those runs may have missed tests.",
|
|
733
|
+
"",
|
|
734
|
+
]
|
|
735
|
+
for c in aside:
|
|
736
|
+
shown = ", ".join(
|
|
737
|
+
f"{code_span(path)} ({n})" for path, n in sorted(c.set_aside.items())[:10]
|
|
738
|
+
)
|
|
739
|
+
more = len(c.set_aside) - 10
|
|
740
|
+
lines.append(f"- {c.name}: {shown}" + (f" and {more} more" if more > 0 else ""))
|
|
741
|
+
lines.append("")
|
|
687
742
|
pushes = [c for c in report.cells if c.pushes]
|
|
688
743
|
if pushes:
|
|
689
744
|
lines += [
|