pycforge 0.15.2__py3-none-any.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 (221) hide show
  1. pycforge/__init__.py +8 -0
  2. pycforge/__main__.py +2 -0
  3. pycforge/_version.py +1 -0
  4. pycforge/converter/__init__.py +0 -0
  5. pycforge/converter/analysis/__init__.py +5 -0
  6. pycforge/converter/analysis/functions.py +723 -0
  7. pycforge/converter/analysis/model.py +158 -0
  8. pycforge/converter/analysis/planning.py +464 -0
  9. pycforge/converter/analysis/stage.py +1976 -0
  10. pycforge/converter/analysis/symbols.py +237 -0
  11. pycforge/converter/analysis/validation.py +2166 -0
  12. pycforge/converter/c_output/__init__.py +2 -0
  13. pycforge/converter/c_output/conformance.py +297 -0
  14. pycforge/converter/c_output/renderer.py +220 -0
  15. pycforge/converter/conditional_regions/__init__.py +71 -0
  16. pycforge/converter/conditional_regions/analysis.py +481 -0
  17. pycforge/converter/conditional_regions/lowering.py +579 -0
  18. pycforge/converter/conditional_regions/model.py +243 -0
  19. pycforge/converter/conditional_regions/validation.py +690 -0
  20. pycforge/converter/containers/__init__.py +19 -0
  21. pycforge/converter/containers/analysis.py +542 -0
  22. pycforge/converter/containers/lowering.py +290 -0
  23. pycforge/converter/containers/model.py +146 -0
  24. pycforge/converter/contracts/__init__.py +0 -0
  25. pycforge/converter/contracts/configuration.py +178 -0
  26. pycforge/converter/contracts/identifiers.py +68 -0
  27. pycforge/converter/contracts/versions.py +71 -0
  28. pycforge/converter/core/__init__.py +0 -0
  29. pycforge/converter/core/artifact_io.py +87 -0
  30. pycforge/converter/core/cancellation.py +7 -0
  31. pycforge/converter/core/canonicalization.py +254 -0
  32. pycforge/converter/core/context.py +13 -0
  33. pycforge/converter/core/diagnostics.py +95 -0
  34. pycforge/converter/core/enums.py +23 -0
  35. pycforge/converter/core/fingerprint.py +22 -0
  36. pycforge/converter/core/pipeline.py +8 -0
  37. pycforge/converter/core/progress.py +25 -0
  38. pycforge/converter/core/request.py +50 -0
  39. pycforge/converter/core/resource_policy.py +31 -0
  40. pycforge/converter/core/result.py +23 -0
  41. pycforge/converter/core/serialization.py +36 -0
  42. pycforge/converter/core/stage.py +10 -0
  43. pycforge/converter/core/stage_artifact.py +80 -0
  44. pycforge/converter/core/stage_outcome.py +15 -0
  45. pycforge/converter/decision_trace/__init__.py +0 -0
  46. pycforge/converter/decision_trace/recorder.py +52 -0
  47. pycforge/converter/facade.py +459 -0
  48. pycforge/converter/frontend/__init__.py +4 -0
  49. pycforge/converter/frontend/normalizer.py +59 -0
  50. pycforge/converter/frontend/parser.py +20 -0
  51. pycforge/converter/frontend/source_document.py +93 -0
  52. pycforge/converter/frontend/stages.py +518 -0
  53. pycforge/converter/frontend/validation.py +76 -0
  54. pycforge/converter/io/__init__.py +0 -0
  55. pycforge/converter/io/atomic_writer.py +33 -0
  56. pycforge/converter/ir/__init__.py +1 -0
  57. pycforge/converter/ir/c_ir/__init__.py +4 -0
  58. pycforge/converter/ir/c_ir/builder.py +26 -0
  59. pycforge/converter/ir/c_ir/model.py +318 -0
  60. pycforge/converter/ir/c_ir/serialization.py +88 -0
  61. pycforge/converter/ir/c_ir/validation.py +834 -0
  62. pycforge/converter/ir/python_ir/__init__.py +17 -0
  63. pycforge/converter/ir/python_ir/nodes.py +86 -0
  64. pycforge/converter/keyword_calls/__init__.py +68 -0
  65. pycforge/converter/keyword_calls/analysis.py +458 -0
  66. pycforge/converter/keyword_calls/lowering.py +271 -0
  67. pycforge/converter/keyword_calls/model.py +304 -0
  68. pycforge/converter/keyword_calls/validation.py +802 -0
  69. pycforge/converter/keyword_only_calls/__init__.py +68 -0
  70. pycforge/converter/keyword_only_calls/analysis.py +640 -0
  71. pycforge/converter/keyword_only_calls/lowering.py +376 -0
  72. pycforge/converter/keyword_only_calls/model.py +328 -0
  73. pycforge/converter/keyword_only_calls/validation.py +1357 -0
  74. pycforge/converter/lowering.py +1000 -0
  75. pycforge/converter/modules/__init__.py +13 -0
  76. pycforge/converter/modules/analysis.py +1250 -0
  77. pycforge/converter/modules/lowering.py +200 -0
  78. pycforge/converter/modules/model.py +73 -0
  79. pycforge/converter/modules/stage.py +192 -0
  80. pycforge/converter/numeric_semantics/__init__.py +23 -0
  81. pycforge/converter/numeric_semantics/analysis.py +420 -0
  82. pycforge/converter/numeric_semantics/lowering.py +153 -0
  83. pycforge/converter/numeric_semantics/model.py +123 -0
  84. pycforge/converter/records/__init__.py +34 -0
  85. pycforge/converter/records/analysis.py +1394 -0
  86. pycforge/converter/records/lowering.py +393 -0
  87. pycforge/converter/records/model.py +319 -0
  88. pycforge/converter/rules/__init__.py +3 -0
  89. pycforge/converter/support_templates/__init__.py +49 -0
  90. pycforge/converter/support_templates/assembly.py +106 -0
  91. pycforge/converter/support_templates/factories.py +348 -0
  92. pycforge/converter/support_templates/model.py +159 -0
  93. pycforge/converter/support_templates/registry.py +388 -0
  94. pycforge/converter/telemetry/__init__.py +0 -0
  95. pycforge/converter/telemetry/sink.py +39 -0
  96. pycforge/ide/__init__.py +19 -0
  97. pycforge/ide/__main__.py +5 -0
  98. pycforge/ide/_worker_event_codec.py +276 -0
  99. pycforge/ide/_worker_protocol_json.py +197 -0
  100. pycforge/ide/_worker_protocol_types.py +90 -0
  101. pycforge/ide/_worker_request_codec.py +200 -0
  102. pycforge/ide/_worker_request_data.py +260 -0
  103. pycforge/ide/_worker_result_data.py +343 -0
  104. pycforge/ide/action_contract.py +469 -0
  105. pycforge/ide/action_validation.py +229 -0
  106. pycforge/ide/command_palette.py +223 -0
  107. pycforge/ide/controller.py +904 -0
  108. pycforge/ide/controller_conversion.py +546 -0
  109. pycforge/ide/controller_io.py +205 -0
  110. pycforge/ide/editor.py +951 -0
  111. pycforge/ide/editor_commands_qt.py +274 -0
  112. pycforge/ide/editor_lexical.py +43 -0
  113. pycforge/ide/editor_sidebars.py +236 -0
  114. pycforge/ide/editor_syntax.py +243 -0
  115. pycforge/ide/find_replace.py +535 -0
  116. pycforge/ide/icons.py +91 -0
  117. pycforge/ide/io_service.py +196 -0
  118. pycforge/ide/model.py +164 -0
  119. pycforge/ide/panels.py +903 -0
  120. pycforge/ide/positions.py +220 -0
  121. pycforge/ide/process_worker.py +130 -0
  122. pycforge/ide/qt.py +230 -0
  123. pycforge/ide/qt_actions.py +418 -0
  124. pycforge/ide/qt_close.py +169 -0
  125. pycforge/ide/qt_command_palette.py +297 -0
  126. pycforge/ide/qt_contract.py +220 -0
  127. pycforge/ide/qt_documents.py +590 -0
  128. pycforge/ide/qt_editor_buffers.py +113 -0
  129. pycforge/ide/qt_editor_surfaces.py +112 -0
  130. pycforge/ide/qt_menus.py +324 -0
  131. pycforge/ide/qt_projection.py +500 -0
  132. pycforge/ide/qt_shell.py +348 -0
  133. pycforge/ide/qt_shell_interactions.py +320 -0
  134. pycforge/ide/qt_state.py +393 -0
  135. pycforge/ide/qt_workspace_features.py +398 -0
  136. pycforge/ide/qt_workspace_navigation.py +208 -0
  137. pycforge/ide/qt_workspace_observers.py +173 -0
  138. pycforge/ide/qt_workspace_panels.py +545 -0
  139. pycforge/ide/qt_workspace_widgets.py +228 -0
  140. pycforge/ide/resources/icons/about.svg +1 -0
  141. pycforge/ide/resources/icons/add-document.svg +1 -0
  142. pycforge/ide/resources/icons/brand-mark.svg +1 -0
  143. pycforge/ide/resources/icons/bundle-search.svg +1 -0
  144. pycforge/ide/resources/icons/cancel.svg +1 -0
  145. pycforge/ide/resources/icons/check.svg +1 -0
  146. pycforge/ide/resources/icons/chevron-right.svg +1 -0
  147. pycforge/ide/resources/icons/close.svg +1 -0
  148. pycforge/ide/resources/icons/collapse-all.svg +1 -0
  149. pycforge/ide/resources/icons/command-palette.svg +1 -0
  150. pycforge/ide/resources/icons/convert.svg +1 -0
  151. pycforge/ide/resources/icons/copy.svg +1 -0
  152. pycforge/ide/resources/icons/cut.svg +1 -0
  153. pycforge/ide/resources/icons/decision-trace.svg +1 -0
  154. pycforge/ide/resources/icons/details.svg +1 -0
  155. pycforge/ide/resources/icons/diagnostics.svg +1 -0
  156. pycforge/ide/resources/icons/duplicate-line.svg +1 -0
  157. pycforge/ide/resources/icons/exit.svg +1 -0
  158. pycforge/ide/resources/icons/expand-all.svg +1 -0
  159. pycforge/ide/resources/icons/export.svg +1 -0
  160. pycforge/ide/resources/icons/find.svg +1 -0
  161. pycforge/ide/resources/icons/go-to-line.svg +1 -0
  162. pycforge/ide/resources/icons/go-to-output.svg +1 -0
  163. pycforge/ide/resources/icons/go-to-source.svg +1 -0
  164. pycforge/ide/resources/icons/history.svg +1 -0
  165. pycforge/ide/resources/icons/indent.svg +1 -0
  166. pycforge/ide/resources/icons/link-c.svg +1 -0
  167. pycforge/ide/resources/icons/mappings.svg +1 -0
  168. pycforge/ide/resources/icons/module.svg +1 -0
  169. pycforge/ide/resources/icons/move-down.svg +1 -0
  170. pycforge/ide/resources/icons/move-line-down.svg +1 -0
  171. pycforge/ide/resources/icons/move-line-up.svg +1 -0
  172. pycforge/ide/resources/icons/move-up.svg +1 -0
  173. pycforge/ide/resources/icons/next.svg +1 -0
  174. pycforge/ide/resources/icons/open.svg +1 -0
  175. pycforge/ide/resources/icons/outdent.svg +1 -0
  176. pycforge/ide/resources/icons/outline.svg +1 -0
  177. pycforge/ide/resources/icons/paste.svg +1 -0
  178. pycforge/ide/resources/icons/previous.svg +1 -0
  179. pycforge/ide/resources/icons/primary-module.svg +1 -0
  180. pycforge/ide/resources/icons/redo.svg +1 -0
  181. pycforge/ide/resources/icons/remove-document.svg +1 -0
  182. pycforge/ide/resources/icons/replace.svg +1 -0
  183. pycforge/ide/resources/icons/save-as.svg +1 -0
  184. pycforge/ide/resources/icons/save.svg +1 -0
  185. pycforge/ide/resources/icons/select-all.svg +1 -0
  186. pycforge/ide/resources/icons/settings.svg +1 -0
  187. pycforge/ide/resources/icons/show-c.svg +1 -0
  188. pycforge/ide/resources/icons/split-view.svg +1 -0
  189. pycforge/ide/resources/icons/summary.svg +1 -0
  190. pycforge/ide/resources/icons/telemetry.svg +1 -0
  191. pycforge/ide/resources/icons/toggle-comment.svg +1 -0
  192. pycforge/ide/resources/icons/toggle-fold.svg +1 -0
  193. pycforge/ide/resources/icons/undo.svg +1 -0
  194. pycforge/ide/resources/icons/whitespace.svg +1 -0
  195. pycforge/ide/revisions.py +400 -0
  196. pycforge/ide/search_service.py +280 -0
  197. pycforge/ide/session_history.py +150 -0
  198. pycforge/ide/source_editing.py +417 -0
  199. pycforge/ide/source_structure.py +558 -0
  200. pycforge/ide/source_structure_async.py +191 -0
  201. pycforge/ide/supervisor.py +503 -0
  202. pycforge/ide/theme.py +119 -0
  203. pycforge/ide/theme_stylesheet.py +598 -0
  204. pycforge/ide/theme_workspace_stylesheet.py +155 -0
  205. pycforge/ide/visual_tokens.py +142 -0
  206. pycforge/ide/worker_protocol.py +80 -0
  207. pycforge/ide/workspace_search.py +462 -0
  208. pycforge/ide/workspace_session.py +256 -0
  209. pycforge/laboratory/__init__.py +6 -0
  210. pycforge/laboratory/audits.py +2244 -0
  211. pycforge/laboratory/checkpoint_e.py +2685 -0
  212. pycforge/laboratory/cli.py +119 -0
  213. pycforge/laboratory/exit_codes.py +11 -0
  214. pycforge/laboratory/keyword_audit.py +661 -0
  215. pycforge/laboratory/keyword_only_audit.py +481 -0
  216. pycforge-0.15.2.dist-info/METADATA +209 -0
  217. pycforge-0.15.2.dist-info/RECORD +221 -0
  218. pycforge-0.15.2.dist-info/WHEEL +5 -0
  219. pycforge-0.15.2.dist-info/entry_points.txt +5 -0
  220. pycforge-0.15.2.dist-info/licenses/LICENSE +674 -0
  221. pycforge-0.15.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,71 @@
