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.
- pycforge/__init__.py +8 -0
- pycforge/__main__.py +2 -0
- pycforge/_version.py +1 -0
- pycforge/converter/__init__.py +0 -0
- pycforge/converter/analysis/__init__.py +5 -0
- pycforge/converter/analysis/functions.py +723 -0
- pycforge/converter/analysis/model.py +158 -0
- pycforge/converter/analysis/planning.py +464 -0
- pycforge/converter/analysis/stage.py +1976 -0
- pycforge/converter/analysis/symbols.py +237 -0
- pycforge/converter/analysis/validation.py +2166 -0
- pycforge/converter/c_output/__init__.py +2 -0
- pycforge/converter/c_output/conformance.py +297 -0
- pycforge/converter/c_output/renderer.py +220 -0
- pycforge/converter/conditional_regions/__init__.py +71 -0
- pycforge/converter/conditional_regions/analysis.py +481 -0
- pycforge/converter/conditional_regions/lowering.py +579 -0
- pycforge/converter/conditional_regions/model.py +243 -0
- pycforge/converter/conditional_regions/validation.py +690 -0
- pycforge/converter/containers/__init__.py +19 -0
- pycforge/converter/containers/analysis.py +542 -0
- pycforge/converter/containers/lowering.py +290 -0
- pycforge/converter/containers/model.py +146 -0
- pycforge/converter/contracts/__init__.py +0 -0
- pycforge/converter/contracts/configuration.py +178 -0
- pycforge/converter/contracts/identifiers.py +68 -0
- pycforge/converter/contracts/versions.py +71 -0
- pycforge/converter/core/__init__.py +0 -0
- pycforge/converter/core/artifact_io.py +87 -0
- pycforge/converter/core/cancellation.py +7 -0
- pycforge/converter/core/canonicalization.py +254 -0
- pycforge/converter/core/context.py +13 -0
- pycforge/converter/core/diagnostics.py +95 -0
- pycforge/converter/core/enums.py +23 -0
- pycforge/converter/core/fingerprint.py +22 -0
- pycforge/converter/core/pipeline.py +8 -0
- pycforge/converter/core/progress.py +25 -0
- pycforge/converter/core/request.py +50 -0
- pycforge/converter/core/resource_policy.py +31 -0
- pycforge/converter/core/result.py +23 -0
- pycforge/converter/core/serialization.py +36 -0
- pycforge/converter/core/stage.py +10 -0
- pycforge/converter/core/stage_artifact.py +80 -0
- pycforge/converter/core/stage_outcome.py +15 -0
- pycforge/converter/decision_trace/__init__.py +0 -0
- pycforge/converter/decision_trace/recorder.py +52 -0
- pycforge/converter/facade.py +459 -0
- pycforge/converter/frontend/__init__.py +4 -0
- pycforge/converter/frontend/normalizer.py +59 -0
- pycforge/converter/frontend/parser.py +20 -0
- pycforge/converter/frontend/source_document.py +93 -0
- pycforge/converter/frontend/stages.py +518 -0
- pycforge/converter/frontend/validation.py +76 -0
- pycforge/converter/io/__init__.py +0 -0
- pycforge/converter/io/atomic_writer.py +33 -0
- pycforge/converter/ir/__init__.py +1 -0
- pycforge/converter/ir/c_ir/__init__.py +4 -0
- pycforge/converter/ir/c_ir/builder.py +26 -0
- pycforge/converter/ir/c_ir/model.py +318 -0
- pycforge/converter/ir/c_ir/serialization.py +88 -0
- pycforge/converter/ir/c_ir/validation.py +834 -0
- pycforge/converter/ir/python_ir/__init__.py +17 -0
- pycforge/converter/ir/python_ir/nodes.py +86 -0
- pycforge/converter/keyword_calls/__init__.py +68 -0
- pycforge/converter/keyword_calls/analysis.py +458 -0
- pycforge/converter/keyword_calls/lowering.py +271 -0
- pycforge/converter/keyword_calls/model.py +304 -0
- pycforge/converter/keyword_calls/validation.py +802 -0
- pycforge/converter/keyword_only_calls/__init__.py +68 -0
- pycforge/converter/keyword_only_calls/analysis.py +640 -0
- pycforge/converter/keyword_only_calls/lowering.py +376 -0
- pycforge/converter/keyword_only_calls/model.py +328 -0
- pycforge/converter/keyword_only_calls/validation.py +1357 -0
- pycforge/converter/lowering.py +1000 -0
- pycforge/converter/modules/__init__.py +13 -0
- pycforge/converter/modules/analysis.py +1250 -0
- pycforge/converter/modules/lowering.py +200 -0
- pycforge/converter/modules/model.py +73 -0
- pycforge/converter/modules/stage.py +192 -0
- pycforge/converter/numeric_semantics/__init__.py +23 -0
- pycforge/converter/numeric_semantics/analysis.py +420 -0
- pycforge/converter/numeric_semantics/lowering.py +153 -0
- pycforge/converter/numeric_semantics/model.py +123 -0
- pycforge/converter/records/__init__.py +34 -0
- pycforge/converter/records/analysis.py +1394 -0
- pycforge/converter/records/lowering.py +393 -0
- pycforge/converter/records/model.py +319 -0
- pycforge/converter/rules/__init__.py +3 -0
- pycforge/converter/support_templates/__init__.py +49 -0
- pycforge/converter/support_templates/assembly.py +106 -0
- pycforge/converter/support_templates/factories.py +348 -0
- pycforge/converter/support_templates/model.py +159 -0
- pycforge/converter/support_templates/registry.py +388 -0
- pycforge/converter/telemetry/__init__.py +0 -0
- pycforge/converter/telemetry/sink.py +39 -0
- pycforge/ide/__init__.py +19 -0
- pycforge/ide/__main__.py +5 -0
- pycforge/ide/_worker_event_codec.py +276 -0
- pycforge/ide/_worker_protocol_json.py +197 -0
- pycforge/ide/_worker_protocol_types.py +90 -0
- pycforge/ide/_worker_request_codec.py +200 -0
- pycforge/ide/_worker_request_data.py +260 -0
- pycforge/ide/_worker_result_data.py +343 -0
- pycforge/ide/action_contract.py +469 -0
- pycforge/ide/action_validation.py +229 -0
- pycforge/ide/command_palette.py +223 -0
- pycforge/ide/controller.py +904 -0
- pycforge/ide/controller_conversion.py +546 -0
- pycforge/ide/controller_io.py +205 -0
- pycforge/ide/editor.py +951 -0
- pycforge/ide/editor_commands_qt.py +274 -0
- pycforge/ide/editor_lexical.py +43 -0
- pycforge/ide/editor_sidebars.py +236 -0
- pycforge/ide/editor_syntax.py +243 -0
- pycforge/ide/find_replace.py +535 -0
- pycforge/ide/icons.py +91 -0
- pycforge/ide/io_service.py +196 -0
- pycforge/ide/model.py +164 -0
- pycforge/ide/panels.py +903 -0
- pycforge/ide/positions.py +220 -0
- pycforge/ide/process_worker.py +130 -0
- pycforge/ide/qt.py +230 -0
- pycforge/ide/qt_actions.py +418 -0
- pycforge/ide/qt_close.py +169 -0
- pycforge/ide/qt_command_palette.py +297 -0
- pycforge/ide/qt_contract.py +220 -0
- pycforge/ide/qt_documents.py +590 -0
- pycforge/ide/qt_editor_buffers.py +113 -0
- pycforge/ide/qt_editor_surfaces.py +112 -0
- pycforge/ide/qt_menus.py +324 -0
- pycforge/ide/qt_projection.py +500 -0
- pycforge/ide/qt_shell.py +348 -0
- pycforge/ide/qt_shell_interactions.py +320 -0
- pycforge/ide/qt_state.py +393 -0
- pycforge/ide/qt_workspace_features.py +398 -0
- pycforge/ide/qt_workspace_navigation.py +208 -0
- pycforge/ide/qt_workspace_observers.py +173 -0
- pycforge/ide/qt_workspace_panels.py +545 -0
- pycforge/ide/qt_workspace_widgets.py +228 -0
- pycforge/ide/resources/icons/about.svg +1 -0
- pycforge/ide/resources/icons/add-document.svg +1 -0
- pycforge/ide/resources/icons/brand-mark.svg +1 -0
- pycforge/ide/resources/icons/bundle-search.svg +1 -0
- pycforge/ide/resources/icons/cancel.svg +1 -0
- pycforge/ide/resources/icons/check.svg +1 -0
- pycforge/ide/resources/icons/chevron-right.svg +1 -0
- pycforge/ide/resources/icons/close.svg +1 -0
- pycforge/ide/resources/icons/collapse-all.svg +1 -0
- pycforge/ide/resources/icons/command-palette.svg +1 -0
- pycforge/ide/resources/icons/convert.svg +1 -0
- pycforge/ide/resources/icons/copy.svg +1 -0
- pycforge/ide/resources/icons/cut.svg +1 -0
- pycforge/ide/resources/icons/decision-trace.svg +1 -0
- pycforge/ide/resources/icons/details.svg +1 -0
- pycforge/ide/resources/icons/diagnostics.svg +1 -0
- pycforge/ide/resources/icons/duplicate-line.svg +1 -0
- pycforge/ide/resources/icons/exit.svg +1 -0
- pycforge/ide/resources/icons/expand-all.svg +1 -0
- pycforge/ide/resources/icons/export.svg +1 -0
- pycforge/ide/resources/icons/find.svg +1 -0
- pycforge/ide/resources/icons/go-to-line.svg +1 -0
- pycforge/ide/resources/icons/go-to-output.svg +1 -0
- pycforge/ide/resources/icons/go-to-source.svg +1 -0
- pycforge/ide/resources/icons/history.svg +1 -0
- pycforge/ide/resources/icons/indent.svg +1 -0
- pycforge/ide/resources/icons/link-c.svg +1 -0
- pycforge/ide/resources/icons/mappings.svg +1 -0
- pycforge/ide/resources/icons/module.svg +1 -0
- pycforge/ide/resources/icons/move-down.svg +1 -0
- pycforge/ide/resources/icons/move-line-down.svg +1 -0
- pycforge/ide/resources/icons/move-line-up.svg +1 -0
- pycforge/ide/resources/icons/move-up.svg +1 -0
- pycforge/ide/resources/icons/next.svg +1 -0
- pycforge/ide/resources/icons/open.svg +1 -0
- pycforge/ide/resources/icons/outdent.svg +1 -0
- pycforge/ide/resources/icons/outline.svg +1 -0
- pycforge/ide/resources/icons/paste.svg +1 -0
- pycforge/ide/resources/icons/previous.svg +1 -0
- pycforge/ide/resources/icons/primary-module.svg +1 -0
- pycforge/ide/resources/icons/redo.svg +1 -0
- pycforge/ide/resources/icons/remove-document.svg +1 -0
- pycforge/ide/resources/icons/replace.svg +1 -0
- pycforge/ide/resources/icons/save-as.svg +1 -0
- pycforge/ide/resources/icons/save.svg +1 -0
- pycforge/ide/resources/icons/select-all.svg +1 -0
- pycforge/ide/resources/icons/settings.svg +1 -0
- pycforge/ide/resources/icons/show-c.svg +1 -0
- pycforge/ide/resources/icons/split-view.svg +1 -0
- pycforge/ide/resources/icons/summary.svg +1 -0
- pycforge/ide/resources/icons/telemetry.svg +1 -0
- pycforge/ide/resources/icons/toggle-comment.svg +1 -0
- pycforge/ide/resources/icons/toggle-fold.svg +1 -0
- pycforge/ide/resources/icons/undo.svg +1 -0
- pycforge/ide/resources/icons/whitespace.svg +1 -0
- pycforge/ide/revisions.py +400 -0
- pycforge/ide/search_service.py +280 -0
- pycforge/ide/session_history.py +150 -0
- pycforge/ide/source_editing.py +417 -0
- pycforge/ide/source_structure.py +558 -0
- pycforge/ide/source_structure_async.py +191 -0
- pycforge/ide/supervisor.py +503 -0
- pycforge/ide/theme.py +119 -0
- pycforge/ide/theme_stylesheet.py +598 -0
- pycforge/ide/theme_workspace_stylesheet.py +155 -0
- pycforge/ide/visual_tokens.py +142 -0
- pycforge/ide/worker_protocol.py +80 -0
- pycforge/ide/workspace_search.py +462 -0
- pycforge/ide/workspace_session.py +256 -0
- pycforge/laboratory/__init__.py +6 -0
- pycforge/laboratory/audits.py +2244 -0
- pycforge/laboratory/checkpoint_e.py +2685 -0
- pycforge/laboratory/cli.py +119 -0
- pycforge/laboratory/exit_codes.py +11 -0
- pycforge/laboratory/keyword_audit.py +661 -0
- pycforge/laboratory/keyword_only_audit.py +481 -0
- pycforge-0.15.2.dist-info/METADATA +209 -0
- pycforge-0.15.2.dist-info/RECORD +221 -0
- pycforge-0.15.2.dist-info/WHEEL +5 -0
- pycforge-0.15.2.dist-info/entry_points.txt +5 -0
- pycforge-0.15.2.dist-info/licenses/LICENSE +674 -0
- pycforge-0.15.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from concurrent.futures import Future
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from hashlib import sha256
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from queue import Empty, Full, Queue
|
|
9
|
+
from tempfile import NamedTemporaryFile
|
|
10
|
+
from threading import RLock, Thread, current_thread
|
|
11
|
+
from typing import Callable
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class WorkspaceIOError(OSError):
|
|
15
|
+
"""A bounded workspace file operation failed."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class StaleWorkspaceWrite(WorkspaceIOError):
|
|
19
|
+
"""Freshness changed before an atomic destination replacement."""
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass(frozen=True, slots=True)
|
|
23
|
+
class FileRead:
|
|
24
|
+
path: str
|
|
25
|
+
text: str
|
|
26
|
+
utf8_sha256: str
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass(slots=True)
|
|
30
|
+
class _IOJob:
|
|
31
|
+
operation: Callable[[], object]
|
|
32
|
+
future: Future
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class WorkspaceIOService:
|
|
36
|
+
"""Small daemon-backed file service that never blocks application exit."""
|
|
37
|
+
|
|
38
|
+
def __init__(self, *, workers: int = 2, capacity: int = 8) -> None:
|
|
39
|
+
if not 1 <= workers <= 4:
|
|
40
|
+
raise ValueError("workspace I/O worker count must be between 1 and 4")
|
|
41
|
+
if capacity < workers:
|
|
42
|
+
raise ValueError("workspace I/O capacity must cover every worker")
|
|
43
|
+
self._queue: Queue[_IOJob | None] = Queue(maxsize=capacity)
|
|
44
|
+
self._lock = RLock()
|
|
45
|
+
self._closed = False
|
|
46
|
+
self._threads = tuple(
|
|
47
|
+
Thread(
|
|
48
|
+
target=self._run,
|
|
49
|
+
name=f"pycforge-file-io-{index + 1}",
|
|
50
|
+
daemon=True,
|
|
51
|
+
)
|
|
52
|
+
for index in range(workers)
|
|
53
|
+
)
|
|
54
|
+
for thread in self._threads:
|
|
55
|
+
thread.start()
|
|
56
|
+
|
|
57
|
+
def read_text(self, path: Path | str) -> Future[FileRead]:
|
|
58
|
+
source = Path(path)
|
|
59
|
+
|
|
60
|
+
def operation() -> FileRead:
|
|
61
|
+
try:
|
|
62
|
+
text = source.read_text(encoding="utf-8")
|
|
63
|
+
encoded = text.encode("utf-8")
|
|
64
|
+
except (OSError, UnicodeError) as exc:
|
|
65
|
+
raise WorkspaceIOError(
|
|
66
|
+
f"could not read UTF-8 workspace file: {source}"
|
|
67
|
+
) from exc
|
|
68
|
+
return FileRead(str(source), text, sha256(encoded).hexdigest())
|
|
69
|
+
|
|
70
|
+
return self._submit(operation)
|
|
71
|
+
|
|
72
|
+
def write_text(
|
|
73
|
+
self,
|
|
74
|
+
path: Path | str,
|
|
75
|
+
text: str,
|
|
76
|
+
*,
|
|
77
|
+
before_replace: Callable[[], bool] | None = None,
|
|
78
|
+
) -> Future[str]:
|
|
79
|
+
destination = Path(path)
|
|
80
|
+
if not isinstance(text, str):
|
|
81
|
+
raise TypeError("workspace file text must be a string")
|
|
82
|
+
|
|
83
|
+
def operation() -> str:
|
|
84
|
+
self._atomic_write(
|
|
85
|
+
destination,
|
|
86
|
+
text,
|
|
87
|
+
before_replace=before_replace,
|
|
88
|
+
)
|
|
89
|
+
return str(destination)
|
|
90
|
+
|
|
91
|
+
return self._submit(operation)
|
|
92
|
+
|
|
93
|
+
def observe_text(self, path: Path | str) -> Future[FileRead]:
|
|
94
|
+
return self.read_text(path)
|
|
95
|
+
|
|
96
|
+
def close(self, *, wait: bool = False, timeout: float | None = None) -> None:
|
|
97
|
+
with self._lock:
|
|
98
|
+
if not self._closed:
|
|
99
|
+
self._closed = True
|
|
100
|
+
while True:
|
|
101
|
+
try:
|
|
102
|
+
job = self._queue.get_nowait()
|
|
103
|
+
except Empty:
|
|
104
|
+
break
|
|
105
|
+
if job is not None and not job.future.done():
|
|
106
|
+
job.future.cancel()
|
|
107
|
+
self._queue.task_done()
|
|
108
|
+
for _ in self._threads:
|
|
109
|
+
try:
|
|
110
|
+
self._queue.put_nowait(None)
|
|
111
|
+
except Full:
|
|
112
|
+
break
|
|
113
|
+
if wait:
|
|
114
|
+
for thread in self._threads:
|
|
115
|
+
if thread is not current_thread():
|
|
116
|
+
thread.join(timeout)
|
|
117
|
+
|
|
118
|
+
def _submit(self, operation: Callable[[], object]):
|
|
119
|
+
future = Future()
|
|
120
|
+
with self._lock:
|
|
121
|
+
if self._closed:
|
|
122
|
+
raise RuntimeError("workspace I/O service is closed")
|
|
123
|
+
try:
|
|
124
|
+
self._queue.put_nowait(_IOJob(operation, future))
|
|
125
|
+
except Full as exc:
|
|
126
|
+
raise WorkspaceIOError(
|
|
127
|
+
"workspace I/O capacity is temporarily full"
|
|
128
|
+
) from exc
|
|
129
|
+
return future
|
|
130
|
+
|
|
131
|
+
def _run(self) -> None:
|
|
132
|
+
while True:
|
|
133
|
+
job = self._queue.get()
|
|
134
|
+
try:
|
|
135
|
+
if job is None:
|
|
136
|
+
return
|
|
137
|
+
if not job.future.set_running_or_notify_cancel():
|
|
138
|
+
continue
|
|
139
|
+
try:
|
|
140
|
+
result = job.operation()
|
|
141
|
+
except BaseException as exc:
|
|
142
|
+
job.future.set_exception(exc)
|
|
143
|
+
else:
|
|
144
|
+
job.future.set_result(result)
|
|
145
|
+
finally:
|
|
146
|
+
self._queue.task_done()
|
|
147
|
+
|
|
148
|
+
@staticmethod
|
|
149
|
+
def _atomic_write(
|
|
150
|
+
destination: Path,
|
|
151
|
+
text: str,
|
|
152
|
+
*,
|
|
153
|
+
before_replace: Callable[[], bool] | None,
|
|
154
|
+
) -> None:
|
|
155
|
+
temporary: Path | None = None
|
|
156
|
+
try:
|
|
157
|
+
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
158
|
+
with NamedTemporaryFile(
|
|
159
|
+
"w",
|
|
160
|
+
encoding="utf-8",
|
|
161
|
+
newline="",
|
|
162
|
+
dir=destination.parent,
|
|
163
|
+
prefix=f".{destination.name}.",
|
|
164
|
+
suffix=".tmp",
|
|
165
|
+
delete=False,
|
|
166
|
+
) as handle:
|
|
167
|
+
temporary = Path(handle.name)
|
|
168
|
+
handle.write(text)
|
|
169
|
+
handle.flush()
|
|
170
|
+
os.fsync(handle.fileno())
|
|
171
|
+
if before_replace is not None and not before_replace():
|
|
172
|
+
raise StaleWorkspaceWrite(
|
|
173
|
+
"workspace freshness changed before file publication"
|
|
174
|
+
)
|
|
175
|
+
os.replace(temporary, destination)
|
|
176
|
+
temporary = None
|
|
177
|
+
except StaleWorkspaceWrite:
|
|
178
|
+
raise
|
|
179
|
+
except Exception as exc:
|
|
180
|
+
raise WorkspaceIOError(
|
|
181
|
+
f"atomic workspace write failed: {destination}"
|
|
182
|
+
) from exc
|
|
183
|
+
finally:
|
|
184
|
+
if temporary is not None:
|
|
185
|
+
try:
|
|
186
|
+
temporary.unlink()
|
|
187
|
+
except FileNotFoundError:
|
|
188
|
+
pass
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
__all__ = [
|
|
192
|
+
"FileRead",
|
|
193
|
+
"StaleWorkspaceWrite",
|
|
194
|
+
"WorkspaceIOError",
|
|
195
|
+
"WorkspaceIOService",
|
|
196
|
+
]
|
pycforge/ide/model.py
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from enum import Enum
|
|
5
|
+
from typing import Any, TypeAlias
|
|
6
|
+
|
|
7
|
+
from .session_history import ConversionHistoryEntry
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
MAX_WORKSPACE_DOCUMENTS = 64
|
|
11
|
+
PreferenceValue: TypeAlias = str | int | float | bool | None
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class WorkspaceState(str, Enum):
|
|
15
|
+
EMPTY = "empty"
|
|
16
|
+
CONVERTING = "converting"
|
|
17
|
+
CANCEL_REQUESTED = "cancel-requested"
|
|
18
|
+
CONVERTED = "converted"
|
|
19
|
+
WARNING = "warning"
|
|
20
|
+
APPROXIMATION = "approximation"
|
|
21
|
+
REJECTED = "rejected"
|
|
22
|
+
CANCELED = "canceled"
|
|
23
|
+
FAILED = "failed"
|
|
24
|
+
STALE = "stale"
|
|
25
|
+
OBSERVER_INCOMPLETE = "observer-incomplete"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
PUBLISHABLE_STATES = frozenset(
|
|
29
|
+
{
|
|
30
|
+
WorkspaceState.CONVERTED,
|
|
31
|
+
WorkspaceState.WARNING,
|
|
32
|
+
WorkspaceState.APPROXIMATION,
|
|
33
|
+
WorkspaceState.OBSERVER_INCOMPLETE,
|
|
34
|
+
}
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass(frozen=True, slots=True)
|
|
39
|
+
class WorkspaceDocument:
|
|
40
|
+
"""One immutable document in a bounded workspace bundle.
|
|
41
|
+
|
|
42
|
+
``path`` is deliberately a string rather than a :class:`~pathlib.Path` so
|
|
43
|
+
snapshots remain composed of plain, persistence-friendly values.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
document_id: str
|
|
47
|
+
module_id: str
|
|
48
|
+
logical_name: str
|
|
49
|
+
text: str = ""
|
|
50
|
+
path: str | None = None
|
|
51
|
+
is_primary: bool = False
|
|
52
|
+
dirty: bool = False
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def initial_document() -> WorkspaceDocument:
|
|
56
|
+
return WorkspaceDocument(
|
|
57
|
+
document_id="doc-main",
|
|
58
|
+
module_id="main",
|
|
59
|
+
logical_name="main.py",
|
|
60
|
+
is_primary=True,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@dataclass(frozen=True, slots=True)
|
|
65
|
+
class WorkspaceSnapshot:
|
|
66
|
+
# Compatibility mirrors for the active document. New code should prefer
|
|
67
|
+
# ``active_document`` and ``bundle_fingerprint``.
|
|
68
|
+
source_text: str = ""
|
|
69
|
+
source_fingerprint: str = ""
|
|
70
|
+
documents: tuple[WorkspaceDocument, ...] = field(
|
|
71
|
+
default_factory=lambda: (initial_document(),)
|
|
72
|
+
)
|
|
73
|
+
active_document_id: str = "doc-main"
|
|
74
|
+
bundle_fingerprint: str = ""
|
|
75
|
+
linked_c_path: str | None = None
|
|
76
|
+
linked_c_path_is_default: bool = True
|
|
77
|
+
preferences: tuple[tuple[str, PreferenceValue], ...] = ()
|
|
78
|
+
|
|
79
|
+
generated_c: str | None = None
|
|
80
|
+
state: WorkspaceState = WorkspaceState.EMPTY
|
|
81
|
+
diagnostics: tuple[dict[str, Any], ...] = ()
|
|
82
|
+
summary: tuple[tuple[str, str], ...] = ()
|
|
83
|
+
decision_trace: dict[str, Any] | None = None
|
|
84
|
+
telemetry: dict[str, Any] | None = None
|
|
85
|
+
conversion_summary: dict[str, Any] | None = None
|
|
86
|
+
mappings: tuple[dict[str, Any], ...] = ()
|
|
87
|
+
conversion_history: tuple[ConversionHistoryEntry, ...] = ()
|
|
88
|
+
revision_generation: int = 0
|
|
89
|
+
revision_authenticated: bool = True
|
|
90
|
+
request_sequence: int = 0
|
|
91
|
+
result_source_fingerprint: str | None = None
|
|
92
|
+
result_bundle_fingerprint: str | None = None
|
|
93
|
+
result_revision_generation: int | None = None
|
|
94
|
+
result_state: WorkspaceState | None = None
|
|
95
|
+
stale_reason: str | None = None
|
|
96
|
+
worker_failure_reason: str | None = None
|
|
97
|
+
active_stage: str | None = None
|
|
98
|
+
completed_stages: int = 0
|
|
99
|
+
total_stages: int = 0
|
|
100
|
+
|
|
101
|
+
@property
|
|
102
|
+
def active_document(self) -> WorkspaceDocument:
|
|
103
|
+
for document in self.documents:
|
|
104
|
+
if document.document_id == self.active_document_id:
|
|
105
|
+
return document
|
|
106
|
+
# Controller invariants make this unreachable. Raising here is safer
|
|
107
|
+
# than silently presenting a different document to a view.
|
|
108
|
+
raise LookupError("active workspace document is missing")
|
|
109
|
+
|
|
110
|
+
@property
|
|
111
|
+
def primary_document(self) -> WorkspaceDocument:
|
|
112
|
+
for document in self.documents:
|
|
113
|
+
if document.is_primary:
|
|
114
|
+
return document
|
|
115
|
+
raise LookupError("primary workspace document is missing")
|
|
116
|
+
|
|
117
|
+
@property
|
|
118
|
+
def can_convert(self) -> bool:
|
|
119
|
+
return bool(
|
|
120
|
+
self.documents
|
|
121
|
+
and self.revision_authenticated
|
|
122
|
+
and self.bundle_fingerprint
|
|
123
|
+
and self.state
|
|
124
|
+
not in {WorkspaceState.CONVERTING, WorkspaceState.CANCEL_REQUESTED}
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
@property
|
|
128
|
+
def can_cancel(self) -> bool:
|
|
129
|
+
return self.state is WorkspaceState.CONVERTING
|
|
130
|
+
|
|
131
|
+
@property
|
|
132
|
+
def can_save_python(self) -> bool:
|
|
133
|
+
return bool(self.documents)
|
|
134
|
+
|
|
135
|
+
@property
|
|
136
|
+
def can_save_c(self) -> bool:
|
|
137
|
+
result_fingerprint = (
|
|
138
|
+
self.result_bundle_fingerprint or self.result_source_fingerprint
|
|
139
|
+
)
|
|
140
|
+
return bool(
|
|
141
|
+
self.generated_c is not None
|
|
142
|
+
and self.state in PUBLISHABLE_STATES
|
|
143
|
+
and result_fingerprint == self.bundle_fingerprint
|
|
144
|
+
and self.result_revision_generation == self.revision_generation
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
@property
|
|
148
|
+
def can_add_document(self) -> bool:
|
|
149
|
+
return len(self.documents) < MAX_WORKSPACE_DOCUMENTS
|
|
150
|
+
|
|
151
|
+
@property
|
|
152
|
+
def can_remove_document(self) -> bool:
|
|
153
|
+
return len(self.documents) > 1
|
|
154
|
+
|
|
155
|
+
def preference_data(self) -> dict[str, PreferenceValue]:
|
|
156
|
+
return dict(self.preferences)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
@dataclass(slots=True)
|
|
160
|
+
class WorkspaceStore:
|
|
161
|
+
snapshot: WorkspaceSnapshot = field(default_factory=WorkspaceSnapshot)
|
|
162
|
+
|
|
163
|
+
def replace(self, snapshot: WorkspaceSnapshot) -> None:
|
|
164
|
+
self.snapshot = snapshot
|