diffcone 0.2.0__tar.gz → 0.4.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.2.0 → diffcone-0.4.0}/PKG-INFO +20 -7
- {diffcone-0.2.0 → diffcone-0.4.0}/README.md +19 -6
- {diffcone-0.2.0 → diffcone-0.4.0}/pyproject.toml +1 -1
- {diffcone-0.2.0 → diffcone-0.4.0}/pyproject.toml.orig +1 -1
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/cache.py +136 -52
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/check.py +153 -37
- diffcone-0.4.0/src/diffcone/child.py +1509 -0
- diffcone-0.4.0/src/diffcone/ci_report.py +528 -0
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/classify.py +144 -56
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/cli.py +312 -46
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/collect.py +716 -165
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/cython.py +47 -31
- diffcone-0.4.0/src/diffcone/declarations.py +178 -0
- diffcone-0.4.0/src/diffcone/discovery/__init__.py +232 -0
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/discovery/asv_static.py +217 -111
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/discovery/common.py +64 -8
- diffcone-0.4.0/src/diffcone/discovery/pytest_static.py +4160 -0
- diffcone-0.4.0/src/diffcone/discovery/session_state.py +205 -0
- diffcone-0.4.0/src/diffcone/evidence.py +1211 -0
- diffcone-0.4.0/src/diffcone/evidence_plan.py +3282 -0
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/execution.py +760 -221
- diffcone-0.4.0/src/diffcone/indexer/__init__.py +99 -0
- diffcone-0.4.0/src/diffcone/indexer/aliases.py +176 -0
- diffcone-0.4.0/src/diffcone/indexer/core.py +1231 -0
- diffcone-0.4.0/src/diffcone/indexer/definitions.py +1067 -0
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/indexer/dynamics.py +234 -114
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/indexer/facts.py +196 -58
- diffcone-0.4.0/src/diffcone/indexer/lazy.py +617 -0
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/indexer/literals.py +161 -72
- diffcone-0.4.0/src/diffcone/indexer/patches.py +475 -0
- diffcone-0.4.0/src/diffcone/indexer/process.py +200 -0
- diffcone-0.4.0/src/diffcone/indexer/references.py +2542 -0
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/indexer/resolver.py +653 -106
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/indexer/scopes.py +118 -22
- diffcone-0.4.0/src/diffcone/indexer/scripts.py +1607 -0
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/indexer/state.py +32 -1
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/indexer/symbols.py +238 -59
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/indexer/syntax.py +123 -0
- diffcone-0.4.0/src/diffcone/indexer/uses.py +2215 -0
- diffcone-0.4.0/src/diffcone/indexer/writes.py +1061 -0
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/manifest.py +2 -2
- diffcone-0.4.0/src/diffcone/model.py +507 -0
- diffcone-0.4.0/src/diffcone/planner.py +2672 -0
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/report.py +55 -3
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/selection.py +84 -5
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/snapshot.py +335 -75
- {diffcone-0.2.0 → diffcone-0.4.0}/src/diffcone/testing.py +7 -2
- diffcone-0.2.0/src/diffcone/declarations.py +0 -111
- diffcone-0.2.0/src/diffcone/discovery/__init__.py +0 -121
- diffcone-0.2.0/src/diffcone/discovery/pytest_static.py +0 -2894
- diffcone-0.2.0/src/diffcone/evidence.py +0 -738
- diffcone-0.2.0/src/diffcone/evidence_plan.py +0 -1491
- diffcone-0.2.0/src/diffcone/indexer/__init__.py +0 -48
- diffcone-0.2.0/src/diffcone/indexer/core.py +0 -332
- diffcone-0.2.0/src/diffcone/indexer/definitions.py +0 -292
- diffcone-0.2.0/src/diffcone/indexer/references.py +0 -948
- diffcone-0.2.0/src/diffcone/model.py +0 -191
- diffcone-0.2.0/src/diffcone/planner.py +0 -1453
- {diffcone-0.2.0 → diffcone-0.4.0}/LICENSE +0 -0
- {diffcone-0.2.0 → diffcone-0.4.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.4.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,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,57 @@ 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
|
+
# 49: SourceIndex.lazy_constants (indexer/lazy.py; roadmap item 19, rule 2);
|
|
57
|
+
# 48: Symbol.annotation_names (what a function's annotations can read; E7);
|
|
58
|
+
# 47: a name bound to modules reads off them (indexer/aliases.py), and a
|
|
59
|
+
# module followed through a name is one a value of unknown type may be;
|
|
60
|
+
# 46: batch B of round 5 (text run as code, test runs, handed instances,
|
|
61
|
+
# match_args); 45: batches A, C and D of round 5 merged (each had numbered its index 44):
|
|
62
|
+
# SourceIndex.file_modes (git modes of the entries under the roots), the
|
|
63
|
+
# evidence stores/memoized/decorations facts;
|
|
64
|
+
# 44: Symbol.statement_layout (the order of a module's or class's statements,
|
|
65
|
+
# audit round 5 R6), Symbol.reads_any_docstring (R7), classes with Enum-family
|
|
66
|
+
# bases or in-scope metaclasses depend on their ``__init__``/``__new__`` (R20),
|
|
67
|
+
# stores through a wider-scoped fixture's ``monkeypatch`` are not undone (R27);
|
|
68
|
+
# 43: Symbol.fixture_scope (the isolation assumption: planner.isolated_test_code);
|
|
69
|
+
# 42: writes only (not handing on) give use-scan ``mutated_by`` edges, modules
|
|
70
|
+
# handed to written parameters, stores put back before the test ends, lookups
|
|
71
|
+
# on the whole chain; 44: stores, memoized, decorations (audit round 5, R22);
|
|
72
|
+
# 41: ``mutated_by`` edges from the use scan (Indexer._mutations), star-imported
|
|
73
|
+
# names in the use scan, UseRecord.direct;
|
|
74
|
+
# 40: no escaped_values; decorated symbols (``decorated`` edges, passive decorators), the known
|
|
75
|
+
# callers of a parameter, deeply nested modules as analysis errors;
|
|
76
|
+
# 39: stores undone after the test (indexer/patches.py: SCOPED, SWAP,
|
|
77
|
+
# external writes, restored process state); 38: attribute_modules,
|
|
78
|
+
# any_module_readers, module_writers, module-attribute references,
|
|
79
|
+
# unpicklers and file loaders, installs under unbounded names;
|
|
80
|
+
# 37: module_reach, sys.modules installs, scoped names in the use scan;
|
|
81
|
+
# 36: process writes, `writes`/`rebinds` edges, builtin containers,
|
|
82
|
+
# main-guarded code; 35: third-party values of project factories (external_returns); 34:
|
|
83
|
+
# writes through parameters and receivers, scripts named in strings;
|
|
84
|
+
# 33: bounded run-time module names, table_imports, graph handles, escaped
|
|
85
|
+
# modules; 32: namespace reads off any object; 31: class-object reads,
|
|
86
|
+
# literal tables of shadowing scopes; 30: quiet_header; 29: uses of tables
|
|
87
|
+
# and modules (indexer.uses); 28: __subclasses__ reads; 27: type
|
|
88
|
+
# parameters, unnameable build scripts as other files; 26: escaped values;
|
|
89
|
+
# 25: external sites; 24: docstring decorators; 23: open classes
|
|
90
|
+
INDEX_FORMAT = 49
|
|
49
91
|
|
|
50
92
|
|
|
51
93
|
def _indexer_fingerprint() -> str:
|
|
@@ -83,6 +125,25 @@ def make_own_dir(directory: Path) -> None:
|
|
|
83
125
|
break
|
|
84
126
|
|
|
85
127
|
|
|
128
|
+
def _write_json_atomic(path: Path, data: Any) -> None:
|
|
129
|
+
"""Write ``data`` as JSON to ``path`` through a temporary file in the
|
|
130
|
+
same directory, so a concurrent reader never sees a partial file. A
|
|
131
|
+
cache write that fails is never an error: the temporary file goes."""
|
|
132
|
+
tmp: str | None = None
|
|
133
|
+
try:
|
|
134
|
+
make_own_dir(path.parent)
|
|
135
|
+
fd, tmp = tempfile.mkstemp(dir=path.parent, suffix=".tmp")
|
|
136
|
+
with os.fdopen(fd, "w", encoding="utf-8") as f:
|
|
137
|
+
json.dump(data, f)
|
|
138
|
+
os.replace(tmp, path)
|
|
139
|
+
except (OSError, TypeError, ValueError):
|
|
140
|
+
if tmp is not None:
|
|
141
|
+
try:
|
|
142
|
+
os.unlink(tmp)
|
|
143
|
+
except OSError:
|
|
144
|
+
pass
|
|
145
|
+
|
|
146
|
+
|
|
86
147
|
def default_cache_dir(repo: Path) -> Path:
|
|
87
148
|
return repo / ".diffcone" / "cache"
|
|
88
149
|
|
|
@@ -99,19 +160,38 @@ def index_to_dict(index: SourceIndex) -> dict:
|
|
|
99
160
|
"modules": sorted(index.modules),
|
|
100
161
|
"failed_modules": sorted(index.failed_modules),
|
|
101
162
|
"escaped_classes": sorted(index.escaped_classes),
|
|
163
|
+
"escaped_modules": sorted(index.escaped_modules),
|
|
164
|
+
"module_reach": {m: list(r) for m, r in sorted(index.module_reach.items())},
|
|
165
|
+
"attribute_modules": sorted(index.attribute_modules),
|
|
166
|
+
"any_module_readers": sorted(index.any_module_readers),
|
|
167
|
+
"module_writers": {m: list(w) for m, w in sorted(index.module_writers.items())},
|
|
102
168
|
"other_files": dict(sorted(index.other_files.items())),
|
|
169
|
+
"file_modes": dict(sorted(index.file_modes.items())),
|
|
103
170
|
"symbols": [asdict(s) for _, s in sorted(index.symbols.items())],
|
|
104
171
|
"edges": [asdict(e) for e in sorted(index.edges)],
|
|
105
172
|
"unresolved": [asdict(u) for u in sorted(index.unresolved)],
|
|
106
173
|
"external": [asdict(x) for x in sorted(index.external)],
|
|
107
174
|
"errors": [asdict(e) for e in sorted(index.errors)],
|
|
108
175
|
"reflection": sorted(list(r) for r in index.reflection),
|
|
176
|
+
"external_sites": [[s, d, list(w)] for (s, d), w in sorted(index.external_sites.items())],
|
|
177
|
+
"table_imports": [
|
|
178
|
+
[s, d, list(c), list(w)] for (s, d), (c, w) in sorted(index.table_imports.items())
|
|
179
|
+
],
|
|
109
180
|
"class_attributes": {
|
|
110
181
|
c: dict(sorted(a.items())) for c, a in sorted(index.class_attributes.items())
|
|
111
182
|
},
|
|
112
183
|
"class_bases": {c: list(b) for c, b in sorted(index.class_bases.items())},
|
|
113
184
|
"open_classes": sorted(index.open_classes),
|
|
114
185
|
"doc_decorated": sorted(index.doc_decorated),
|
|
186
|
+
"scripts": dict(sorted(index.scripts.items())),
|
|
187
|
+
"script_refs": sorted(list(r) for r in index.script_refs),
|
|
188
|
+
"process_writes": sorted(list(w) for w in index.process_writes),
|
|
189
|
+
"main_guarded": sorted(list(m) for m in index.main_guarded),
|
|
190
|
+
"stores": sorted(list(s) for s in index.stores),
|
|
191
|
+
"handed": sorted(list(h) for h in index.handed),
|
|
192
|
+
"memoized": sorted(index.memoized),
|
|
193
|
+
"decorations": sorted(list(d) for d in index.decorations),
|
|
194
|
+
"lazy_constants": dict(sorted(index.lazy_constants.items())),
|
|
115
195
|
"cython": {
|
|
116
196
|
path: {
|
|
117
197
|
"functions": [{**asdict(f), "names": sorted(f.names)} for f in module.functions],
|
|
@@ -128,30 +208,47 @@ def index_to_dict(index: SourceIndex) -> dict:
|
|
|
128
208
|
def index_from_dict(data: dict) -> SourceIndex:
|
|
129
209
|
if data.get("format") != INDEX_FORMAT:
|
|
130
210
|
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
|
|
211
|
+
symbols = {s.id: s for s in map(symbol_from_dict, data["symbols"])}
|
|
139
212
|
return SourceIndex(
|
|
140
|
-
snapshot=SnapshotInfo(
|
|
213
|
+
snapshot=SnapshotInfo(
|
|
214
|
+
**data["snapshot"] | {"kind": SnapshotKind(data["snapshot"]["kind"])}
|
|
215
|
+
),
|
|
141
216
|
modules=set(data["modules"]),
|
|
142
217
|
symbols=symbols,
|
|
143
|
-
edges={
|
|
144
|
-
|
|
218
|
+
edges={
|
|
219
|
+
Edge(e["source"], e["target"], EdgeKind(e["kind"]), e["detail"]) for e in data["edges"]
|
|
220
|
+
},
|
|
221
|
+
unresolved={
|
|
222
|
+
UnresolvedReference(u["symbol"], UnresolvedKind(u["kind"]), u["name"], u["detail"])
|
|
223
|
+
for u in data["unresolved"]
|
|
224
|
+
},
|
|
145
225
|
external={ExternalReference(**x) for x in data["external"]},
|
|
146
226
|
errors=[AnalysisError(**e) for e in data["errors"]],
|
|
147
227
|
failed_modules=set(data["failed_modules"]),
|
|
148
228
|
escaped_classes=set(data["escaped_classes"]),
|
|
229
|
+
escaped_modules=set(data["escaped_modules"]),
|
|
230
|
+
module_reach={m: tuple(r) for m, r in data["module_reach"].items()},
|
|
231
|
+
attribute_modules=set(data["attribute_modules"]),
|
|
232
|
+
any_module_readers=set(data["any_module_readers"]),
|
|
233
|
+
module_writers={m: tuple(w) for m, w in data["module_writers"].items()},
|
|
149
234
|
other_files=dict(data["other_files"]),
|
|
235
|
+
file_modes=dict(data["file_modes"]),
|
|
150
236
|
reflection={(s, d) for s, d in data["reflection"]},
|
|
237
|
+
external_sites={(s, d): tuple(w) for s, d, w in data["external_sites"]},
|
|
238
|
+
table_imports={(s, d): (tuple(c), tuple(w)) for s, d, c, w in data["table_imports"]},
|
|
151
239
|
class_attributes={c: dict(a) for c, a in data["class_attributes"].items()},
|
|
152
240
|
class_bases={c: tuple(b) for c, b in data["class_bases"].items()},
|
|
153
241
|
open_classes=set(data["open_classes"]),
|
|
154
242
|
doc_decorated=set(data["doc_decorated"]),
|
|
243
|
+
scripts=dict(data["scripts"]),
|
|
244
|
+
script_refs={(s, p) for s, p in data["script_refs"]},
|
|
245
|
+
process_writes={(s, w) for s, w in data["process_writes"]},
|
|
246
|
+
main_guarded={(a, b, c) for a, b, c in data["main_guarded"]},
|
|
247
|
+
stores={(a, b, c) for a, b, c in data["stores"]},
|
|
248
|
+
handed={(a, b, c) for a, b, c in data["handed"]},
|
|
249
|
+
memoized=set(data["memoized"]),
|
|
250
|
+
decorations={(a, b) for a, b in data["decorations"]},
|
|
251
|
+
lazy_constants=dict(data["lazy_constants"]),
|
|
155
252
|
cython={
|
|
156
253
|
path: CythonModule(
|
|
157
254
|
path,
|
|
@@ -202,6 +299,7 @@ class ModuleCache:
|
|
|
202
299
|
|
|
203
300
|
def __init__(self, directory: Path) -> None:
|
|
204
301
|
self.path = directory / "modules.sqlite"
|
|
302
|
+
# Hit and miss counters: test instrumentation, nothing reads them else.
|
|
205
303
|
self.facts_hits = 0
|
|
206
304
|
self.facts_misses = 0
|
|
207
305
|
self.resolved_hits = 0
|
|
@@ -375,6 +473,8 @@ class DiscoveryCache:
|
|
|
375
473
|
roots: list[str],
|
|
376
474
|
options: DiscoveryOptions,
|
|
377
475
|
) -> None:
|
|
476
|
+
if any(TOO_DEEP in n.detail for n in result.notes):
|
|
477
|
+
return # depends on the caller's stack depth, not only on the commit
|
|
378
478
|
path = self._path(commit, roots, result.runner, options)
|
|
379
479
|
data = {
|
|
380
480
|
"format": DISCOVERY_FORMAT,
|
|
@@ -385,25 +485,16 @@ class DiscoveryCache:
|
|
|
385
485
|
"notes": [asdict(n) for n in result.notes],
|
|
386
486
|
"config": result.config,
|
|
387
487
|
}
|
|
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
|
|
488
|
+
_write_json_atomic(path, data)
|
|
396
489
|
|
|
397
490
|
|
|
398
491
|
class IndexCache:
|
|
399
492
|
def __init__(self, directory: Path) -> None:
|
|
400
493
|
self.directory = directory
|
|
401
|
-
self.hits = 0
|
|
494
|
+
self.hits = 0 # hit and miss counters: test instrumentation
|
|
402
495
|
self.misses = 0
|
|
403
496
|
self.modules = ModuleCache(directory)
|
|
404
497
|
self.discovery = DiscoveryCache(directory)
|
|
405
|
-
# The per-file hash cache this replaced left ``hashes/`` behind.
|
|
406
|
-
shutil.rmtree(directory / "hashes", ignore_errors=True)
|
|
407
498
|
|
|
408
499
|
def _path(self, commit: str, source_roots: list[str]) -> Path:
|
|
409
500
|
return self.directory / "index" / f"{index_key(commit, source_roots)}.json"
|
|
@@ -423,16 +514,9 @@ class IndexCache:
|
|
|
423
514
|
return index
|
|
424
515
|
|
|
425
516
|
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
|
|
517
|
+
if any(e.message.startswith(TOO_DEEP) for e in index.errors):
|
|
518
|
+
return # depends on the caller's stack depth, not only on the commit
|
|
519
|
+
_write_json_atomic(self._path(index.snapshot.commit, source_roots), index_to_dict(index))
|
|
436
520
|
|
|
437
521
|
|
|
438
522
|
# --------------------------------------------------------------------------- pruning
|