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.
Files changed (133) hide show
  1. smelt/__init__.py +6 -0
  2. smelt/__main__.py +5 -0
  3. smelt/analysis/__init__.py +45 -0
  4. smelt/analysis/annotations.py +105 -0
  5. smelt/analysis/cache.py +168 -0
  6. smelt/analysis/context.py +147 -0
  7. smelt/analysis/contracts.py +210 -0
  8. smelt/analysis/coverage.py +377 -0
  9. smelt/analysis/definition_blocks.py +569 -0
  10. smelt/analysis/enum_values.py +217 -0
  11. smelt/analysis/errors.py +11 -0
  12. smelt/analysis/exports.py +166 -0
  13. smelt/analysis/files.py +279 -0
  14. smelt/analysis/function_usage.py +123 -0
  15. smelt/analysis/graphs.py +77 -0
  16. smelt/analysis/identity.py +64 -0
  17. smelt/analysis/import_cache.py +98 -0
  18. smelt/analysis/imports.py +452 -0
  19. smelt/analysis/literals.py +17 -0
  20. smelt/analysis/member_state.py +108 -0
  21. smelt/analysis/members.py +975 -0
  22. smelt/analysis/ordering.py +399 -0
  23. smelt/analysis/ordering_rewrite.py +232 -0
  24. smelt/analysis/package_exports.py +58 -0
  25. smelt/analysis/parsing.py +126 -0
  26. smelt/analysis/python_version.py +164 -0
  27. smelt/analysis/retained.py +84 -0
  28. smelt/analysis/syntax.py +109 -0
  29. smelt/analysis/test_awaits.py +91 -0
  30. smelt/analysis/test_cases.py +84 -0
  31. smelt/analysis/test_deadlines.py +90 -0
  32. smelt/analysis/test_outcomes.py +71 -0
  33. smelt/analysis/test_subprocesses.py +107 -0
  34. smelt/analysis/test_syntax.py +1425 -0
  35. smelt/analysis/test_timing.py +76 -0
  36. smelt/analysis/type_dispatch.py +193 -0
  37. smelt/analysis/workspace.py +146 -0
  38. smelt/cli/__init__.py +3 -0
  39. smelt/cli/app.py +300 -0
  40. smelt/cli/commands/__init__.py +62 -0
  41. smelt/cli/commands/adopt.py +274 -0
  42. smelt/cli/commands/check.py +151 -0
  43. smelt/cli/commands/discover.py +51 -0
  44. smelt/cli/commands/info.py +112 -0
  45. smelt/cli/session.py +163 -0
  46. smelt/cli/session_slots.py +43 -0
  47. smelt/cli/support.py +90 -0
  48. smelt/config/__init__.py +36 -0
  49. smelt/config/discovery.py +93 -0
  50. smelt/config/errors.py +51 -0
  51. smelt/config/loader.py +282 -0
  52. smelt/config/models.py +717 -0
  53. smelt/config/patterns.py +47 -0
  54. smelt/config/schema.py +23 -0
  55. smelt/config/source.py +56 -0
  56. smelt/config/validation.py +180 -0
  57. smelt/diagnostics/__init__.py +0 -0
  58. smelt/diagnostics/debt.py +226 -0
  59. smelt/diagnostics/dedupe.py +41 -0
  60. smelt/diagnostics/groups.py +109 -0
  61. smelt/diagnostics/render/__init__.py +0 -0
  62. smelt/diagnostics/render/machine.py +237 -0
  63. smelt/diagnostics/render/text.py +321 -0
  64. smelt/diagnostics/report.py +104 -0
  65. smelt/diagnostics/suppressions.py +80 -0
  66. smelt/diagnostics/violation.py +120 -0
  67. smelt/docs.py +98 -0
  68. smelt/engine/__init__.py +0 -0
  69. smelt/engine/briefing.py +630 -0
  70. smelt/engine/cache.py +65 -0
  71. smelt/engine/changes.py +260 -0
  72. smelt/engine/check.py +724 -0
  73. smelt/engine/coverage.py +151 -0
  74. smelt/engine/evaluation.py +291 -0
  75. smelt/engine/file_checks.py +94 -0
  76. smelt/engine/git_source.py +140 -0
  77. smelt/engine/inference.py +854 -0
  78. smelt/engine/mirror_inference.py +95 -0
  79. smelt/engine/native_git.py +190 -0
  80. smelt/engine/ordering_fixes.py +132 -0
  81. smelt/engine/paths.py +163 -0
  82. smelt/engine/result_cache.py +208 -0
  83. smelt/engine/rule_settings.py +164 -0
  84. smelt/engine/schema.py +58 -0
  85. smelt/engine/staged.py +75 -0
  86. smelt/engine/workspace.py +5 -0
  87. smelt/model/__init__.py +9 -0
  88. smelt/model/architecture.py +234 -0
  89. smelt/py.typed +0 -0
  90. smelt/rules/__init__.py +0 -0
  91. smelt/rules/activation.py +129 -0
  92. smelt/rules/base.py +131 -0
  93. smelt/rules/catalog.json +600 -0
  94. smelt/rules/common.py +164 -0
  95. smelt/rules/dependencies/__init__.py +0 -0
  96. smelt/rules/dependencies/composition_root.py +86 -0
  97. smelt/rules/dependencies/cycles.py +329 -0
  98. smelt/rules/dependencies/fanout.py +81 -0
  99. smelt/rules/dependencies/features.py +165 -0
  100. smelt/rules/dependencies/interfaces.py +84 -0
  101. smelt/rules/dependencies/layers.py +138 -0
  102. smelt/rules/dependencies/third_party.py +132 -0
  103. smelt/rules/member_names.py +13 -0
  104. smelt/rules/meta.py +74 -0
  105. smelt/rules/registry.py +132 -0
  106. smelt/rules/structure/__init__.py +0 -0
  107. smelt/rules/structure/assignments.py +114 -0
  108. smelt/rules/structure/contracts.py +71 -0
  109. smelt/rules/structure/coverage.py +100 -0
  110. smelt/rules/structure/enum_values.py +50 -0
  111. smelt/rules/structure/headers.py +143 -0
  112. smelt/rules/structure/import_style.py +145 -0
  113. smelt/rules/structure/layout.py +202 -0
  114. smelt/rules/structure/members.py +116 -0
  115. smelt/rules/structure/naming.py +132 -0
  116. smelt/rules/structure/ordering.py +83 -0
  117. smelt/rules/structure/package_imports.py +117 -0
  118. smelt/rules/structure/type_dispatch.py +79 -0
  119. smelt/rules/testing/__init__.py +0 -0
  120. smelt/rules/testing/awaits.py +46 -0
  121. smelt/rules/testing/cases.py +47 -0
  122. smelt/rules/testing/location.py +537 -0
  123. smelt/rules/testing/mocking.py +140 -0
  124. smelt/rules/testing/outcomes.py +119 -0
  125. smelt/rules/testing/private_access.py +93 -0
  126. smelt/rules/testing/public_attributes.py +62 -0
  127. smelt/rules/testing/public_functions.py +52 -0
  128. smelt/rules/testing/timing.py +62 -0
  129. smelt_cli-0.2.0.data/scripts/smelt.exe +0 -0
  130. smelt_cli-0.2.0.dist-info/METADATA +103 -0
  131. smelt_cli-0.2.0.dist-info/RECORD +133 -0
  132. smelt_cli-0.2.0.dist-info/WHEEL +4 -0
  133. smelt_cli-0.2.0.dist-info/sboms/smelt-cli.cyclonedx.json +5462 -0