1
+ """Current public and StableInternal contract identities.
2
+
3
+ Keeping active identities in one data-only module prevents the pipeline,
4
+ serialization, CLI, and observers from silently publishing different phases.
5
+ Historical identities remain beside their historical readers.
6
+ """
7
+
8
+ SOURCE_BUNDLE_SCHEMA = "source-bundle/0.2"
9
+ PYTHON_IR_BUNDLE_SCHEMA = "python-ir/0.4"
10
+
11
+ # The install/package version may advance for hardening or distribution work
12
+ # without changing deterministic conversion records. This identity advances
13
+ # only when the active converter semantics or serialized contracts advance.
14
+ CONVERTER_CONTRACT_VERSION = "0.14.3"
15
+
16
+ # Phase 12 readers and explicit historical requests keep exact identities.
17
+ PHASE12_CONVERSION_PLAN_SCHEMA = "conversion-plan/0.12"
18
+ PHASE12_C_IR_SCHEMA = "c-ir/0.12"
19
+ PHASE12_GENERATED_C_SCHEMA = "generated-c/0.12"
20
+ PHASE12_CONVERSION_SUMMARY_SCHEMA = "pycforge.conversion-summary/0.12"
21
+ PHASE12_DECISION_TRACE_SCHEMA = "pycforge.decision-trace/0.12"
22
+
23
+ PHASE13_CONVERSION_PLAN_SCHEMA = "conversion-plan/0.13"
24
+ PHASE13_C_IR_SCHEMA = "c-ir/0.13"
25
+ PHASE13_GENERATED_C_SCHEMA = "generated-c/0.13"
26
+ PHASE13_CONVERSION_SUMMARY_SCHEMA = "pycforge.conversion-summary/0.13"
27
+ PHASE13_DECISION_TRACE_SCHEMA = "pycforge.decision-trace/0.13"
28
+
29
+ # Phase 14A readers and explicit historical requests keep exact identities.
30
+ PHASE14A_CONVERSION_PLAN_SCHEMA = "conversion-plan/0.14"
31
+ PHASE14A_C_IR_SCHEMA = "c-ir/0.14"
32
+ PHASE14A_GENERATED_C_SCHEMA = "generated-c/0.14"
33
+ PHASE14A_CONVERSION_SUMMARY_SCHEMA = "pycforge.conversion-summary/0.14"
34
+ PHASE14A_DECISION_TRACE_SCHEMA = "pycforge.decision-trace/0.14"
35
+ PHASE14_CONVERSION_PLAN_SCHEMA = PHASE14A_CONVERSION_PLAN_SCHEMA
36
+ PHASE14_C_IR_SCHEMA = PHASE14A_C_IR_SCHEMA
37
+ PHASE14_GENERATED_C_SCHEMA = PHASE14A_GENERATED_C_SCHEMA
38
+ PHASE14_CONVERSION_SUMMARY_SCHEMA = PHASE14A_CONVERSION_SUMMARY_SCHEMA
39
+ PHASE14_DECISION_TRACE_SCHEMA = PHASE14A_DECISION_TRACE_SCHEMA
40
+
41
+ PHASE14B_CONVERSION_PLAN_SCHEMA = "conversion-plan/0.14.1"
42
+ PHASE14B_C_IR_SCHEMA = "c-ir/0.14.1"
43
+ PHASE14B_GENERATED_C_SCHEMA = "generated-c/0.14.1"
44
+ PHASE14B_CONVERSION_SUMMARY_SCHEMA = "pycforge.conversion-summary/0.14.1"
45
+ PHASE14B_DECISION_TRACE_SCHEMA = "pycforge.decision-trace/0.14.1"
46
+
47
+ # Phase 14C readers and explicit historical requests keep exact identities.
48
+ PHASE14C_CONVERSION_PLAN_SCHEMA = "conversion-plan/0.14.2"
49
+ PHASE14C_C_IR_SCHEMA = "c-ir/0.14.2"
50
+ PHASE14C_GENERATED_C_SCHEMA = "generated-c/0.14.2"
51
+ PHASE14C_CONVERSION_SUMMARY_SCHEMA = "pycforge.conversion-summary/0.14.2"
52
+ PHASE14C_DECISION_TRACE_SCHEMA = "pycforge.decision-trace/0.14.2"
53
+
54
+ CONVERSION_PLAN_SCHEMA = "conversion-plan/0.14.3"
55
+ C_IR_SCHEMA = "c-ir/0.14.3"
56
+ GENERATED_C_SCHEMA = "generated-c/0.14.3"
57
+ CONVERSION_SUMMARY_SCHEMA = "pycforge.conversion-summary/0.14.3"
58
+ DECISION_TRACE_SCHEMA = "pycforge.decision-trace/0.14.3"
59
+
60
+ # The result envelope shape is unchanged. Its nested summary and trace carry
61
+ # their own bumped schema identities, so result serialization remains 0.5.
62
+ RESULT_SCHEMA_VERSION = "0.5"
63
+ CONTAINER_FACT_SCHEMA = "fact-table/0.11"
64
+ MODULE_FACT_SCHEMA = "fact-table/0.12"
65
+ RECORD_FACT_SCHEMA = "fact-table/0.13"
66
+ NUMERIC_FACT_SCHEMA = "fact-table/0.14"
67
+ CONDITIONAL_FACT_SCHEMA = "fact-table/0.14.1"
68
+ CONDITIONAL_REGION_FACT_SCHEMA = CONDITIONAL_FACT_SCHEMA
69
+ PHASE14B_CONDITIONAL_FACT_SCHEMA = CONDITIONAL_FACT_SCHEMA
70
+ KEYWORD_CALL_FACT_SCHEMA = "fact-table/0.14.2"
71
+ KEYWORD_ONLY_CALL_FACT_SCHEMA = "fact-table/0.14.3"
File without changes
@@ -0,0 +1,87 @@
1
+ from __future__ import annotations
2
+ import json
3
+ import re
4
+ from types import MappingProxyType
5
+ from pathlib import Path
6
+ from typing import Any
7
+ from .fingerprint import Fingerprint, fingerprint
8
+ from .stage_artifact import StageArtifact
9
+
10
+ ARTIFACT_ENVELOPE_VERSION = "0.2"
11
+
12
+ class ArtifactCompatibilityError(ValueError):
13
+ pass
14
+
15
+ _FINGERPRINT_FIELDS = {"domain", "schema_version", "canonicalization_version", "algorithm", "value"}
16
+ _SHA256 = re.compile(r"^[0-9a-f]{64}$")
17
+
18
+ def _fp_from_dict(value: object, *, required: bool, role: str) -> Fingerprint | None:
19
+ if value is None:
20
+ if required:
21
+ raise ArtifactCompatibilityError(f"PYC3103 missing {role} fingerprint")
22
+ return None
23
+ if not isinstance(value, dict) or set(value) != _FINGERPRINT_FIELDS or not all(isinstance(item, str) for item in value.values()):
24
+ raise ArtifactCompatibilityError(f"PYC3103 malformed {role} fingerprint")
25
+ result = Fingerprint(**value)
26
+ if result.domain != "stage-artifact" or result.schema_version != "0.1" or result.canonicalization_version != "canonical-json-v1" or result.algorithm != "sha256" or not _SHA256.fullmatch(result.value):
27
+ raise ArtifactCompatibilityError(f"PYC3103 incompatible {role} fingerprint metadata")
28
+ return result
29
+
30
+ def artifact_to_dict(artifact: StageArtifact) -> dict[str, Any]:
31
+ payload = {key: list(value) if isinstance(value, tuple) else value for key, value in artifact.payload.items()}
32
+ return {
33
+ "envelope_version": ARTIFACT_ENVELOPE_VERSION,
34
+ "kind": artifact.kind,
35
+ "schema_version": artifact.schema_version,
36
+ "conversion_id": artifact.conversion_id,
37
+ "parent_fingerprint": None if artifact.parent_fingerprint is None else artifact.parent_fingerprint.to_dict(),
38
+ "payload": payload,
39
+ "artifact_fingerprint": artifact.artifact_fingerprint.to_dict(),
40
+ }
41
+
42
+ def artifact_from_dict(data: dict[str, Any], *, accepted: set[tuple[str, str]] | None = None) -> StageArtifact:
43
+ if data.get("envelope_version") != ARTIFACT_ENVELOPE_VERSION:
44
+ raise ArtifactCompatibilityError("PYC3101 incompatible artifact envelope version")
45
+ required = {"kind", "schema_version", "conversion_id", "parent_fingerprint", "payload", "artifact_fingerprint"}
46
+ if not required.issubset(data):
47
+ raise ArtifactCompatibilityError("PYC3103 incomplete artifact envelope")
48
+ if set(data) != required | {"envelope_version"}:
49
+ raise ArtifactCompatibilityError("PYC3103 artifact envelope contains unknown fields")
50
+ if not all(isinstance(data.get(key), str) and data.get(key) for key in ("kind", "schema_version", "conversion_id")):
51
+ raise ArtifactCompatibilityError("PYC3103 invalid artifact identity")
52
+ pair = (data["kind"], data["schema_version"])
53
+ if accepted is not None and pair not in accepted:
54
+ raise ArtifactCompatibilityError("PYC3102 incompatible artifact kind or schema")
55
+ raw_payload = data["payload"]
56
+ if not isinstance(raw_payload, dict):
57
+ raise ArtifactCompatibilityError("PYC3104 artifact payload must be an object")
58
+ payload = dict(raw_payload)
59
+ if isinstance(payload.get("stage_order"), list):
60
+ payload["stage_order"] = tuple(payload["stage_order"])
61
+ is_initial = data["kind"] == "initial"
62
+ parent = _fp_from_dict(data["parent_fingerprint"], required=not is_initial, role="parent")
63
+ artifact_fingerprint = _fp_from_dict(data["artifact_fingerprint"], required=True, role="artifact")
64
+ if is_initial and parent is not None:
65
+ raise ArtifactCompatibilityError("PYC3103 initial artifact cannot have a parent fingerprint")
66
+ try:
67
+ artifact = StageArtifact(str(data["kind"]), str(data["schema_version"]), str(data["conversion_id"]), parent, MappingProxyType(payload), artifact_fingerprint)
68
+ except (TypeError, ValueError) as exc:
69
+ raise ArtifactCompatibilityError("PYC3105 artifact fingerprint mismatch") from exc
70
+ expected = fingerprint("stage-artifact", {"kind": artifact.kind, "conversion_id": artifact.conversion_id, "parent": None if artifact.parent_fingerprint is None else artifact.parent_fingerprint.value, "payload": {key: list(value) if isinstance(value, tuple) else value for key, value in artifact.payload.items()}})
71
+ if artifact.kind == "initial":
72
+ expected = fingerprint("stage-artifact", {"kind":"initial","conversion_id":artifact.conversion_id,"payload":{"stage_order":list(artifact.payload.get("stage_order",()))}})
73
+ if expected != artifact.artifact_fingerprint:
74
+ raise ArtifactCompatibilityError("PYC3105 artifact fingerprint mismatch")
75
+ return artifact
76
+
77
+ def save_artifact(path: Path, artifact: StageArtifact, writer: Any) -> None:
78
+ writer.write_text(path, json.dumps(artifact_to_dict(artifact), sort_keys=True, separators=(",", ":"), ensure_ascii=False, allow_nan=False) + "\n")
79
+
80
+ def load_artifact(path: Path, *, accepted: set[tuple[str, str]] | None = None) -> StageArtifact:
81
+ try:
82
+ data = json.loads(path.read_text(encoding="utf-8"))
83
+ except (OSError, UnicodeError, json.JSONDecodeError) as exc:
84
+ raise ArtifactCompatibilityError("PYC3100 unreadable artifact") from exc
85
+ if not isinstance(data, dict):
86
+ raise ArtifactCompatibilityError("PYC3103 artifact envelope must be an object")
87
+ return artifact_from_dict(data, accepted=accepted)
@@ -0,0 +1,7 @@
1
+ from __future__ import annotations
2
+ from threading import Event
3
+ class CancellationToken:
4
+ def __init__(self)->None: self._event=Event()
5
+ def cancel(self)->None: self._event.set()
6
+ @property
7
+ def is_canceled(self)->bool: return self._event.is_set()
@@ -0,0 +1,254 @@
1
+ from __future__ import annotations
2
+
3
+ import re
4
+ from dataclasses import dataclass
5
+ from pathlib import PurePosixPath
6
+
7
+ from pycforge.converter.contracts.configuration import (
8
+ COMPATIBLE_RENDERERS_BY_RULE_SET,
9
+ DEFAULT_TARGET_CONTRACT,
10
+ MAX_SOURCE_DOCUMENTS,
11
+ SUPPORTED_CONTAINER_POLICIES,
12
+ SUPPORTED_HELPER_POLICIES,
13
+ SUPPORTED_MODULE_POLICIES,
14
+ SUPPORTED_NUMERIC_POLICIES,
15
+ SUPPORTED_RECORD_POLICIES,
16
+ SUPPORTED_RENDERERS,
17
+ SUPPORTED_RULE_SETS,
18
+ SUPPORTED_SEMANTIC_POLICIES,
19
+ SUPPORTED_TARGET_CONTRACTS,
20
+ supports_modules,
21
+ supports_numeric,
22
+ supports_records,
23
+ )
24
+
25
+ from .diagnostics import Diagnostic
26
+ from .enums import Severity
27
+ from .fingerprint import Fingerprint, fingerprint
28
+ from .request import ConversionRequest, SourceBundle, SourceDocumentInput
29
+ from .resource_policy import ResourcePolicy
30
+
31
+
32
+ _MODULE_SEGMENT = re.compile(r"^[a-z][a-z0-9_]{0,62}$")
33
+
34
+
35
+ @dataclass(frozen=True, slots=True)
36
+ class CanonicalRequest:
37
+ request: ConversionRequest
38
+ request_fingerprint: Fingerprint
39
+ resource_fingerprint: Fingerprint
40
+
41
+ def semantic_dict(self) -> dict[str, object]:
42
+ request = self.request
43
+ documents = (request.source_bundle.primary,) + request.source_bundle.companions
44
+ return {
45
+ "source_bundle": {
46
+ "schema_version": "source-bundle/0.2" if supports_modules(request.rule_set_version) else "source-bundle/0.1",
47
+ "primary": _document_dict(documents[0]),
48
+ "companions": [_document_dict(item) for item in documents[1:]],
49
+ },
50
+ "python_version": request.python_version,
51
+ "target_contract": request.target_contract,
52
+ "semantic_policy": request.semantic_policy,
53
+ "approximation_allowlist": list(request.approximation_allowlist),
54
+ "rule_set_version": request.rule_set_version,
55
+ "renderer_version": request.renderer_version,
56
+ "helper_policy_version": request.helper_policy_version,
57
+ "container_policy_version": request.container_policy_version,
58
+ "module_policy_version": request.module_policy_version,
59
+ **(
60
+ {"record_policy_version": request.record_policy_version}
61
+ if supports_records(request.rule_set_version)
62
+ else {}
63
+ ),
64
+ **(
65
+ {"numeric_policy_version": request.numeric_policy_version}
66
+ if supports_numeric(request.rule_set_version)
67
+ else {}
68
+ ),
69
+ "resource_policy": request.resource_policy.to_dict(),
70
+ }
71
+
72
+
73
+ def _document_dict(document: SourceDocumentInput) -> dict[str, object]:
74
+ return {
75
+ "logical_name": document.logical_name,
76
+ "module_id": document.module_id,
77
+ "text": document.text,
78
+ }
79
+
80
+
81
+ def _valid_logical_name(value: object) -> bool:
82
+ if not isinstance(value, str) or not value:
83
+ return False
84
+ try:
85
+ value.encode("utf-8")
86
+ except UnicodeEncodeError:
87
+ return False
88
+ path = PurePosixPath(value)
89
+ return bool(
90
+ path.parts
91
+ and path.as_posix() == value
92
+ and not value.startswith("/")
93
+ and "\\" not in value
94
+ and ".." not in path.parts
95
+ and not any(ord(character) < 32 for character in value)
96
+ )
97
+
98
+
99
+ def _valid_module_id(value: object) -> bool:
100
+ if not isinstance(value, str) or not value:
101
+ return False
102
+ try:
103
+ encoded = value.encode("utf-8")
104
+ except UnicodeEncodeError:
105
+ return False
106
+ parts = value.split(".")
107
+ return bool(
108
+ len(encoded) <= 255
109
+ and 1 <= len(parts) <= 16
110
+ and all(_MODULE_SEGMENT.fullmatch(part) for part in parts)
111
+ )
112
+
113
+
114
+ def canonicalize(request: ConversionRequest) -> tuple[CanonicalRequest | None, tuple[Diagnostic, ...]]:
115
+ errors: list[Diagnostic] = []
116
+ if not isinstance(request, ConversionRequest):
117
+ return None, (Diagnostic("PYC1000", Severity.ERROR, "request", "Request must be ConversionRequest"),)
118
+ if not isinstance(request.source_bundle, SourceBundle) or not isinstance(request.source_bundle.primary, SourceDocumentInput):
119
+ return None, (Diagnostic("PYC1000", Severity.ERROR, "request", "Request must contain a SourceBundle with one primary SourceDocumentInput"),)
120
+ if not isinstance(request.resource_policy, ResourcePolicy):
121
+ return None, (Diagnostic("PYC1005", Severity.ERROR, "request", "resource_policy must be ResourcePolicy"),)
122
+
123
+ policy_errors = request.resource_policy.validate()
124
+ errors.extend(Diagnostic("PYC1005", Severity.ERROR, "request", message) for message in policy_errors)
125
+
126
+ companions = request.source_bundle.companions
127
+ if not isinstance(companions, (tuple, list)) or any(not isinstance(item, SourceDocumentInput) for item in companions):
128
+ errors.append(Diagnostic("PYC1007", Severity.ERROR, "request", "Companion source documents must be SourceDocumentInput values"))
129
+ documents: tuple[SourceDocumentInput, ...] = (request.source_bundle.primary,)
130
+ else:
131
+ documents = (request.source_bundle.primary,) + tuple(companions)
132
+
133
+ modules_enabled = isinstance(request.rule_set_version, str) and supports_modules(request.rule_set_version)
134
+ if not modules_enabled and len(documents) > 1:
135
+ errors.append(Diagnostic("PYC1007", Severity.ERROR, "request", "Companion source documents require a module-bundle rule set"))
136
+ configured_document_limit = request.resource_policy.max_source_documents
137
+ valid_document_limit = isinstance(configured_document_limit, int) and not isinstance(configured_document_limit, bool) and configured_document_limit > 0
138
+ document_limit = min(configured_document_limit, MAX_SOURCE_DOCUMENTS) if valid_document_limit else None
139
+ if modules_enabled and document_limit is not None and len(documents) > document_limit:
140
+ errors.append(Diagnostic("PYC3510", Severity.ERROR, "request", "SourceBundle exceeds the closed 64-document or configured document ceiling"))
141
+
142
+ total_bytes = 0
143
+ normalized_documents: list[SourceDocumentInput] = []
144
+ for ordinal, document in enumerate(documents):
145
+ role = "Primary" if ordinal == 0 else "Companion"
146
+ if not _valid_logical_name(document.logical_name):
147
+ errors.append(Diagnostic("PYC3501" if modules_enabled else "PYC1001", Severity.ERROR, "request", f"{role} logical name must be a canonical non-empty relative logical path"))
148
+ if modules_enabled and not _valid_module_id(document.module_id):
149
+ errors.append(Diagnostic("PYC3501", Severity.ERROR, "request", f"{role} module ID must be an exact canonical lowercase dotted logical identifier"))
150
+ if not isinstance(document.text, str):
151
+ errors.append(Diagnostic("PYC1002", Severity.ERROR, "request", f"{role} source must be decoded text"))
152
+ continue
153
+ try:
154
+ encoded = document.text.encode("utf-8")
155
+ except UnicodeEncodeError:
156
+ errors.append(Diagnostic("PYC1002", Severity.ERROR, "request", f"{role} source must be valid Unicode encodable as UTF-8"))
157
+ continue
158
+ total_bytes += len(encoded)
159
+ normalized_documents.append(SourceDocumentInput(document.logical_name, document.text, document.module_id))
160
+
161
+ if modules_enabled:
162
+ module_ids = [item.module_id for item in documents if isinstance(item.module_id, str)]
163
+ logical_names = [item.logical_name for item in documents if isinstance(item.logical_name, str)]
164
+ if len(module_ids) != len(set(module_ids)) or len(logical_names) != len(set(logical_names)):
165
+ errors.append(Diagnostic("PYC3502", Severity.ERROR, "request", "SourceBundle logical module IDs and logical source names must each be unique"))
166
+ source_byte_limit = request.resource_policy.max_source_bytes
167
+ valid_source_byte_limit = isinstance(source_byte_limit, int) and not isinstance(source_byte_limit, bool) and source_byte_limit >= 0
168
+ if valid_source_byte_limit and total_bytes > source_byte_limit:
169
+ code = "PYC3510" if modules_enabled else "PYC1003"
170
+ errors.append(Diagnostic(code, Severity.ERROR, "request", "SourceBundle exceeds max_source_bytes" if modules_enabled else "Primary source exceeds max_source_bytes"))
171
+
172
+ if request.python_version != "3.11":
173
+ errors.append(Diagnostic("PYC1004", Severity.ERROR, "request", "Unsupported Python grammar version"))
174
+
175
+ allowlist = request.approximation_allowlist
176
+ if not isinstance(allowlist, (tuple, list)) or any(not isinstance(item, str) for item in allowlist):
177
+ errors.append(Diagnostic("PYC1006", Severity.ERROR, "request", "Approximation allowlist must be an ordered collection of string codes"))
178
+ normalized_allowlist: tuple[str, ...] = ()
179
+ else:
180
+ normalized_allowlist = tuple(sorted(allowlist))
181
+ if len(set(allowlist)) != len(allowlist):
182
+ errors.append(Diagnostic("PYC1006", Severity.ERROR, "request", "Approximation allowlist contains duplicates"))
183
+
184
+ checks = (
185
+ (request.target_contract, SUPPORTED_TARGET_CONTRACTS, "PYC1008", "Unsupported Target C Source Contract"),
186
+ (request.semantic_policy, SUPPORTED_SEMANTIC_POLICIES, "PYC1009", "Unsupported conversion semantic policy"),
187
+ (request.rule_set_version, SUPPORTED_RULE_SETS, "PYC1010", "Unsupported conversion rule-set version"),
188
+ (request.renderer_version, SUPPORTED_RENDERERS, "PYC1011", "Unsupported C renderer version"),
189
+ (request.helper_policy_version, SUPPORTED_HELPER_POLICIES, "PYC1014", "Unsupported helper policy version"),
190
+ (request.container_policy_version, SUPPORTED_CONTAINER_POLICIES, "PYC1015", "Unsupported container policy version"),
191
+ (request.module_policy_version, SUPPORTED_MODULE_POLICIES, "PYC1016", "Unsupported module policy version"),
192
+ (request.record_policy_version, SUPPORTED_RECORD_POLICIES, "PYC1017", "Unsupported record policy version"),
193
+ (request.numeric_policy_version, SUPPORTED_NUMERIC_POLICIES, "PYC1018", "Unsupported numeric policy version"),
194
+ )
195
+ for value, supported, code, message in checks:
196
+ if not isinstance(value, str) or value not in supported:
197
+ errors.append(Diagnostic(code, Severity.ERROR, "request", message))
198
+ if (
199
+ request.rule_set_version in SUPPORTED_RULE_SETS
200
+ and request.renderer_version in SUPPORTED_RENDERERS
201
+ and request.renderer_version
202
+ not in COMPATIBLE_RENDERERS_BY_RULE_SET.get(
203
+ request.rule_set_version,
204
+ frozenset(),
205
+ )
206
+ ):
207
+ errors.append(Diagnostic(
208
+ "PYC1011",
209
+ Severity.ERROR,
210
+ "request",
211
+ "C renderer version is incompatible with selected rule-set version",
212
+ ))
213
+ if (
214
+ isinstance(request.rule_set_version, str)
215
+ and supports_numeric(request.rule_set_version)
216
+ and request.target_contract in SUPPORTED_TARGET_CONTRACTS
217
+ and request.target_contract != DEFAULT_TARGET_CONTRACT
218
+ ):
219
+ errors.append(Diagnostic(
220
+ "PYC1008",
221
+ Severity.ERROR,
222
+ "request",
223
+ "Phase 14 bounded numeric rules require the exact c11-portable-fixed-v1 target contract",
224
+ ))
225
+
226
+ if errors:
227
+ return None, tuple(errors)
228
+ if len(normalized_documents) != len(documents):
229
+ return None, (Diagnostic("PYC1000", Severity.ERROR, "request", "SourceBundle could not be canonicalized"),)
230
+
231
+ bundle = SourceBundle(normalized_documents[0], tuple(normalized_documents[1:]))
232
+ normalized = ConversionRequest(
233
+ source_bundle=bundle,
234
+ python_version=request.python_version,
235
+ target_contract=request.target_contract,
236
+ semantic_policy=request.semantic_policy,
237
+ approximation_allowlist=normalized_allowlist,
238
+ rule_set_version=request.rule_set_version,
239
+ renderer_version=request.renderer_version,
240
+ helper_policy_version=request.helper_policy_version,
241
+ container_policy_version=request.container_policy_version,
242
+ resource_policy=request.resource_policy,
243
+ module_policy_version=request.module_policy_version,
244
+ record_policy_version=request.record_policy_version,
245
+ numeric_policy_version=request.numeric_policy_version,
246
+ )
247
+ placeholder = fingerprint("canonicalization-placeholder", {})
248
+ temporary = CanonicalRequest(normalized, placeholder, placeholder)
249
+ semantic = temporary.semantic_dict()
250
+ return CanonicalRequest(
251
+ normalized,
252
+ fingerprint("conversion-request", semantic),
253
+ fingerprint("resource-policy", normalized.resource_policy.to_dict()),
254
+ ), ()
@@ -0,0 +1,13 @@
1
+ from __future__ import annotations
2
+ from dataclasses import dataclass
3
+ from .canonicalization import CanonicalRequest
4
+ from .diagnostics import DiagnosticCollector
5
+ from .cancellation import CancellationToken
6
+ @dataclass(slots=True)
7
+ class ConversionContext:
8
+ canonical: CanonicalRequest
9
+ diagnostics: DiagnosticCollector
10
+ cancellation: CancellationToken
11
+ frontend_tree: object|None = None
12
+ frontend_documents: tuple[object, ...] = ()
13
+ frontend_trees: tuple[object, ...] = ()
@@ -0,0 +1,95 @@
1
+ from __future__ import annotations
2
+ import hashlib
3
+ import json
4
+ from dataclasses import dataclass
5
+ from threading import Lock
6
+ from .enums import Severity
7
+ from .stage_artifact import freeze_value
8
+
9
+ @dataclass(frozen=True, slots=True)
10
+ class Diagnostic:
11
+ code: str
12
+ severity: Severity
13
+ stage: str
14
+ message: str
15
+ effect_on_status: bool = True
16
+ source_span: dict[str, object]|None = None
17
+ related_spans: tuple[dict[str, object], ...] = ()
18
+ causal_diagnostic_id: str | None = None
19
+ target_contract: str | None = None
20
+ semantic_policy: str | None = None
21
+ rule_id: str | None = None
22
+ fact_references: tuple[str, ...] = ()
23
+ obligation_references: tuple[str, ...] = ()
24
+ explanation: str | None = None
25
+ remediation: str | None = None
26
+ approximation_code: str | None = None
27
+ semantic_delta: str | None = None
28
+ source_module_id: str | None = None
29
+ source_logical_name: str | None = None
30
+
31
+ def __post_init__(self) -> None:
32
+ if self.source_span is not None:
33
+ object.__setattr__(self, "source_span", freeze_value(self.source_span))
34
+ object.__setattr__(self, "related_spans", tuple(freeze_value(item) for item in self.related_spans))
35
+ object.__setattr__(self, "fact_references", tuple(self.fact_references))
36
+ object.__setattr__(self, "obligation_references", tuple(self.obligation_references))
37
+
38
+ @property
39
+ def diagnostic_id(self) -> str:
40
+ identity = {
41
+ "code": self.code,
42
+ "stage": self.stage,
43
+ "message": self.message,
44
+ "source_span": self.source_span,
45
+ "rule_id": self.rule_id,
46
+ "cause": self.causal_diagnostic_id,
47
+ }
48
+ raw = json.dumps(identity, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode("utf-8")
49
+ return "diag-" + hashlib.sha256(raw).hexdigest()[:20]
50
+
51
+ def to_dict(self) -> dict[str, object]:
52
+ return {
53
+ "diagnostic_id": self.diagnostic_id,
54
+ "code": self.code,
55
+ "severity": self.severity.value,
56
+ "stage": self.stage,
57
+ "message": self.message,
58
+ "effect_on_status": self.effect_on_status,
59
+ "source_span": self.source_span,
60
+ "related_spans": list(self.related_spans),
61
+ "causal_diagnostic_id": self.causal_diagnostic_id,
62
+ "target_contract": self.target_contract,
63
+ "semantic_policy": self.semantic_policy,
64
+ "rule_id": self.rule_id,
65
+ "fact_references": list(self.fact_references),
66
+ "obligation_references": list(self.obligation_references),
67
+ "explanation": self.explanation,
68
+ "remediation": self.remediation,
69
+ "approximation_code": self.approximation_code,
70
+ "semantic_delta": self.semantic_delta,
71
+ "source_module_id": self.source_module_id,
72
+ "source_logical_name": self.source_logical_name,
73
+ }
74
+
75
+ class DiagnosticCollector:
76
+ def __init__(self, limit: int, document_order: tuple[str, ...] = ()) -> None:
77
+ self._limit=limit; self._items:list[Diagnostic]=[]; self._ids:set[str]=set(); self._lock=Lock()
78
+ self._document_order={document_id:ordinal for ordinal,document_id in enumerate(document_order)}
79
+ def add(self, diagnostic: Diagnostic) -> None:
80
+ with self._lock:
81
+ if diagnostic.diagnostic_id in self._ids:
82
+ return
83
+ if len(self._items) < self._limit:
84
+ self._items.append(diagnostic)
85
+ self._ids.add(diagnostic.diagnostic_id)
86
+ def snapshot(self) -> tuple[Diagnostic, ...]:
87
+ with self._lock:
88
+ def key(diagnostic: Diagnostic) -> tuple[object, ...]:
89
+ span = diagnostic.source_span or {}
90
+ start = span.get("start", {}) if isinstance(span, dict) else {}
91
+ offset = start.get("offset") if isinstance(start, dict) else None
92
+ document_id = span.get("document_id") if isinstance(span, dict) else None
93
+ document_ordinal = -1 if document_id is None else self._document_order.get(document_id, 2**31 - 1)
94
+ return (document_ordinal, offset if isinstance(offset, int) else -1, diagnostic.stage, diagnostic.severity.value, diagnostic.code, diagnostic.diagnostic_id)
95
+ return tuple(sorted(self._items, key=key))
@@ -0,0 +1,23 @@
1
+ from __future__ import annotations
2
+ from enum import Enum
3
+
4
+ class ResultStatus(str, Enum):
5
+ CONVERTED = "Converted"
6
+ CONVERTED_WITH_WARNINGS = "ConvertedWithWarnings"
7
+ CONVERTED_WITH_APPROXIMATIONS = "ConvertedWithApproximations"
8
+ REJECTED = "Rejected"
9
+ INTERNAL_FAILURE = "InternalFailure"
10
+ CANCELED = "Canceled"
11
+
12
+ class StageTerminal(str, Enum):
13
+ COMPLETED = "Completed"
14
+ REJECTED = "Rejected"
15
+ INTERNAL_FAILURE = "InternalFailure"
16
+ CANCELED = "Canceled"
17
+
18
+ class Severity(str, Enum):
19
+ INFORMATION = "Information"
20
+ WARNING = "Warning"
21
+ APPROXIMATION = "Approximation"
22
+ ERROR = "Error"
23
+ INTERNAL_ERROR = "InternalError"
@@ -0,0 +1,22 @@
1
+ from __future__ import annotations
2
+ import hashlib, json
3
+ from dataclasses import dataclass
4
+ from typing import Any
5
+
6
+ def canonical_json(value: Any) -> bytes:
7
+ return json.dumps(value, sort_keys=True, separators=(",", ":"), ensure_ascii=False, allow_nan=False).encode("utf-8")
8
+
9
+ @dataclass(frozen=True, slots=True)
10
+ class Fingerprint:
11
+ domain: str
12
+ schema_version: str
13
+ canonicalization_version: str
14
+ algorithm: str
15
+ value: str
16
+
17
+ def to_dict(self) -> dict[str, str]:
18
+ return {"domain": self.domain, "schema_version": self.schema_version, "canonicalization_version": self.canonicalization_version, "algorithm": self.algorithm, "value": self.value}
19
+
20
+ def fingerprint(domain: str, value: Any) -> Fingerprint:
21
+ digest = hashlib.sha256(canonical_json(value)).hexdigest()
22
+ return Fingerprint(domain, "0.1", "canonical-json-v1", "sha256", digest)
@@ -0,0 +1,8 @@
1
+ from __future__ import annotations
2
+ from pycforge.converter.frontend.stages import SourceDocumentStage,ParseStage,NormalizeStage
3
+ from pycforge.converter.modules.stage import ModuleResolutionStage
4
+ from pycforge.converter.analysis.stage import AnalysisPlanningStage
5
+ from pycforge.converter.lowering import FirstSliceLoweringStage
6
+ class Pipeline:
7
+ def __init__(self,stages=None)->None:
8
+ self.stages=tuple(stages or (SourceDocumentStage(),ParseStage(),NormalizeStage(),ModuleResolutionStage(),AnalysisPlanningStage(),FirstSliceLoweringStage()))
@@ -0,0 +1,25 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+
5
+
6
+ @dataclass(frozen=True, slots=True)
7
+ class ConversionProgress:
8
+ """Observer-only progress at deterministic pipeline boundaries."""
9
+
10
+ state: str
11
+ stage_id: str | None
12
+ completed_stages: int
13
+ total_stages: int
14
+
15
+ def __post_init__(self) -> None:
16
+ if self.state not in {"pipeline-ready", "stage-entered", "stage-completed"}:
17
+ raise ValueError("unknown conversion-progress state")
18
+ if self.completed_stages < 0 or self.total_stages < 0:
19
+ raise ValueError("conversion-progress counts must be non-negative")
20
+ if self.completed_stages > self.total_stages:
21
+ raise ValueError("completed conversion stages exceed the pipeline size")
22
+ if self.state == "pipeline-ready" and self.stage_id is not None:
23
+ raise ValueError("pipeline-ready progress cannot identify an active stage")
24
+ if self.state != "pipeline-ready" and not self.stage_id:
25
+ raise ValueError("stage progress requires a stage identity")