diffcone 0.3.0__tar.gz → 0.5.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.3.0 → diffcone-0.5.0}/PKG-INFO +20 -7
- {diffcone-0.3.0 → diffcone-0.5.0}/README.md +19 -6
- {diffcone-0.3.0 → diffcone-0.5.0}/pyproject.toml +2 -1
- {diffcone-0.3.0 → diffcone-0.5.0}/pyproject.toml.orig +2 -1
- {diffcone-0.3.0 → diffcone-0.5.0}/src/diffcone/cache.py +217 -56
- {diffcone-0.3.0 → diffcone-0.5.0}/src/diffcone/check.py +185 -39
- diffcone-0.5.0/src/diffcone/child.py +1516 -0
- diffcone-0.5.0/src/diffcone/ci_report.py +616 -0
- {diffcone-0.3.0 → diffcone-0.5.0}/src/diffcone/classify.py +144 -56
- {diffcone-0.3.0 → diffcone-0.5.0}/src/diffcone/cli.py +412 -61
- diffcone-0.5.0/src/diffcone/collect.py +1727 -0
- {diffcone-0.3.0 → diffcone-0.5.0}/src/diffcone/cython.py +47 -31
- diffcone-0.5.0/src/diffcone/declarations.py +168 -0
- diffcone-0.5.0/src/diffcone/discovery/__init__.py +232 -0
- {diffcone-0.3.0 → diffcone-0.5.0}/src/diffcone/discovery/asv_static.py +233 -112
- diffcone-0.5.0/src/diffcone/discovery/common.py +227 -0
- diffcone-0.5.0/src/diffcone/discovery/pytest_static.py +5480 -0
- diffcone-0.5.0/src/diffcone/discovery/session_state.py +205 -0
- diffcone-0.5.0/src/diffcone/evidence.py +1302 -0
- diffcone-0.5.0/src/diffcone/evidence_plan.py +3636 -0
- {diffcone-0.3.0 → diffcone-0.5.0}/src/diffcone/execution.py +1067 -239
- diffcone-0.5.0/src/diffcone/indexer/__init__.py +142 -0
- diffcone-0.5.0/src/diffcone/indexer/aliases.py +302 -0
- diffcone-0.5.0/src/diffcone/indexer/core.py +1942 -0
- diffcone-0.5.0/src/diffcone/indexer/definitions.py +1067 -0
- {diffcone-0.3.0 → diffcone-0.5.0}/src/diffcone/indexer/dynamics.py +234 -114
- diffcone-0.5.0/src/diffcone/indexer/facts.py +780 -0
- diffcone-0.5.0/src/diffcone/indexer/lazy.py +813 -0
- diffcone-0.5.0/src/diffcone/indexer/literals.py +1200 -0
- diffcone-0.5.0/src/diffcone/indexer/patches.py +475 -0
- diffcone-0.5.0/src/diffcone/indexer/process.py +209 -0
- diffcone-0.5.0/src/diffcone/indexer/references.py +4604 -0
- {diffcone-0.3.0 → diffcone-0.5.0}/src/diffcone/indexer/resolver.py +821 -110
- {diffcone-0.3.0 → diffcone-0.5.0}/src/diffcone/indexer/scopes.py +155 -22
- diffcone-0.5.0/src/diffcone/indexer/scripts.py +1727 -0
- {diffcone-0.3.0 → diffcone-0.5.0}/src/diffcone/indexer/state.py +49 -2
- {diffcone-0.3.0 → diffcone-0.5.0}/src/diffcone/indexer/symbols.py +275 -59
- {diffcone-0.3.0 → diffcone-0.5.0}/src/diffcone/indexer/syntax.py +123 -0
- diffcone-0.5.0/src/diffcone/indexer/uses.py +2215 -0
- diffcone-0.5.0/src/diffcone/indexer/writes.py +1969 -0
- {diffcone-0.3.0 → diffcone-0.5.0}/src/diffcone/manifest.py +2 -2
- diffcone-0.5.0/src/diffcone/model.py +541 -0
- diffcone-0.5.0/src/diffcone/planner.py +2819 -0
- {diffcone-0.3.0 → diffcone-0.5.0}/src/diffcone/report.py +63 -5
- {diffcone-0.3.0 → diffcone-0.5.0}/src/diffcone/selection.py +89 -8
- {diffcone-0.3.0 → diffcone-0.5.0}/src/diffcone/snapshot.py +465 -80
- {diffcone-0.3.0 → diffcone-0.5.0}/src/diffcone/testing.py +37 -19
- diffcone-0.3.0/src/diffcone/ci_report.py +0 -382
- diffcone-0.3.0/src/diffcone/collect.py +0 -1063
- diffcone-0.3.0/src/diffcone/declarations.py +0 -111
- diffcone-0.3.0/src/diffcone/discovery/__init__.py +0 -121
- diffcone-0.3.0/src/diffcone/discovery/common.py +0 -130
- diffcone-0.3.0/src/diffcone/discovery/pytest_static.py +0 -2894
- diffcone-0.3.0/src/diffcone/evidence.py +0 -738
- diffcone-0.3.0/src/diffcone/evidence_plan.py +0 -1491
- diffcone-0.3.0/src/diffcone/indexer/__init__.py +0 -48
- diffcone-0.3.0/src/diffcone/indexer/core.py +0 -332
- diffcone-0.3.0/src/diffcone/indexer/definitions.py +0 -292
- diffcone-0.3.0/src/diffcone/indexer/facts.py +0 -387
- diffcone-0.3.0/src/diffcone/indexer/literals.py +0 -470
- diffcone-0.3.0/src/diffcone/indexer/references.py +0 -948
- diffcone-0.3.0/src/diffcone/model.py +0 -191
- diffcone-0.3.0/src/diffcone/planner.py +0 -1453
- {diffcone-0.3.0 → diffcone-0.5.0}/LICENSE +0 -0
- {diffcone-0.3.0 → diffcone-0.5.0}/src/diffcone/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: diffcone
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.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
|
|
@@ -31,6 +31,12 @@ Description-Content-Type: text/markdown
|
|
|
31
31
|
|
|
32
32
|
[](https://github.com/bearing-research/diffcone/actions/workflows/ci.yml)
|
|
33
33
|
[](https://bearing-research.github.io/diffcone/)
|
|
34
|
+
[](https://pypi.org/project/diffcone/)
|
|
35
|
+
[](https://pypi.org/project/diffcone/)
|
|
36
|
+
[](https://github.com/bearing-research/diffcone/blob/main/LICENSE)
|
|
37
|
+
[](https://github.com/astral-sh/ruff)
|
|
38
|
+
[](https://github.com/astral-sh/uv)
|
|
39
|
+
[](https://pypi.org/project/diffcone/)
|
|
34
40
|
|
|
35
41
|
**Run the tests your change can affect, and know why each one was picked.**
|
|
36
42
|
|
|
@@ -49,23 +55,30 @@ changed symbols (1):
|
|
|
49
55
|
selected targets (2):
|
|
50
56
|
pytest: tests/test_calc.py::test_mul
|
|
51
57
|
- dependency: calc.ops.mul body_changed
|
|
58
|
+
target:pytest:tests/test_calc.py::test_mul -[entry]-> tests.test_calc.test_mul -[references]-> calc.ops.mul
|
|
52
59
|
pytest: tests/test_calc.py::test_square
|
|
53
60
|
- dependency: calc.ops.mul body_changed
|
|
61
|
+
target:pytest:tests/test_calc.py::test_square -[entry]-> tests.test_calc.test_square -[references]-> calc.ops.square -[references]-> calc.ops.mul
|
|
54
62
|
|
|
55
63
|
unselected targets (1):
|
|
56
64
|
pytest: tests/test_calc.py::test_add
|
|
65
|
+
...
|
|
57
66
|
```
|
|
58
67
|
|
|
59
68
|
- **Every selection is explained:** the report shows the chain of calls and
|
|
60
69
|
references from each test to the change.
|
|
61
70
|
- **It errs on the side of running more:** when diffcone can't tell what a
|
|
62
71
|
change reaches, it selects more tests and says why.
|
|
63
|
-
- **It never runs your code to plan:** planning reads files and git history
|
|
64
|
-
only.
|
|
65
72
|
- **pytest and ASV:** tests and benchmarks are found from your
|
|
66
73
|
configuration and source, the way each runner collects them.
|
|
67
|
-
- **
|
|
68
|
-
|
|
74
|
+
- **Two ways to plan:**
|
|
75
|
+
- **From the code (the default).** diffcone reads your source and git
|
|
76
|
+
history. It never imports your code or runs your tests.
|
|
77
|
+
- **From execution evidence (opt-in, Python 3.12+).** For large codebases
|
|
78
|
+
where nearly everything imports everything. You run your test suite
|
|
79
|
+
once under diffcone's recorder, which notes what each test ran; plans
|
|
80
|
+
then select from that recording. Recording runs your tests; planning
|
|
81
|
+
from a recording only reads it.
|
|
69
82
|
|
|
70
83
|
## Install
|
|
71
84
|
|
|
@@ -84,7 +97,7 @@ diffcone plan --base main --head WORKTREE --discover pytest --format text
|
|
|
84
97
|
# Run only those tests (arguments after -- go to pytest)
|
|
85
98
|
diffcone run --base main --head WORKTREE --discover pytest --command "uv run pytest" -- -x
|
|
86
99
|
|
|
87
|
-
#
|
|
100
|
+
# Run the suite once under the recorder, then plan from the recording (Python 3.12+)
|
|
88
101
|
diffcone collect --command "uv run pytest" -- -n 8
|
|
89
102
|
diffcone plan --base main --head HEAD --discover pytest --evidence auto -o plan.json
|
|
90
103
|
|
|
@@ -112,7 +125,7 @@ Read the documentation at
|
|
|
112
125
|
## Status
|
|
113
126
|
|
|
114
127
|
diffcone is alpha software. Its selections have been checked against the
|
|
115
|
-
full test suites of
|
|
128
|
+
full test suites of more than 40 open-source projects. See the
|
|
116
129
|
[changelog](https://github.com/bearing-research/diffcone/blob/main/CHANGELOG.md)
|
|
117
130
|
for what each release contains.
|
|
118
131
|
|
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/bearing-research/diffcone/actions/workflows/ci.yml)
|
|
4
4
|
[](https://bearing-research.github.io/diffcone/)
|
|
5
|
+
[](https://pypi.org/project/diffcone/)
|
|
6
|
+
[](https://pypi.org/project/diffcone/)
|
|
7
|
+
[](https://github.com/bearing-research/diffcone/blob/main/LICENSE)
|
|
8
|
+
[](https://github.com/astral-sh/ruff)
|
|
9
|
+
[](https://github.com/astral-sh/uv)
|
|
10
|
+
[](https://pypi.org/project/diffcone/)
|
|
5
11
|
|
|
6
12
|
**Run the tests your change can affect, and know why each one was picked.**
|
|
7
13
|
|
|
@@ -20,23 +26,30 @@ changed symbols (1):
|
|
|
20
26
|
selected targets (2):
|
|
21
27
|
pytest: tests/test_calc.py::test_mul
|
|
22
28
|
- dependency: calc.ops.mul body_changed
|
|
29
|
+
target:pytest:tests/test_calc.py::test_mul -[entry]-> tests.test_calc.test_mul -[references]-> calc.ops.mul
|
|
23
30
|
pytest: tests/test_calc.py::test_square
|
|
24
31
|
- dependency: calc.ops.mul body_changed
|
|
32
|
+
target:pytest:tests/test_calc.py::test_square -[entry]-> tests.test_calc.test_square -[references]-> calc.ops.square -[references]-> calc.ops.mul
|
|
25
33
|
|
|
26
34
|
unselected targets (1):
|
|
27
35
|
pytest: tests/test_calc.py::test_add
|
|
36
|
+
...
|
|
28
37
|
```
|
|
29
38
|
|
|
30
39
|
- **Every selection is explained:** the report shows the chain of calls and
|
|
31
40
|
references from each test to the change.
|
|
32
41
|
- **It errs on the side of running more:** when diffcone can't tell what a
|
|
33
42
|
change reaches, it selects more tests and says why.
|
|
34
|
-
- **It never runs your code to plan:** planning reads files and git history
|
|
35
|
-
only.
|
|
36
43
|
- **pytest and ASV:** tests and benchmarks are found from your
|
|
37
44
|
configuration and source, the way each runner collects them.
|
|
38
|
-
- **
|
|
39
|
-
|
|
45
|
+
- **Two ways to plan:**
|
|
46
|
+
- **From the code (the default).** diffcone reads your source and git
|
|
47
|
+
history. It never imports your code or runs your tests.
|
|
48
|
+
- **From execution evidence (opt-in, Python 3.12+).** For large codebases
|
|
49
|
+
where nearly everything imports everything. You run your test suite
|
|
50
|
+
once under diffcone's recorder, which notes what each test ran; plans
|
|
51
|
+
then select from that recording. Recording runs your tests; planning
|
|
52
|
+
from a recording only reads it.
|
|
40
53
|
|
|
41
54
|
## Install
|
|
42
55
|
|
|
@@ -55,7 +68,7 @@ diffcone plan --base main --head WORKTREE --discover pytest --format text
|
|
|
55
68
|
# Run only those tests (arguments after -- go to pytest)
|
|
56
69
|
diffcone run --base main --head WORKTREE --discover pytest --command "uv run pytest" -- -x
|
|
57
70
|
|
|
58
|
-
#
|
|
71
|
+
# Run the suite once under the recorder, then plan from the recording (Python 3.12+)
|
|
59
72
|
diffcone collect --command "uv run pytest" -- -n 8
|
|
60
73
|
diffcone plan --base main --head HEAD --discover pytest --evidence auto -o plan.json
|
|
61
74
|
|
|
@@ -83,7 +96,7 @@ Read the documentation at
|
|
|
83
96
|
## Status
|
|
84
97
|
|
|
85
98
|
diffcone is alpha software. Its selections have been checked against the
|
|
86
|
-
full test suites of
|
|
99
|
+
full test suites of more than 40 open-source projects. See the
|
|
87
100
|
[changelog](https://github.com/bearing-research/diffcone/blob/main/CHANGELOG.md)
|
|
88
101
|
for what each release contains.
|
|
89
102
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "diffcone"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.5.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"
|
|
@@ -53,6 +53,7 @@ dev = [
|
|
|
53
53
|
"cython>=3.1",
|
|
54
54
|
"pytest>=8",
|
|
55
55
|
"pytest-cov>=5",
|
|
56
|
+
"pytest-xdist>=3.6",
|
|
56
57
|
"ruff>=0.5",
|
|
57
58
|
"setuptools",
|
|
58
59
|
"ty==0.0.84",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "diffcone"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.5.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"
|
|
@@ -44,6 +44,7 @@ dev = [
|
|
|
44
44
|
"cython>=3.1", # tests that build a profiled extension (evidence over Cython)
|
|
45
45
|
"pytest>=8",
|
|
46
46
|
"pytest-cov>=5",
|
|
47
|
+
"pytest-xdist>=3.6",
|
|
47
48
|
"ruff>=0.5",
|
|
48
49
|
"setuptools", # builds those extensions
|
|
49
50
|
"ty==0.0.84", # pre-1.0: pinned, since new releases add checks
|
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
"""
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
"""The cache under ``<repo>/.diffcone/cache`` (``cache_dir``; diffcone
|
|
2
|
+
gives ``.diffcone/`` a ``.gitignore`` of its own). It is an optimisation
|
|
3
|
+
only: a hit must produce a byte-identical plan to a miss.
|
|
4
|
+
|
|
5
|
+
- ``index/<key>.json`` (:class:`IndexCache`): a committed snapshot's whole
|
|
6
|
+
:class:`SourceIndex`, a pure function of the commit, the source roots and
|
|
7
|
+
the indexer version. The working tree and the git index are never cached
|
|
8
|
+
whole (their content is not identified by a commit), and neither is an
|
|
9
|
+
index whose analysis ran out of stack (``TOO_DEEP``).
|
|
10
|
+
- ``discovery/<key>.json`` (:class:`DiscoveryCache`): static discovery
|
|
11
|
+
results per committed snapshot, runner and options; not one that left a
|
|
12
|
+
module out as too deeply nested to walk (``TOO_DEEP``), for the same
|
|
13
|
+
reason.
|
|
14
|
+
- ``modules.sqlite`` (:class:`ModuleCache`): per-module results for every
|
|
15
|
+
snapshot kind, the working tree included: a module's first-pass facts are
|
|
16
|
+
a pure function of its file, and its second-pass resolution a pure
|
|
17
|
+
function of the file plus a fingerprint of what other modules expose (see
|
|
18
|
+
``Indexer.build``). A warm working-tree plan after a one-line edit then
|
|
19
|
+
re-parses and re-resolves only the edited module.
|
|
20
|
+
|
|
21
|
+
:func:`prune` (``diffcone prune``) keeps only what planning at given commits
|
|
22
|
+
reads.
|
|
18
23
|
"""
|
|
19
24
|
|
|
20
25
|
from __future__ import annotations
|
|
@@ -23,7 +28,6 @@ import hashlib
|
|
|
23
28
|
import json
|
|
24
29
|
import os
|
|
25
30
|
import re
|
|
26
|
-
import shutil
|
|
27
31
|
import sqlite3
|
|
28
32
|
import sys
|
|
29
33
|
import tempfile
|
|
@@ -33,19 +37,90 @@ from typing import Any
|
|
|
33
37
|
|
|
34
38
|
from diffcone.cython import CythonFunction, CythonModule, CythonStatement
|
|
35
39
|
from diffcone.discovery import DiscoveryNote, DiscoveryOptions, DiscoveryResult
|
|
40
|
+
from diffcone.indexer.facts import symbol_from_dict
|
|
41
|
+
from diffcone.indexer.syntax import TOO_DEEP
|
|
36
42
|
from diffcone.manifest import Target
|
|
37
43
|
from diffcone.model import (
|
|
38
44
|
AnalysisError,
|
|
39
45
|
Edge,
|
|
46
|
+
EdgeKind,
|
|
40
47
|
ExternalReference,
|
|
41
48
|
SnapshotInfo,
|
|
49
|
+
SnapshotKind,
|
|
42
50
|
SourceIndex,
|
|
43
|
-
|
|
51
|
+
UnresolvedKind,
|
|
44
52
|
UnresolvedReference,
|
|
45
53
|
)
|
|
46
54
|
|
|
47
55
|
# Bump whenever the indexer's output for the same input can change.
|
|
48
|
-
|
|
56
|
+
# 62: a class reached by another name is written through it, one record of
|
|
57
|
+
# what each class is given (writes.ClassRecord), shared objects bound in
|
|
58
|
+
# methods, nested classes' state, library methods on a class and
|
|
59
|
+
# ``type()`` of three arguments (audit round 7, U2, U3, U11, U12);
|
|
60
|
+
# 63: SourceIndex.decorator_symbols goes through the whole-index cache
|
|
61
|
+
# (audit round 7, U27); the state rules of round 7's state batch;
|
|
62
|
+
# 64: typed_calls and shared_instances; receiver attribute stores keep
|
|
63
|
+
# their name (``@self.x``), re-initialisation is ``@init``; memoisers
|
|
64
|
+
# applied by a call (audit round 7, U4, U5, U14, U15, U16, U17, U18);
|
|
65
|
+
# 59: a class attribute bound once to a value that cannot change in place
|
|
66
|
+
# is no root of its class (audit round 6, T24); an instance holds the
|
|
67
|
+
# arguments its constructor was handed, and only a write that may reach
|
|
68
|
+
# them writes them (T23);
|
|
69
|
+
# 58: an instance an in-scope class makes (``Store()``, ``cls.__new__(cls)``)
|
|
70
|
+
# is no root of the class; a write in place into it writes the class
|
|
71
|
+
# when the class holds state, and ``__new__``/``__init_subclass__`` take
|
|
72
|
+
# the class (audit round 6, T22);
|
|
73
|
+
# 57: a write in place into a module variable holding an instance of an
|
|
74
|
+
# in-scope class with class-level state writes the class and its
|
|
75
|
+
# in-scope bases too (audit round 6, T21);
|
|
76
|
+
# 56: SourceIndex.stores without what the value derives from, through
|
|
77
|
+
# ``__dict__``/``vars()`` and explicit re-initialisation (audit T19);
|
|
78
|
+
# 55: no mutated_by edge from a module variable whose one binding is an
|
|
79
|
+
# immutable value nothing binds anew (audit round 6, T20);
|
|
80
|
+
# 54: writes to state held on a class, and through another name for a module
|
|
81
|
+
# variable (a local alias, a getter's result, globals()), give mutated_by
|
|
82
|
+
# edges (audit round 6, T6 and T7);
|
|
83
|
+
# 53: imports and runs of files [index] exclude keeps out are unknown
|
|
84
|
+
# dependencies; pytest.importorskip, find_spec, pkgutil imports (T2, T9);
|
|
85
|
+
# 52: SourceIndex.write_values, call_values removed again (audit T1);
|
|
86
|
+
# 51: SourceIndex.write_values, call_values (what in-place writes store and calls
|
|
87
|
+
# hand on; E32, E35, E36);
|
|
88
|
+
# 50: SnapshotInfo.excluded (diffcone.toml [index] exclude; E29);
|
|
89
|
+
# 49: SourceIndex.lazy_constants (indexer/lazy.py; roadmap item 19, rule 2);
|
|
90
|
+
# 48: Symbol.annotation_names (what a function's annotations can read; E7);
|
|
91
|
+
# 47: a name bound to modules reads off them (indexer/aliases.py), and a
|
|
92
|
+
# module followed through a name is one a value of unknown type may be;
|
|
93
|
+
# 46: batch B of round 5 (text run as code, test runs, handed instances,
|
|
94
|
+
# match_args); 45: batches A, C and D of round 5 merged (each had numbered its index 44):
|
|
95
|
+
# SourceIndex.file_modes (git modes of the entries under the roots), the
|
|
96
|
+
# evidence stores/memoized/decorations facts;
|
|
97
|
+
# 44: Symbol.statement_layout (the order of a module's or class's statements,
|
|
98
|
+
# audit round 5 R6), Symbol.reads_any_docstring (R7), classes with Enum-family
|
|
99
|
+
# bases or in-scope metaclasses depend on their ``__init__``/``__new__`` (R20),
|
|
100
|
+
# stores through a wider-scoped fixture's ``monkeypatch`` are not undone (R27);
|
|
101
|
+
# 43: Symbol.fixture_scope (the isolation assumption: planner.isolated_test_code);
|
|
102
|
+
# 42: writes only (not handing on) give use-scan ``mutated_by`` edges, modules
|
|
103
|
+
# handed to written parameters, stores put back before the test ends, lookups
|
|
104
|
+
# on the whole chain; 44: stores, memoized, decorations (audit round 5, R22);
|
|
105
|
+
# 41: ``mutated_by`` edges from the use scan (Indexer._mutations), star-imported
|
|
106
|
+
# names in the use scan, UseRecord.direct;
|
|
107
|
+
# 40: no escaped_values; decorated symbols (``decorated`` edges, passive decorators), the known
|
|
108
|
+
# callers of a parameter, deeply nested modules as analysis errors;
|
|
109
|
+
# 39: stores undone after the test (indexer/patches.py: SCOPED, SWAP,
|
|
110
|
+
# external writes, restored process state); 38: attribute_modules,
|
|
111
|
+
# any_module_readers, module_writers, module-attribute references,
|
|
112
|
+
# unpicklers and file loaders, installs under unbounded names;
|
|
113
|
+
# 37: module_reach, sys.modules installs, scoped names in the use scan;
|
|
114
|
+
# 36: process writes, `writes`/`rebinds` edges, builtin containers,
|
|
115
|
+
# main-guarded code; 35: third-party values of project factories (external_returns); 34:
|
|
116
|
+
# writes through parameters and receivers, scripts named in strings;
|
|
117
|
+
# 33: bounded run-time module names, table_imports, graph handles, escaped
|
|
118
|
+
# modules; 32: namespace reads off any object; 31: class-object reads,
|
|
119
|
+
# literal tables of shadowing scopes; 30: quiet_header; 29: uses of tables
|
|
120
|
+
# and modules (indexer.uses); 28: __subclasses__ reads; 27: type
|
|
121
|
+
# parameters, unnameable build scripts as other files; 26: escaped values;
|
|
122
|
+
# 25: external sites; 24: docstring decorators; 23: open classes
|
|
123
|
+
INDEX_FORMAT = 64
|
|
49
124
|
|
|
50
125
|
|
|
51
126
|
def _indexer_fingerprint() -> str:
|
|
@@ -83,6 +158,25 @@ def make_own_dir(directory: Path) -> None:
|
|
|
83
158
|
break
|
|
84
159
|
|
|
85
160
|
|
|
161
|
+
def _write_json_atomic(path: Path, data: Any) -> None:
|
|
162
|
+
"""Write ``data`` as JSON to ``path`` through a temporary file in the
|
|
163
|
+
same directory, so a concurrent reader never sees a partial file. A
|
|
164
|
+
cache write that fails is never an error: the temporary file goes."""
|
|
165
|
+
tmp: str | None = None
|
|
166
|
+
try:
|
|
167
|
+
make_own_dir(path.parent)
|
|
168
|
+
fd, tmp = tempfile.mkstemp(dir=path.parent, suffix=".tmp")
|
|
169
|
+
with os.fdopen(fd, "w", encoding="utf-8") as f:
|
|
170
|
+
json.dump(data, f)
|
|
171
|
+
os.replace(tmp, path)
|
|
172
|
+
except (OSError, TypeError, ValueError):
|
|
173
|
+
if tmp is not None:
|
|
174
|
+
try:
|
|
175
|
+
os.unlink(tmp)
|
|
176
|
+
except OSError:
|
|
177
|
+
pass
|
|
178
|
+
|
|
179
|
+
|
|
86
180
|
def default_cache_dir(repo: Path) -> Path:
|
|
87
181
|
return repo / ".diffcone" / "cache"
|
|
88
182
|
|
|
@@ -99,19 +193,41 @@ def index_to_dict(index: SourceIndex) -> dict:
|
|
|
99
193
|
"modules": sorted(index.modules),
|
|
100
194
|
"failed_modules": sorted(index.failed_modules),
|
|
101
195
|
"escaped_classes": sorted(index.escaped_classes),
|
|
196
|
+
"escaped_modules": sorted(index.escaped_modules),
|
|
197
|
+
"module_reach": {m: list(r) for m, r in sorted(index.module_reach.items())},
|
|
198
|
+
"attribute_modules": sorted(index.attribute_modules),
|
|
199
|
+
"any_module_readers": sorted(index.any_module_readers),
|
|
200
|
+
"module_writers": {m: list(w) for m, w in sorted(index.module_writers.items())},
|
|
102
201
|
"other_files": dict(sorted(index.other_files.items())),
|
|
202
|
+
"file_modes": dict(sorted(index.file_modes.items())),
|
|
103
203
|
"symbols": [asdict(s) for _, s in sorted(index.symbols.items())],
|
|
104
204
|
"edges": [asdict(e) for e in sorted(index.edges)],
|
|
105
205
|
"unresolved": [asdict(u) for u in sorted(index.unresolved)],
|
|
106
206
|
"external": [asdict(x) for x in sorted(index.external)],
|
|
107
207
|
"errors": [asdict(e) for e in sorted(index.errors)],
|
|
108
208
|
"reflection": sorted(list(r) for r in index.reflection),
|
|
209
|
+
"external_sites": [[s, d, list(w)] for (s, d), w in sorted(index.external_sites.items())],
|
|
210
|
+
"table_imports": [
|
|
211
|
+
[s, d, list(c), list(w)] for (s, d), (c, w) in sorted(index.table_imports.items())
|
|
212
|
+
],
|
|
109
213
|
"class_attributes": {
|
|
110
214
|
c: dict(sorted(a.items())) for c, a in sorted(index.class_attributes.items())
|
|
111
215
|
},
|
|
112
216
|
"class_bases": {c: list(b) for c, b in sorted(index.class_bases.items())},
|
|
113
217
|
"open_classes": sorted(index.open_classes),
|
|
114
218
|
"doc_decorated": sorted(index.doc_decorated),
|
|
219
|
+
"decorator_symbols": sorted(index.decorator_symbols),
|
|
220
|
+
"scripts": dict(sorted(index.scripts.items())),
|
|
221
|
+
"script_refs": sorted(list(r) for r in index.script_refs),
|
|
222
|
+
"process_writes": sorted(list(w) for w in index.process_writes),
|
|
223
|
+
"main_guarded": sorted(list(m) for m in index.main_guarded),
|
|
224
|
+
"stores": sorted(list(s) for s in index.stores),
|
|
225
|
+
"handed": sorted(list(h) for h in index.handed),
|
|
226
|
+
"memoized": sorted(index.memoized),
|
|
227
|
+
"decorations": sorted(list(d) for d in index.decorations),
|
|
228
|
+
"typed_calls": sorted(list(t) for t in index.typed_calls),
|
|
229
|
+
"shared_instances": sorted(index.shared_instances),
|
|
230
|
+
"lazy_constants": dict(sorted(index.lazy_constants.items())),
|
|
115
231
|
"cython": {
|
|
116
232
|
path: {
|
|
117
233
|
"functions": [{**asdict(f), "names": sorted(f.names)} for f in module.functions],
|
|
@@ -128,30 +244,54 @@ def index_to_dict(index: SourceIndex) -> dict:
|
|
|
128
244
|
def index_from_dict(data: dict) -> SourceIndex:
|
|
129
245
|
if data.get("format") != INDEX_FORMAT:
|
|
130
246
|
raise ValueError("unsupported index format")
|
|
131
|
-
symbols = {}
|
|
132
|
-
for s in data["symbols"]:
|
|
133
|
-
s = dict(s)
|
|
134
|
-
s["line_ranges"] = tuple(tuple(r) for r in s["line_ranges"])
|
|
135
|
-
s["imports"] = tuple(s["imports"])
|
|
136
|
-
s["import_layout"] = tuple(s["import_layout"])
|
|
137
|
-
symbol = Symbol(**s)
|
|
138
|
-
symbols[symbol.id] = symbol
|
|
247
|
+
symbols = {s.id: s for s in map(symbol_from_dict, data["symbols"])}
|
|
139
248
|
return SourceIndex(
|
|
140
|
-
snapshot=SnapshotInfo(
|
|
249
|
+
snapshot=SnapshotInfo(
|
|
250
|
+
**data["snapshot"]
|
|
251
|
+
| {
|
|
252
|
+
"kind": SnapshotKind(data["snapshot"]["kind"]),
|
|
253
|
+
"excluded": tuple(data["snapshot"]["excluded"]),
|
|
254
|
+
}
|
|
255
|
+
),
|
|
141
256
|
modules=set(data["modules"]),
|
|
142
257
|
symbols=symbols,
|
|
143
|
-
edges={
|
|
144
|
-
|
|
258
|
+
edges={
|
|
259
|
+
Edge(e["source"], e["target"], EdgeKind(e["kind"]), e["detail"]) for e in data["edges"]
|
|
260
|
+
},
|
|
261
|
+
unresolved={
|
|
262
|
+
UnresolvedReference(u["symbol"], UnresolvedKind(u["kind"]), u["name"], u["detail"])
|
|
263
|
+
for u in data["unresolved"]
|
|
264
|
+
},
|
|
145
265
|
external={ExternalReference(**x) for x in data["external"]},
|
|
146
266
|
errors=[AnalysisError(**e) for e in data["errors"]],
|
|
147
267
|
failed_modules=set(data["failed_modules"]),
|
|
148
268
|
escaped_classes=set(data["escaped_classes"]),
|
|
269
|
+
escaped_modules=set(data["escaped_modules"]),
|
|
270
|
+
module_reach={m: tuple(r) for m, r in data["module_reach"].items()},
|
|
271
|
+
attribute_modules=set(data["attribute_modules"]),
|
|
272
|
+
any_module_readers=set(data["any_module_readers"]),
|
|
273
|
+
module_writers={m: tuple(w) for m, w in data["module_writers"].items()},
|
|
149
274
|
other_files=dict(data["other_files"]),
|
|
275
|
+
file_modes=dict(data["file_modes"]),
|
|
150
276
|
reflection={(s, d) for s, d in data["reflection"]},
|
|
277
|
+
external_sites={(s, d): tuple(w) for s, d, w in data["external_sites"]},
|
|
278
|
+
table_imports={(s, d): (tuple(c), tuple(w)) for s, d, c, w in data["table_imports"]},
|
|
151
279
|
class_attributes={c: dict(a) for c, a in data["class_attributes"].items()},
|
|
152
280
|
class_bases={c: tuple(b) for c, b in data["class_bases"].items()},
|
|
153
281
|
open_classes=set(data["open_classes"]),
|
|
154
282
|
doc_decorated=set(data["doc_decorated"]),
|
|
283
|
+
decorator_symbols=set(data["decorator_symbols"]),
|
|
284
|
+
scripts=dict(data["scripts"]),
|
|
285
|
+
script_refs={(s, p) for s, p in data["script_refs"]},
|
|
286
|
+
process_writes={(s, w) for s, w in data["process_writes"]},
|
|
287
|
+
main_guarded={(a, b, c) for a, b, c in data["main_guarded"]},
|
|
288
|
+
stores={(a, b) for a, b in data["stores"]},
|
|
289
|
+
handed={(a, b, c) for a, b, c in data["handed"]},
|
|
290
|
+
memoized=set(data["memoized"]),
|
|
291
|
+
decorations={(a, b) for a, b in data["decorations"]},
|
|
292
|
+
typed_calls={(a, b) for a, b in data["typed_calls"]},
|
|
293
|
+
shared_instances=set(data["shared_instances"]),
|
|
294
|
+
lazy_constants=dict(data["lazy_constants"]),
|
|
155
295
|
cython={
|
|
156
296
|
path: CythonModule(
|
|
157
297
|
path,
|
|
@@ -201,7 +341,11 @@ class ModuleCache:
|
|
|
201
341
|
the file read-only and work on a directory that cannot be written."""
|
|
202
342
|
|
|
203
343
|
def __init__(self, directory: Path) -> None:
|
|
204
|
-
|
|
344
|
+
# Absolute, so that the read-only URI below can be formed: a relative
|
|
345
|
+
# directory (the default ``--repo .``) once made every read a miss
|
|
346
|
+
# (audit round 7, U24).
|
|
347
|
+
self.path = (directory / "modules.sqlite").absolute()
|
|
348
|
+
# Hit and miss counters: test instrumentation, nothing reads them else.
|
|
205
349
|
self.facts_hits = 0
|
|
206
350
|
self.facts_misses = 0
|
|
207
351
|
self.resolved_hits = 0
|
|
@@ -307,7 +451,8 @@ class ModuleCache:
|
|
|
307
451
|
conn.close()
|
|
308
452
|
|
|
309
453
|
|
|
310
|
-
|
|
454
|
+
# 2: lifecycle dependencies every target lists are written once (audit E37)
|
|
455
|
+
DISCOVERY_FORMAT = 2
|
|
311
456
|
|
|
312
457
|
|
|
313
458
|
def _discovery_fingerprint() -> str:
|
|
@@ -324,6 +469,27 @@ def _discovery_fingerprint() -> str:
|
|
|
324
469
|
DISCOVERY_FINGERPRINT = _discovery_fingerprint()
|
|
325
470
|
|
|
326
471
|
|
|
472
|
+
def _sorted_unique(deps: tuple[str, ...]) -> bool:
|
|
473
|
+
return all(a < b for a, b in zip(deps, deps[1:], strict=False))
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
def _shared_lifecycle(targets: list[Target]) -> frozenset[str]:
|
|
477
|
+
"""The lifecycle dependencies every target lists, where each lists them
|
|
478
|
+
sorted and once (as discovery does), so a target's own rest rebuilds it."""
|
|
479
|
+
sets = [frozenset(t.lifecycle_dependencies) for t in targets]
|
|
480
|
+
if not sets or not all(_sorted_unique(t.lifecycle_dependencies) for t in targets):
|
|
481
|
+
return frozenset()
|
|
482
|
+
return frozenset.intersection(*sets)
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
def _target_entry(target: Target, shared: frozenset[str]) -> dict[str, Any]:
|
|
486
|
+
entry = asdict(target)
|
|
487
|
+
if shared:
|
|
488
|
+
del entry["lifecycle_dependencies"]
|
|
489
|
+
entry["own"] = [d for d in target.lifecycle_dependencies if d not in shared]
|
|
490
|
+
return entry
|
|
491
|
+
|
|
492
|
+
|
|
327
493
|
class DiscoveryCache:
|
|
328
494
|
"""Static discovery results per committed snapshot. Discovery reads only
|
|
329
495
|
the snapshot and its index, so a commit, source roots, runner and
|
|
@@ -351,6 +517,8 @@ class DiscoveryCache:
|
|
|
351
517
|
data = json.loads(self._path(commit, roots, runner, options).read_text("utf-8"))
|
|
352
518
|
if data.get("format") != DISCOVERY_FORMAT or data.get("commit") != commit:
|
|
353
519
|
return None
|
|
520
|
+
shared = data["shared"]
|
|
521
|
+
pool: dict[str, str] = {d: d for d in shared}
|
|
354
522
|
return DiscoveryResult(
|
|
355
523
|
runner=data["runner"],
|
|
356
524
|
targets=[
|
|
@@ -358,7 +526,9 @@ class DiscoveryCache:
|
|
|
358
526
|
t["runner"],
|
|
359
527
|
t["runner_id"],
|
|
360
528
|
t["entry_symbol"],
|
|
361
|
-
tuple(t["
|
|
529
|
+
tuple(sorted([*shared, *(pool.setdefault(d, d) for d in t["own"])]))
|
|
530
|
+
if "own" in t
|
|
531
|
+
else tuple(t["lifecycle_dependencies"]),
|
|
362
532
|
)
|
|
363
533
|
for t in data["targets"]
|
|
364
534
|
],
|
|
@@ -375,35 +545,33 @@ class DiscoveryCache:
|
|
|
375
545
|
roots: list[str],
|
|
376
546
|
options: DiscoveryOptions,
|
|
377
547
|
) -> None:
|
|
548
|
+
if any(TOO_DEEP in n.detail for n in result.notes):
|
|
549
|
+
return # depends on the caller's stack depth, not only on the commit
|
|
378
550
|
path = self._path(commit, roots, result.runner, options)
|
|
551
|
+
shared = _shared_lifecycle(result.targets)
|
|
379
552
|
data = {
|
|
380
553
|
"format": DISCOVERY_FORMAT,
|
|
381
554
|
"commit": commit,
|
|
382
555
|
"fingerprint": DISCOVERY_FINGERPRINT,
|
|
383
556
|
"runner": result.runner,
|
|
384
|
-
|
|
557
|
+
# What every target depends on, written once (audit E37: pandas'
|
|
558
|
+
# 25 620 targets each carry the same 654, a 680 MB file that took
|
|
559
|
+
# 1.4 GB to load); a target lists the rest (``own``).
|
|
560
|
+
"shared": sorted(shared),
|
|
561
|
+
"targets": [_target_entry(t, shared) for t in result.targets],
|
|
385
562
|
"notes": [asdict(n) for n in result.notes],
|
|
386
563
|
"config": result.config,
|
|
387
564
|
}
|
|
388
|
-
|
|
389
|
-
make_own_dir(path.parent)
|
|
390
|
-
fd, tmp = tempfile.mkstemp(dir=path.parent, suffix=".tmp")
|
|
391
|
-
with os.fdopen(fd, "w", encoding="utf-8") as f:
|
|
392
|
-
json.dump(data, f)
|
|
393
|
-
os.replace(tmp, path)
|
|
394
|
-
except (OSError, TypeError, ValueError):
|
|
395
|
-
pass # a cache write failure is never an error
|
|
565
|
+
_write_json_atomic(path, data)
|
|
396
566
|
|
|
397
567
|
|
|
398
568
|
class IndexCache:
|
|
399
569
|
def __init__(self, directory: Path) -> None:
|
|
400
570
|
self.directory = directory
|
|
401
|
-
self.hits = 0
|
|
571
|
+
self.hits = 0 # hit and miss counters: test instrumentation
|
|
402
572
|
self.misses = 0
|
|
403
573
|
self.modules = ModuleCache(directory)
|
|
404
574
|
self.discovery = DiscoveryCache(directory)
|
|
405
|
-
# The per-file hash cache this replaced left ``hashes/`` behind.
|
|
406
|
-
shutil.rmtree(directory / "hashes", ignore_errors=True)
|
|
407
575
|
|
|
408
576
|
def _path(self, commit: str, source_roots: list[str]) -> Path:
|
|
409
577
|
return self.directory / "index" / f"{index_key(commit, source_roots)}.json"
|
|
@@ -423,16 +591,9 @@ class IndexCache:
|
|
|
423
591
|
return index
|
|
424
592
|
|
|
425
593
|
def store(self, index: SourceIndex, source_roots: list[str]) -> None:
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
# Write atomically so a concurrent reader never sees a partial file.
|
|
430
|
-
fd, tmp = tempfile.mkstemp(dir=path.parent, suffix=".tmp")
|
|
431
|
-
with os.fdopen(fd, "w", encoding="utf-8") as f:
|
|
432
|
-
json.dump(index_to_dict(index), f)
|
|
433
|
-
os.replace(tmp, path)
|
|
434
|
-
except OSError:
|
|
435
|
-
pass # a cache write failure is never an error
|
|
594
|
+
if any(e.message.startswith(TOO_DEEP) for e in index.errors):
|
|
595
|
+
return # depends on the caller's stack depth, not only on the commit
|
|
596
|
+
_write_json_atomic(self._path(index.snapshot.commit, source_roots), index_to_dict(index))
|
|
436
597
|
|
|
437
598
|
|
|
438
599
|
# --------------------------------------------------------------------------- pruning
|