@@ -0,0 +1,90 @@
1
+ """Local async deadline facts shared by outcome and timing review."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import ast
6
+ from dataclasses import dataclass
7
+ from typing import TYPE_CHECKING
8
+
9
+ if TYPE_CHECKING:
10
+ from collections.abc import Mapping, Sequence
11
+
12
+
13
+ def has_timeout(
14
+ call: ast.Call, name: str = "timeout", position: int | None = None
15
+ ) -> bool:
16
+ value = next((kw.value for kw in call.keywords if kw.arg == name), None)
17
+ if value is None and position is not None and len(call.args) > position:
18
+ value = call.args[position]
19
+ return value is not None and not (
20
+ isinstance(value, ast.Constant) and value.value is None
21
+ )
22
+
23
+
24
+ _CONTEXT_TIMEOUTS = {
25
+ "asyncio.timeout": "delay",
26
+ "asyncio.timeout_at": "when",
27
+ "anyio.fail_after": "delay",
28
+ "anyio.move_on_after": "delay",
29
+ "trio.fail_after": "seconds",
30
+ "trio.move_on_after": "seconds",
31
+ }
32
+
33
+
34
+ @dataclass(frozen=True)
35
+ class AsyncDeadline:
36
+ awaited: bool
37
+ bounded: bool
38
+ raises_on_timeout: bool
39
+
40
+
41
+ def async_deadline(
42
+ node: ast.Call | ast.Await,
43
+ calls: Mapping[ast.Call, str],
44
+ parents: Mapping[ast.AST, ast.AST],
45
+ helpers: Sequence[str] = (),
46
+ ) -> AsyncDeadline:
47
+ awaited = isinstance(node, ast.Await)
48
+ bounded = False
49
+ raises = False
50
+ may_move_on = False
51
+ awaitable: ast.AST | None = node if isinstance(node, ast.Call) else None
52
+ child: ast.AST = node
53
+ parent = parents.get(child)
54
+ while parent is not None:
55
+ if isinstance(parent, ast.Await) and child is awaitable:
56
+ awaited = True
57
+ awaitable = None
58
+ if isinstance(parent, ast.Call):
59
+ wrapper = calls.get(parent)
60
+ wraps = awaitable is not None and (
61
+ bool(parent.args and parent.args[0] is awaitable)
62
+ or any(
63
+ kw.arg == "fut" and kw.value is awaitable for kw in parent.keywords
64
+ )
65
+ )
66
+ if wraps and wrapper == "asyncio.wait_for":
67
+ awaitable = parent
68
+ if has_timeout(parent, position=1):
69
+ bounded = True
70
+ raises = True
71
+ elif wraps and wrapper in helpers:
72
+ awaitable = parent
73
+ bounded = True
74
+ if isinstance(parent, ast.With | ast.AsyncWith) and child in parent.body:
75
+ for item in parent.items:
76
+ context = item.context_expr
77
+ if not isinstance(context, ast.Call):
78
+ continue
79
+ wrapper = calls.get(context)
80
+ keyword = _CONTEXT_TIMEOUTS.get(wrapper or "")
81
+ if keyword and has_timeout(context, keyword, 0):
82
+ bounded = True
83
+ if wrapper and wrapper.endswith(".move_on_after"):
84
+ may_move_on = True
85
+ else:
86
+ raises = True
87
+ bounded |= wrapper in helpers
88
+ child, parent = parent, parents.get(parent)
89
+ # A move_on_after scope may leave successfully before the event is observed.
90
+ return AsyncDeadline(awaited, bounded, raises and not may_move_on)
@@ -0,0 +1,71 @@
1
+ """Conservative evidence that all recognized checks can vanish on empty output."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import ast
6
+ from typing import TYPE_CHECKING
7
+
8
+ from smelt.analysis.literals import nonempty_literal
9
+
10
+ if TYPE_CHECKING:
11
+ from smelt.analysis.test_syntax import TestFunction
12
+
13
+
14
+ def vacuous_outcomes(
15
+ test: TestFunction, helpers: list[str]
16
+ ) -> list[ast.For | ast.AsyncFor | ast.Call]:
17
+ """Report only when every recognized outcome is loop/all dependent.
18
+
19
+ An additional explicit check is evidence, not a proof of a nonempty collection.
20
+ No attempt is made to judge persistence semantics or general reachability.
21
+ """
22
+ evidence = test.outcome_evidence(helpers)
23
+ if not evidence:
24
+ return []
25
+ parents = {
26
+ child: node
27
+ for node in ast.walk(test.node)
28
+ for child in ast.iter_child_nodes(node)
29
+ }
30
+ universal = {call.node for call in test.calls if call.qualified == "builtins.all"}
31
+ risks: list[ast.For | ast.AsyncFor | ast.Call] = []
32
+ for outcome in evidence:
33
+ child: ast.AST = outcome
34
+ parent = parents.get(outcome)
35
+ risky: ast.For | ast.AsyncFor | ast.Call | None = None
36
+ while parent is not None and parent is not test.node:
37
+ if (
38
+ isinstance(parent, ast.For | ast.AsyncFor)
39
+ and child in parent.body
40
+ and _possibly_empty(parent.iter, test.nonempty_iterables)
41
+ ):
42
+ risky = parent
43
+ break
44
+ child, parent = parent, parents.get(parent)
45
+ if risky is None and isinstance(outcome, ast.Assert):
46
+ expression = outcome.test
47
+ # Explicit empty/alternative cases and compound assertions remain
48
+ # outside this narrow review aid.
49
+ if (
50
+ isinstance(expression, ast.Call)
51
+ and expression in universal
52
+ and expression.args
53
+ and _possibly_empty(expression.args[0], test.nonempty_iterables)
54
+ ):
55
+ risky = expression
56
+ if risky is None:
57
+ return []
58
+ if risky not in risks:
59
+ risks.append(risky)
60
+ return risks
61
+
62
+
63
+ def _possibly_empty(node: ast.expr, known: set[ast.expr]) -> bool:
64
+ if isinstance(node, ast.GeneratorExp | ast.ListComp | ast.SetComp | ast.DictComp):
65
+ return any(
66
+ generator.ifs
67
+ or generator.is_async
68
+ or _possibly_empty(generator.iter, known)
69
+ for generator in node.generators
70
+ )
71
+ return node not in known and not nonempty_literal(node)
@@ -0,0 +1,107 @@
1
+ """Static outcome evidence in checked, inline Python subprocesses."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import ast
6
+ from typing import TYPE_CHECKING
7
+
8
+ if TYPE_CHECKING:
9
+ from collections.abc import Callable, Mapping
10
+
11
+ _CHECKED = frozenset(
12
+ {"subprocess.run", "subprocess.check_call", "subprocess.check_output"}
13
+ )
14
+ _FLAGS = frozenset({"-P", "-I", "-B", "-u"})
15
+
16
+
17
+ def checked_python_assertions(
18
+ call: ast.Call,
19
+ qualified: str,
20
+ resolve: Callable[[ast.AST], str | None],
21
+ text: Callable[[ast.expr], str | None],
22
+ ) -> bool:
23
+ if not _checked_options(call, qualified, text):
24
+ return False
25
+ command = (
26
+ call.args[0]
27
+ if call.args
28
+ else next((kw.value for kw in call.keywords if kw.arg == "args"), None)
29
+ )
30
+ source = _python_source(command, resolve, text)
31
+ if source is None:
32
+ return False
33
+ try:
34
+ tree = ast.parse(source)
35
+ except (SyntaxError, ValueError, RecursionError):
36
+ return False
37
+ return any(
38
+ isinstance(node, ast.Assert)
39
+ and not (isinstance(node.test, ast.Constant) and node.test.value is True)
40
+ for node in tree.body
41
+ )
42
+
43
+
44
+ def child_status_propagates(call: ast.Call, parents: Mapping[ast.AST, ast.AST]) -> bool:
45
+ node: ast.AST = call
46
+ while node in parents:
47
+ node = parents[node]
48
+ if isinstance(node, ast.Try | ast.TryStar | ast.With | ast.AsyncWith):
49
+ return False
50
+ return True
51
+
52
+
53
+ _COMMAND_PARTS = 3
54
+ _SCRIPT_ARGUMENTS = 2
55
+
56
+
57
+ def _checked_options(
58
+ call: ast.Call, qualified: str, text: Callable[[ast.expr], str | None]
59
+ ) -> bool:
60
+ if qualified not in _CHECKED or any(kw.arg is None for kw in call.keywords):
61
+ return False
62
+ options = {kw.arg: kw.value for kw in call.keywords}
63
+ check = options.get("check")
64
+ if qualified == "subprocess.run" and not (
65
+ isinstance(check, ast.Constant) and check.value is True
66
+ ):
67
+ return False
68
+ if "executable" in options or (
69
+ "shell" in options
70
+ and not (
71
+ isinstance(options["shell"], ast.Constant)
72
+ and options["shell"].value is False
73
+ )
74
+ ):
75
+ return False
76
+ environment = options.get("env")
77
+ return not (
78
+ environment is not None
79
+ and (
80
+ not isinstance(environment, ast.Dict)
81
+ or any(
82
+ text(key) == "PYTHONOPTIMIZE" and text(value) not in {"", "0"}
83
+ for key, value in zip(environment.keys, environment.values, strict=True)
84
+ if key is not None
85
+ )
86
+ )
87
+ )
88
+
89
+
90
+ def _python_source(
91
+ command: ast.expr | None,
92
+ resolve: Callable[[ast.AST], str | None],
93
+ text: Callable[[ast.expr], str | None],
94
+ ) -> str | None:
95
+ if (
96
+ not isinstance(command, ast.List | ast.Tuple)
97
+ or len(command.elts) < _COMMAND_PARTS
98
+ ):
99
+ return None
100
+ interpreter, *arguments = command.elts
101
+ if resolve(interpreter) != "sys.executable":
102
+ return None
103
+ while arguments and text(arguments[0]) in _FLAGS:
104
+ arguments.pop(0)
105
+ if len(arguments) != _SCRIPT_ARGUMENTS or text(arguments[0]) != "-c":
106
+ return None
107
+ return text(arguments[1])