smelt-cli 0.2.0__py3-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- smelt/__init__.py +6 -0
- smelt/__main__.py +5 -0
- smelt/analysis/__init__.py +45 -0
- smelt/analysis/annotations.py +105 -0
- smelt/analysis/cache.py +168 -0
- smelt/analysis/context.py +147 -0
- smelt/analysis/contracts.py +210 -0
- smelt/analysis/coverage.py +377 -0
- smelt/analysis/definition_blocks.py +569 -0
- smelt/analysis/enum_values.py +217 -0
- smelt/analysis/errors.py +11 -0
- smelt/analysis/exports.py +166 -0
- smelt/analysis/files.py +279 -0
- smelt/analysis/function_usage.py +123 -0
- smelt/analysis/graphs.py +77 -0
- smelt/analysis/identity.py +64 -0
- smelt/analysis/import_cache.py +98 -0
- smelt/analysis/imports.py +452 -0
- smelt/analysis/literals.py +17 -0
- smelt/analysis/member_state.py +108 -0
- smelt/analysis/members.py +975 -0
- smelt/analysis/ordering.py +399 -0
- smelt/analysis/ordering_rewrite.py +232 -0
- smelt/analysis/package_exports.py +58 -0
- smelt/analysis/parsing.py +126 -0
- smelt/analysis/python_version.py +164 -0
- smelt/analysis/retained.py +84 -0
- smelt/analysis/syntax.py +109 -0
- smelt/analysis/test_awaits.py +91 -0
- smelt/analysis/test_cases.py +84 -0
- smelt/analysis/test_deadlines.py +90 -0
- smelt/analysis/test_outcomes.py +71 -0
- smelt/analysis/test_subprocesses.py +107 -0
- smelt/analysis/test_syntax.py +1425 -0
- smelt/analysis/test_timing.py +76 -0
- smelt/analysis/type_dispatch.py +193 -0
- smelt/analysis/workspace.py +146 -0
- smelt/cli/__init__.py +3 -0
- smelt/cli/app.py +300 -0
- smelt/cli/commands/__init__.py +62 -0
- smelt/cli/commands/adopt.py +274 -0
- smelt/cli/commands/check.py +151 -0
- smelt/cli/commands/discover.py +51 -0
- smelt/cli/commands/info.py +112 -0
- smelt/cli/session.py +163 -0
- smelt/cli/session_slots.py +43 -0
- smelt/cli/support.py +90 -0
- smelt/config/__init__.py +36 -0
- smelt/config/discovery.py +93 -0
- smelt/config/errors.py +51 -0
- smelt/config/loader.py +282 -0
- smelt/config/models.py +717 -0
- smelt/config/patterns.py +47 -0
- smelt/config/schema.py +23 -0
- smelt/config/source.py +56 -0
- smelt/config/validation.py +180 -0
- smelt/diagnostics/__init__.py +0 -0
- smelt/diagnostics/debt.py +226 -0
- smelt/diagnostics/dedupe.py +41 -0
- smelt/diagnostics/groups.py +109 -0
- smelt/diagnostics/render/__init__.py +0 -0
- smelt/diagnostics/render/machine.py +237 -0
- smelt/diagnostics/render/text.py +321 -0
- smelt/diagnostics/report.py +104 -0
- smelt/diagnostics/suppressions.py +80 -0
- smelt/diagnostics/violation.py +120 -0
- smelt/docs.py +98 -0
- smelt/engine/__init__.py +0 -0
- smelt/engine/briefing.py +630 -0
- smelt/engine/cache.py +65 -0
- smelt/engine/changes.py +260 -0
- smelt/engine/check.py +724 -0
- smelt/engine/coverage.py +151 -0
- smelt/engine/evaluation.py +291 -0
- smelt/engine/file_checks.py +94 -0
- smelt/engine/git_source.py +140 -0
- smelt/engine/inference.py +854 -0
- smelt/engine/mirror_inference.py +95 -0
- smelt/engine/native_git.py +190 -0
- smelt/engine/ordering_fixes.py +132 -0
- smelt/engine/paths.py +163 -0
- smelt/engine/result_cache.py +208 -0
- smelt/engine/rule_settings.py +164 -0
- smelt/engine/schema.py +58 -0
- smelt/engine/staged.py +75 -0
- smelt/engine/workspace.py +5 -0
- smelt/model/__init__.py +9 -0
- smelt/model/architecture.py +234 -0
- smelt/py.typed +0 -0
- smelt/rules/__init__.py +0 -0
- smelt/rules/activation.py +129 -0
- smelt/rules/base.py +131 -0
- smelt/rules/catalog.json +600 -0
- smelt/rules/common.py +164 -0
- smelt/rules/dependencies/__init__.py +0 -0
- smelt/rules/dependencies/composition_root.py +86 -0
- smelt/rules/dependencies/cycles.py +329 -0
- smelt/rules/dependencies/fanout.py +81 -0
- smelt/rules/dependencies/features.py +165 -0
- smelt/rules/dependencies/interfaces.py +84 -0
- smelt/rules/dependencies/layers.py +138 -0
- smelt/rules/dependencies/third_party.py +132 -0
- smelt/rules/member_names.py +13 -0
- smelt/rules/meta.py +74 -0
- smelt/rules/registry.py +132 -0
- smelt/rules/structure/__init__.py +0 -0
- smelt/rules/structure/assignments.py +114 -0
- smelt/rules/structure/contracts.py +71 -0
- smelt/rules/structure/coverage.py +100 -0
- smelt/rules/structure/enum_values.py +50 -0
- smelt/rules/structure/headers.py +143 -0
- smelt/rules/structure/import_style.py +145 -0
- smelt/rules/structure/layout.py +202 -0
- smelt/rules/structure/members.py +116 -0
- smelt/rules/structure/naming.py +132 -0
- smelt/rules/structure/ordering.py +83 -0
- smelt/rules/structure/package_imports.py +117 -0
- smelt/rules/structure/type_dispatch.py +79 -0
- smelt/rules/testing/__init__.py +0 -0
- smelt/rules/testing/awaits.py +46 -0
- smelt/rules/testing/cases.py +47 -0
- smelt/rules/testing/location.py +537 -0
- smelt/rules/testing/mocking.py +140 -0
- smelt/rules/testing/outcomes.py +119 -0
- smelt/rules/testing/private_access.py +93 -0
- smelt/rules/testing/public_attributes.py +62 -0
- smelt/rules/testing/public_functions.py +52 -0
- smelt/rules/testing/timing.py +62 -0
- smelt_cli-0.2.0.data/scripts/smelt.exe +0 -0
- smelt_cli-0.2.0.dist-info/METADATA +103 -0
- smelt_cli-0.2.0.dist-info/RECORD +133 -0
- smelt_cli-0.2.0.dist-info/WHEEL +4 -0
- smelt_cli-0.2.0.dist-info/sboms/smelt-cli.cyclonedx.json +5462 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""Shared binding, export and reference facts for public-use analysis."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import ast
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
7
|
+
|
|
8
|
+
from smelt.analysis.parsing import resolve_relative
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from collections.abc import Iterator
|
|
12
|
+
|
|
13
|
+
from smelt.analysis.syntax import ModuleSyntax
|
|
14
|
+
|
|
15
|
+
type Target = tuple[str, str | None]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def definition_bindings(tree: ast.Module) -> dict[str, list[ast.AST]]:
|
|
19
|
+
definitions: dict[str, list[ast.AST]] = {}
|
|
20
|
+
for node in ast.walk(tree):
|
|
21
|
+
if isinstance(node, ast.Name) and isinstance(node.ctx, ast.Store | ast.Del):
|
|
22
|
+
definitions.setdefault(node.id, []).append(node)
|
|
23
|
+
elif isinstance(node, ast.FunctionDef | ast.AsyncFunctionDef | ast.ClassDef):
|
|
24
|
+
definitions.setdefault(node.name, []).append(node)
|
|
25
|
+
return definitions
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def reference_names(module: ModuleSyntax) -> tuple[list[str], list[str], list[str]]:
|
|
29
|
+
"""Unresolved use evidence, independent of every other module's contents."""
|
|
30
|
+
imports: set[str] = set()
|
|
31
|
+
loads: set[str] = set()
|
|
32
|
+
stars: set[str] = set()
|
|
33
|
+
nodes = list(ast.walk(module.tree))
|
|
34
|
+
# Preserve every possible import binding. A same-named import in a different
|
|
35
|
+
# local scope must not hide a real production consumer elsewhere in the file.
|
|
36
|
+
bindings: dict[str, set[str]] = {}
|
|
37
|
+
for node in nodes:
|
|
38
|
+
if isinstance(node, ast.Import):
|
|
39
|
+
for alias in node.names:
|
|
40
|
+
name = alias.asname or alias.name.split(".")[0]
|
|
41
|
+
bindings.setdefault(name, set()).add(
|
|
42
|
+
alias.name if alias.asname else name
|
|
43
|
+
)
|
|
44
|
+
elif isinstance(node, ast.ImportFrom):
|
|
45
|
+
base = resolve_relative(
|
|
46
|
+
module.module,
|
|
47
|
+
is_package=module.is_package,
|
|
48
|
+
level=node.level,
|
|
49
|
+
target=node.module,
|
|
50
|
+
)
|
|
51
|
+
for alias in node.names:
|
|
52
|
+
if alias.name == "*":
|
|
53
|
+
stars.add(base)
|
|
54
|
+
continue
|
|
55
|
+
qualified = f"{base}.{alias.name}"
|
|
56
|
+
bindings.setdefault(alias.asname or alias.name, set()).add(qualified)
|
|
57
|
+
imports.add(qualified)
|
|
58
|
+
parents = {
|
|
59
|
+
child: parent for parent in nodes for child in ast.iter_child_nodes(parent)
|
|
60
|
+
}
|
|
61
|
+
for node in nodes:
|
|
62
|
+
if isinstance(node, ast.Name | ast.Attribute) and isinstance(
|
|
63
|
+
node.ctx, ast.Load
|
|
64
|
+
):
|
|
65
|
+
parent = parents.get(node)
|
|
66
|
+
if isinstance(parent, ast.Attribute) and parent.value is node:
|
|
67
|
+
continue
|
|
68
|
+
for qualified in _qualified(node, bindings):
|
|
69
|
+
# Module-valued loads may escape via aliases, callbacks or reflection.
|
|
70
|
+
loads.add(qualified)
|
|
71
|
+
return sorted(imports), sorted(loads), sorted(stars)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def explicit_exports(tree: ast.Module) -> frozenset[str] | None:
|
|
75
|
+
"""None means a dynamic export declaration whose intent we cannot narrow."""
|
|
76
|
+
exports: set[str] = set()
|
|
77
|
+
handled: set[ast.AST] = set()
|
|
78
|
+
for node in tree.body:
|
|
79
|
+
if not isinstance(node, ast.Assign | ast.AnnAssign | ast.AugAssign):
|
|
80
|
+
continue
|
|
81
|
+
targets: list[ast.expr] = []
|
|
82
|
+
if isinstance(node, ast.Assign):
|
|
83
|
+
targets = node.targets
|
|
84
|
+
elif isinstance(node, ast.AnnAssign | ast.AugAssign):
|
|
85
|
+
targets = [node.target]
|
|
86
|
+
names = [
|
|
87
|
+
target
|
|
88
|
+
for target in targets
|
|
89
|
+
if isinstance(target, ast.Name) and target.id == "__all__"
|
|
90
|
+
]
|
|
91
|
+
if not names:
|
|
92
|
+
continue
|
|
93
|
+
value = node.value
|
|
94
|
+
if not isinstance(value, ast.List | ast.Tuple | ast.Set) or not all(
|
|
95
|
+
isinstance(item, ast.Constant) and isinstance(item.value, str)
|
|
96
|
+
for item in value.elts
|
|
97
|
+
):
|
|
98
|
+
return None
|
|
99
|
+
if isinstance(node, ast.AugAssign):
|
|
100
|
+
if not isinstance(node.op, ast.Add):
|
|
101
|
+
return None
|
|
102
|
+
else:
|
|
103
|
+
exports.clear()
|
|
104
|
+
exports.update(
|
|
105
|
+
item.value
|
|
106
|
+
for item in value.elts
|
|
107
|
+
if isinstance(item, ast.Constant) and isinstance(item.value, str)
|
|
108
|
+
)
|
|
109
|
+
handled.update(names)
|
|
110
|
+
if any(
|
|
111
|
+
isinstance(node, ast.Name) and node.id == "__all__" and node not in handled
|
|
112
|
+
for node in ast.walk(tree)
|
|
113
|
+
):
|
|
114
|
+
return None
|
|
115
|
+
return frozenset(exports)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _qualified(node: ast.AST, bindings: dict[str, set[str]]) -> Iterator[str]:
|
|
119
|
+
if isinstance(node, ast.Name):
|
|
120
|
+
yield from sorted(bindings.get(node.id, ()))
|
|
121
|
+
elif isinstance(node, ast.Attribute):
|
|
122
|
+
for base in _qualified(node.value, bindings):
|
|
123
|
+
yield f"{base}.{node.attr}"
|
smelt/analysis/graphs.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
from collections import deque
|
|
2
|
+
from collections.abc import Hashable, Mapping, Set
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def strongly_connected_components[T: Hashable](
|
|
6
|
+
adjacency: Mapping[T, Set[T]],
|
|
7
|
+
) -> list[set[T]]:
|
|
8
|
+
"""Tarjan's algorithm, iterative so deep graphs don't hit the recursion limit."""
|
|
9
|
+
index_of: dict[T, int] = {}
|
|
10
|
+
lowlink: dict[T, int] = {}
|
|
11
|
+
on_stack: set[T] = set()
|
|
12
|
+
stack: list[T] = []
|
|
13
|
+
components: list[set[T]] = []
|
|
14
|
+
counter = 0
|
|
15
|
+
nodes = set(adjacency) | {n for targets in adjacency.values() for n in targets}
|
|
16
|
+
|
|
17
|
+
for start in sorted(nodes, key=str):
|
|
18
|
+
if start in index_of:
|
|
19
|
+
continue
|
|
20
|
+
work: list[tuple[T, list[T]]] = [
|
|
21
|
+
(start, sorted(adjacency.get(start, ()), key=str))
|
|
22
|
+
]
|
|
23
|
+
index_of[start] = lowlink[start] = counter
|
|
24
|
+
counter += 1
|
|
25
|
+
stack.append(start)
|
|
26
|
+
on_stack.add(start)
|
|
27
|
+
while work:
|
|
28
|
+
node, children = work[-1]
|
|
29
|
+
if children:
|
|
30
|
+
child = children.pop(0)
|
|
31
|
+
if child not in index_of:
|
|
32
|
+
index_of[child] = lowlink[child] = counter
|
|
33
|
+
counter += 1
|
|
34
|
+
stack.append(child)
|
|
35
|
+
on_stack.add(child)
|
|
36
|
+
work.append((child, sorted(adjacency.get(child, ()), key=str)))
|
|
37
|
+
elif child in on_stack:
|
|
38
|
+
lowlink[node] = min(lowlink[node], index_of[child])
|
|
39
|
+
continue
|
|
40
|
+
work.pop()
|
|
41
|
+
if work:
|
|
42
|
+
parent = work[-1][0]
|
|
43
|
+
lowlink[parent] = min(lowlink[parent], lowlink[node])
|
|
44
|
+
if lowlink[node] == index_of[node]:
|
|
45
|
+
component: set[T] = set()
|
|
46
|
+
while True:
|
|
47
|
+
member = stack.pop()
|
|
48
|
+
on_stack.discard(member)
|
|
49
|
+
component.add(member)
|
|
50
|
+
if member == node:
|
|
51
|
+
break
|
|
52
|
+
components.append(component)
|
|
53
|
+
return components
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def shortest_cycle[T: Hashable](
|
|
57
|
+
start: T, adjacency: Mapping[T, Set[T]], within: Set[T]
|
|
58
|
+
) -> list[T] | None:
|
|
59
|
+
"""Shortest path ``start -> ... -> start`` using only nodes in ``within``."""
|
|
60
|
+
previous: dict[T, T] = {}
|
|
61
|
+
queue: deque[T] = deque([start])
|
|
62
|
+
visited: set[T] = set()
|
|
63
|
+
while queue:
|
|
64
|
+
node = queue.popleft()
|
|
65
|
+
for child in sorted(adjacency.get(node, ()), key=str):
|
|
66
|
+
if child not in within:
|
|
67
|
+
continue
|
|
68
|
+
if child == start:
|
|
69
|
+
path = [node]
|
|
70
|
+
while path[-1] != start:
|
|
71
|
+
path.append(previous[path[-1]])
|
|
72
|
+
return [*reversed(path), start]
|
|
73
|
+
if child not in visited:
|
|
74
|
+
visited.add(child)
|
|
75
|
+
previous[child] = node
|
|
76
|
+
queue.append(child)
|
|
77
|
+
return None
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""Cache identity without importing the analysis engine or its schemas."""
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import json
|
|
5
|
+
import sys
|
|
6
|
+
from functools import cache
|
|
7
|
+
from importlib.metadata import PackageNotFoundError, distribution, version
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _installed_sources(package: Path) -> list[tuple[str, str, str, int | None]] | None:
|
|
12
|
+
"""Use the installed wheel's build hashes, never those of another checkout."""
|
|
13
|
+
try:
|
|
14
|
+
installed = distribution("smelt-cli")
|
|
15
|
+
direct = json.loads(installed.read_text("direct_url.json") or "{}")
|
|
16
|
+
if direct.get("dir_info", {}).get("editable", False):
|
|
17
|
+
return None
|
|
18
|
+
if Path(str(installed.locate_file("smelt"))).resolve() != package:
|
|
19
|
+
return None
|
|
20
|
+
files = sorted(
|
|
21
|
+
(
|
|
22
|
+
file
|
|
23
|
+
for file in installed.files or ()
|
|
24
|
+
if file.parts
|
|
25
|
+
and file.parts[0] == "smelt"
|
|
26
|
+
and file.suffix in {".py", ".json"}
|
|
27
|
+
),
|
|
28
|
+
key=str,
|
|
29
|
+
)
|
|
30
|
+
if not files or any(file.hash is None for file in files):
|
|
31
|
+
return None
|
|
32
|
+
return [
|
|
33
|
+
(str(file), file.hash.mode, file.hash.value, file.size)
|
|
34
|
+
for file in files
|
|
35
|
+
if file.hash is not None
|
|
36
|
+
]
|
|
37
|
+
except (OSError, ValueError, TypeError, AttributeError, PackageNotFoundError):
|
|
38
|
+
return None
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@cache
|
|
42
|
+
def analyzer_identity() -> str:
|
|
43
|
+
"""Invalidate editable checkouts too, even without a package version bump."""
|
|
44
|
+
digest = hashlib.sha256()
|
|
45
|
+
package = Path(__file__).resolve().parent.parent
|
|
46
|
+
record = _installed_sources(package)
|
|
47
|
+
if record is not None:
|
|
48
|
+
digest.update(b"wheel-record\0")
|
|
49
|
+
digest.update(json.dumps(record).encode())
|
|
50
|
+
else:
|
|
51
|
+
digest.update(b"source\0")
|
|
52
|
+
for path in sorted(
|
|
53
|
+
path for path in package.rglob("*") if path.suffix in {".py", ".json"}
|
|
54
|
+
):
|
|
55
|
+
digest.update(path.relative_to(package).as_posix().encode())
|
|
56
|
+
digest.update(path.read_bytes())
|
|
57
|
+
digest.update(str(sys.version_info).encode())
|
|
58
|
+
for dependency in ("smelt-cli", "grimp", "pydantic", "packaging", "pyyaml"):
|
|
59
|
+
try:
|
|
60
|
+
installed = version(dependency)
|
|
61
|
+
except PackageNotFoundError:
|
|
62
|
+
installed = "uninstalled"
|
|
63
|
+
digest.update(f"{dependency}:{installed}".encode())
|
|
64
|
+
return digest.hexdigest()
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""Per-module native import scans, keyed by contents and resolution inventory."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
from typing import TYPE_CHECKING
|
|
8
|
+
|
|
9
|
+
from grimp.application.ports.caching import Cache, CacheMiss
|
|
10
|
+
from grimp.domain.valueobjects import DirectImport, Module
|
|
11
|
+
from pydantic import TypeAdapter
|
|
12
|
+
|
|
13
|
+
from smelt.analysis.files import python_files
|
|
14
|
+
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
from grimp.application.ports.modulefinder import ModuleFile
|
|
17
|
+
|
|
18
|
+
from smelt.analysis.cache import FactCache
|
|
19
|
+
from smelt.analysis.files import FileIndex
|
|
20
|
+
from smelt.analysis.parsing import AstCache
|
|
21
|
+
|
|
22
|
+
_IMPORTS = TypeAdapter(list[DirectImport])
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def resolution_identity(files: FileIndex) -> str:
|
|
26
|
+
inventory = files.store.inventory()
|
|
27
|
+
paths = (
|
|
28
|
+
inventory
|
|
29
|
+
if inventory is not None
|
|
30
|
+
else (
|
|
31
|
+
path
|
|
32
|
+
for roots in files.package_roots.values()
|
|
33
|
+
for root in roots
|
|
34
|
+
for path in python_files(root, store=files.store)
|
|
35
|
+
)
|
|
36
|
+
)
|
|
37
|
+
inputs = [
|
|
38
|
+
sorted(files.relative(path) for path in paths if path.suffix == ".py"),
|
|
39
|
+
[
|
|
40
|
+
(s.module, s.path, s.is_package)
|
|
41
|
+
for s in sorted(files.sources.values(), key=lambda s: s.path)
|
|
42
|
+
],
|
|
43
|
+
[
|
|
44
|
+
(name, [(p.path, p.has_init) for p in parts])
|
|
45
|
+
for name, parts in sorted(files.package_parts.items())
|
|
46
|
+
],
|
|
47
|
+
]
|
|
48
|
+
return hashlib.sha256(json.dumps(inputs).encode()).hexdigest()
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def import_cache_type(
|
|
52
|
+
files: FileIndex, asts: AstCache, cache: FactCache | None, inventory: str
|
|
53
|
+
) -> type[Cache]:
|
|
54
|
+
misses: set[Module] = set()
|
|
55
|
+
|
|
56
|
+
class ContentCache(Cache):
|
|
57
|
+
def key(self, module: Module) -> str:
|
|
58
|
+
source = files.sources[module.name]
|
|
59
|
+
if cache is None:
|
|
60
|
+
raise CacheMiss
|
|
61
|
+
return cache.key(
|
|
62
|
+
"native-imports",
|
|
63
|
+
[
|
|
64
|
+
source.module,
|
|
65
|
+
source.path,
|
|
66
|
+
source.is_package,
|
|
67
|
+
files.content_id(source.path),
|
|
68
|
+
inventory,
|
|
69
|
+
self.include_external_packages,
|
|
70
|
+
self.exclude_type_checking_imports,
|
|
71
|
+
],
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
def read_imports(self, module_file: ModuleFile) -> set[DirectImport]:
|
|
75
|
+
module = module_file.module
|
|
76
|
+
cached = (
|
|
77
|
+
cache.read(self.key(module), _IMPORTS) if cache is not None else None
|
|
78
|
+
)
|
|
79
|
+
if cached is not None:
|
|
80
|
+
return set(cached)
|
|
81
|
+
# Validate only new contents before Grimp's native scanner, retaining
|
|
82
|
+
# Smelt's syntax/encoding errors without reparsing unchanged files.
|
|
83
|
+
asts.parse(files.sources[module.name].path)
|
|
84
|
+
misses.add(module)
|
|
85
|
+
raise CacheMiss
|
|
86
|
+
|
|
87
|
+
def write(self, imports_by_module: dict[Module, set[DirectImport]]) -> None:
|
|
88
|
+
if cache is not None:
|
|
89
|
+
for module in misses:
|
|
90
|
+
cache.write(
|
|
91
|
+
self.key(module), sorted(imports_by_module[module]), _IMPORTS
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
@classmethod
|
|
95
|
+
def cache_dir_or_default(cls, cache_dir: str | None) -> str:
|
|
96
|
+
return cache_dir or "smelt"
|
|
97
|
+
|
|
98
|
+
return ContentCache
|