sillon 2.1.2__tar.gz → 2.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. {sillon-2.1.2/sillon.egg-info → sillon-2.3.0}/PKG-INFO +14 -3
  2. {sillon-2.1.2 → sillon-2.3.0}/README.md +4 -1
  3. {sillon-2.1.2 → sillon-2.3.0}/packages/common/src/silloncommon/__init__.py +1 -1
  4. {sillon-2.1.2 → sillon-2.3.0}/packages/core/src/silloncore/bundle.py +4 -2
  5. {sillon-2.1.2 → sillon-2.3.0}/packages/core/src/silloncore/diff.py +142 -43
  6. {sillon-2.1.2 → sillon-2.3.0}/packages/core/src/silloncore/display.py +65 -0
  7. {sillon-2.1.2 → sillon-2.3.0}/packages/core/src/silloncore/engine.py +105 -12
  8. {sillon-2.1.2 → sillon-2.3.0}/packages/core/src/silloncore/project_paths.py +28 -9
  9. sillon-2.3.0/packages/interface/cli/src/silloncli/commands/gui.py +141 -0
  10. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/commands/versions.py +48 -9
  11. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/main.py +2 -0
  12. sillon-2.3.0/packages/interface/gui/src/sillongui/__init__.py +12 -0
  13. sillon-2.3.0/packages/interface/gui/src/sillongui/__main__.py +7 -0
  14. sillon-2.3.0/packages/interface/gui/src/sillongui/app.py +42 -0
  15. sillon-2.3.0/packages/interface/gui/src/sillongui/models/__init__.py +0 -0
  16. sillon-2.3.0/packages/interface/gui/src/sillongui/models/run_model.py +140 -0
  17. sillon-2.3.0/packages/interface/gui/src/sillongui/preferences.py +124 -0
  18. sillon-2.3.0/packages/interface/gui/src/sillongui/project.py +355 -0
  19. sillon-2.3.0/packages/interface/gui/src/sillongui/query.py +173 -0
  20. sillon-2.3.0/packages/interface/gui/src/sillongui/theme.py +450 -0
  21. sillon-2.3.0/packages/interface/gui/src/sillongui/views/__init__.py +0 -0
  22. sillon-2.3.0/packages/interface/gui/src/sillongui/views/data_tab.py +77 -0
  23. sillon-2.3.0/packages/interface/gui/src/sillongui/views/data_view.py +204 -0
  24. sillon-2.3.0/packages/interface/gui/src/sillongui/views/details_view.py +76 -0
  25. sillon-2.3.0/packages/interface/gui/src/sillongui/views/errors.py +15 -0
  26. sillon-2.3.0/packages/interface/gui/src/sillongui/views/export_dialog.py +60 -0
  27. sillon-2.3.0/packages/interface/gui/src/sillongui/views/figure_view.py +267 -0
  28. sillon-2.3.0/packages/interface/gui/src/sillongui/views/main_window.py +686 -0
  29. sillon-2.3.0/packages/interface/gui/src/sillongui/views/output_view.py +275 -0
  30. sillon-2.3.0/packages/interface/gui/src/sillongui/views/query_bar.py +183 -0
  31. sillon-2.3.0/packages/interface/gui/src/sillongui/views/run_list.py +229 -0
  32. sillon-2.3.0/packages/interface/gui/src/sillongui/views/settings_dialog.py +139 -0
  33. sillon-2.3.0/packages/interface/gui/src/sillongui/views/source_view.py +227 -0
  34. sillon-2.3.0/packages/interface/gui/src/sillongui/views/title_bar.py +71 -0
  35. sillon-2.3.0/packages/interface/gui/src/sillongui/views/vibrancy.py +106 -0
  36. sillon-2.3.0/packages/interface/gui/src/sillongui/views/widgets.py +41 -0
  37. sillon-2.3.0/packages/interface/gui/src/sillongui/workers/__init__.py +0 -0
  38. sillon-2.3.0/packages/interface/gui/src/sillongui/workers/task.py +76 -0
  39. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/sillonlab/src/sillonlab/project.py +66 -0
  40. {sillon-2.1.2 → sillon-2.3.0}/pyproject.toml +4 -1
  41. {sillon-2.1.2 → sillon-2.3.0/sillon.egg-info}/PKG-INFO +14 -3
  42. {sillon-2.1.2 → sillon-2.3.0}/sillon.egg-info/SOURCES.txt +28 -0
  43. {sillon-2.1.2 → sillon-2.3.0}/sillon.egg-info/entry_points.txt +1 -0
  44. {sillon-2.1.2 → sillon-2.3.0}/sillon.egg-info/requires.txt +10 -1
  45. {sillon-2.1.2 → sillon-2.3.0}/sillon.egg-info/top_level.txt +1 -0
  46. {sillon-2.1.2 → sillon-2.3.0}/LICENSE +0 -0
  47. {sillon-2.1.2 → sillon-2.3.0}/packages/common/src/silloncommon/access_log.py +0 -0
  48. {sillon-2.1.2 → sillon-2.3.0}/packages/common/src/silloncommon/codeversion.py +0 -0
  49. {sillon-2.1.2 → sillon-2.3.0}/packages/common/src/silloncommon/commands.py +0 -0
  50. {sillon-2.1.2 → sillon-2.3.0}/packages/common/src/silloncommon/database.py +0 -0
  51. {sillon-2.1.2 → sillon-2.3.0}/packages/common/src/silloncommon/framing.py +0 -0
  52. {sillon-2.1.2 → sillon-2.3.0}/packages/common/src/silloncommon/hashing.py +0 -0
  53. {sillon-2.1.2 → sillon-2.3.0}/packages/common/src/silloncommon/hdf5_staging.py +0 -0
  54. {sillon-2.1.2 → sillon-2.3.0}/packages/common/src/silloncommon/project_config.py +0 -0
  55. {sillon-2.1.2 → sillon-2.3.0}/packages/common/src/silloncommon/registry.py +0 -0
  56. {sillon-2.1.2 → sillon-2.3.0}/packages/common/src/silloncommon/rpcHandler.py +0 -0
  57. {sillon-2.1.2 → sillon-2.3.0}/packages/common/src/silloncommon/socket_path.py +0 -0
  58. {sillon-2.1.2 → sillon-2.3.0}/packages/common/src/silloncommon/source_store.py +0 -0
  59. {sillon-2.1.2 → sillon-2.3.0}/packages/common/src/silloncommon/timestamps.py +0 -0
  60. {sillon-2.1.2 → sillon-2.3.0}/packages/common/src/silloncommon/transport.py +0 -0
  61. {sillon-2.1.2 → sillon-2.3.0}/packages/common/src/silloncommon/user_paths.py +0 -0
  62. {sillon-2.1.2 → sillon-2.3.0}/packages/core/src/silloncore/__init__.py +0 -0
  63. {sillon-2.1.2 → sillon-2.3.0}/packages/core/src/silloncore/check.py +0 -0
  64. {sillon-2.1.2 → sillon-2.3.0}/packages/core/src/silloncore/envhandler.py +0 -0
  65. {sillon-2.1.2 → sillon-2.3.0}/packages/core/src/silloncore/glob.py +0 -0
  66. {sillon-2.1.2 → sillon-2.3.0}/packages/core/src/silloncore/projects.py +0 -0
  67. {sillon-2.1.2 → sillon-2.3.0}/packages/core/src/silloncore/server/__init__.py +0 -0
  68. {sillon-2.1.2 → sillon-2.3.0}/packages/core/src/silloncore/server/main.py +0 -0
  69. {sillon-2.1.2 → sillon-2.3.0}/packages/core/src/silloncore/server/server.py +0 -0
  70. {sillon-2.1.2 → sillon-2.3.0}/packages/core/src/silloncore/server/visitor.py +0 -0
  71. {sillon-2.1.2 → sillon-2.3.0}/packages/core/src/silloncore/simulation.py +0 -0
  72. {sillon-2.1.2 → sillon-2.3.0}/packages/core/src/silloncore/transfer.py +0 -0
  73. {sillon-2.1.2 → sillon-2.3.0}/packages/core/src/silloncore/versioncontrol.py +0 -0
  74. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/__init__.py +0 -0
  75. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/commands/__init__.py +0 -0
  76. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/commands/add.py +0 -0
  77. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/commands/check.py +0 -0
  78. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/commands/delete.py +0 -0
  79. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/commands/diff.py +0 -0
  80. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/commands/export.py +0 -0
  81. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/commands/fetch.py +0 -0
  82. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/commands/import_cmd.py +0 -0
  83. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/commands/init.py +0 -0
  84. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/commands/like.py +0 -0
  85. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/commands/lineage.py +0 -0
  86. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/commands/list.py +0 -0
  87. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/commands/projects.py +0 -0
  88. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/commands/prune.py +0 -0
  89. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/commands/query.py +0 -0
  90. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/commands/rename.py +0 -0
  91. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/commands/report.py +0 -0
  92. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/commands/show.py +0 -0
  93. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/commands/trace.py +0 -0
  94. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/cli/src/silloncli/context.py +0 -0
  95. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/sillonlab/src/sillonlab/__init__.py +0 -0
  96. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/sillonlab/src/sillonlab/display.py +0 -0
  97. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/sillonlab/src/sillonlab/projects.py +0 -0
  98. {sillon-2.1.2 → sillon-2.3.0}/packages/interface/sillonlab/src/sillonlab/run.py +0 -0
  99. {sillon-2.1.2 → sillon-2.3.0}/packages/pyapi/src/sillonpy/__init__.py +0 -0
  100. {sillon-2.1.2 → sillon-2.3.0}/packages/pyapi/src/sillonpy/api.py +0 -0
  101. {sillon-2.1.2 → sillon-2.3.0}/packages/pyapi/src/sillonpy/daemon.py +0 -0
  102. {sillon-2.1.2 → sillon-2.3.0}/packages/pyapi/src/sillonpy/metadata.py +0 -0
  103. {sillon-2.1.2 → sillon-2.3.0}/packages/pyapi/src/sillonpy/serverCom.py +0 -0
  104. {sillon-2.1.2 → sillon-2.3.0}/packages/pyapi/src/sillonpy/tracker.py +0 -0
  105. {sillon-2.1.2 → sillon-2.3.0}/setup.cfg +0 -0
  106. {sillon-2.1.2 → sillon-2.3.0}/sillon.egg-info/dependency_links.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sillon
3
- Version: 2.1.2
3
+ Version: 2.3.0
4
4
  Summary: Git for simulations — log, track, query and analyze simulation runs.
5
5
  Author-email: Guillaume Tassotti <placeholder@email.com>, Baptiste Lerat <lerat.baptiste99@proton.ch>
6
6
  License-Expression: Apache-2.0
@@ -28,9 +28,17 @@ Requires-Dist: numpy
28
28
  Requires-Dist: tqdm
29
29
  Provides-Extra: analysis
30
30
  Requires-Dist: pandas; extra == "analysis"
31
+ Provides-Extra: gui
32
+ Requires-Dist: PySide6>=6.10; extra == "gui"
33
+ Requires-Dist: silx; extra == "gui"
34
+ Requires-Dist: matplotlib; extra == "gui"
35
+ Requires-Dist: qtawesome; extra == "gui"
36
+ Requires-Dist: PyOpenGL; extra == "gui"
37
+ Requires-Dist: pygments; extra == "gui"
31
38
  Provides-Extra: dev
32
- Requires-Dist: sillon[analysis]; extra == "dev"
39
+ Requires-Dist: sillon[analysis,gui]; extra == "dev"
33
40
  Requires-Dist: pytest; extra == "dev"
41
+ Requires-Dist: pytest-qt; extra == "dev"
34
42
  Requires-Dist: psutil; extra == "dev"
35
43
  Requires-Dist: build; extra == "dev"
36
44
  Requires-Dist: twine; extra == "dev"
@@ -172,6 +180,7 @@ start, and heavy arrays offloaded without you thinking about it.
172
180
  | [Core concepts](docs/getting-started/concepts.md) | the mental model — read once |
173
181
  | [Logging runs](docs/guide/logging.md) | the whole logging API |
174
182
  | [Querying and analysis](docs/guide/analysis.md) | working with many runs |
183
+ | [The desktop browser](docs/guide/gui.md) | `sillon gui`: runs, data and figures in a window |
175
184
  | [Provenance and lineage](docs/guide/provenance.md) | code versions, automatic lineage, figures, hashes |
176
185
  | [Moving runs between machines](docs/guide/transfer.md) | bundles, merging projects, the shared drive |
177
186
  | [Working with projects](docs/guide/projects.md) | finding, naming, moving them |
@@ -195,9 +204,11 @@ See [Architecture](docs/dev/architecture.md).
195
204
  ## Status and roadmap
196
205
 
197
206
  The logging API, the daemon, the CLI and the analysis library are in daily use.
207
+ The desktop browser (`pip install "sillon[gui]"`, then `sillon gui`) is new in
208
+ 2.2; its Lineage tab is not built yet.
198
209
 
199
210
  Not implemented yet, despite appearing in older notes: `sillon run`
200
- (reproduction), `sillon watch`, `sillon estimate`, a GUI, Slurm integration, and
211
+ (reproduction), `sillon watch`, `sillon estimate`, Slurm integration, and
201
212
  non-Python clients. If a command is not in the [CLI reference](docs/reference/cli.md),
202
213
  it does not exist.
203
214
 
@@ -131,6 +131,7 @@ start, and heavy arrays offloaded without you thinking about it.
131
131
  | [Core concepts](docs/getting-started/concepts.md) | the mental model — read once |
132
132
  | [Logging runs](docs/guide/logging.md) | the whole logging API |
133
133
  | [Querying and analysis](docs/guide/analysis.md) | working with many runs |
134
+ | [The desktop browser](docs/guide/gui.md) | `sillon gui`: runs, data and figures in a window |
134
135
  | [Provenance and lineage](docs/guide/provenance.md) | code versions, automatic lineage, figures, hashes |
135
136
  | [Moving runs between machines](docs/guide/transfer.md) | bundles, merging projects, the shared drive |
136
137
  | [Working with projects](docs/guide/projects.md) | finding, naming, moving them |
@@ -154,9 +155,11 @@ See [Architecture](docs/dev/architecture.md).
154
155
  ## Status and roadmap
155
156
 
156
157
  The logging API, the daemon, the CLI and the analysis library are in daily use.
158
+ The desktop browser (`pip install "sillon[gui]"`, then `sillon gui`) is new in
159
+ 2.2; its Lineage tab is not built yet.
157
160
 
158
161
  Not implemented yet, despite appearing in older notes: `sillon run`
159
- (reproduction), `sillon watch`, `sillon estimate`, a GUI, Slurm integration, and
162
+ (reproduction), `sillon watch`, `sillon estimate`, Slurm integration, and
160
163
  non-Python clients. If a command is not in the [CLI reference](docs/reference/cli.md),
161
164
  it does not exist.
162
165
 
@@ -2,4 +2,4 @@
2
2
 
3
3
  # Single source of truth for the sillon data/format version, recorded on every
4
4
  # run (SimulationTable.sillonversion) and reused across packages.
5
- __version__ = "2.1.2"
5
+ __version__ = "2.3.0"
@@ -218,9 +218,11 @@ def _resolve_dest(dest, project_path, hostname: str) -> Path:
218
218
  """Where to write, accepting either a file or a directory."""
219
219
  if dest is None:
220
220
  return Path.cwd() / default_bundle_name(project_path, hostname)
221
+ # Read the trailing separator off the caller's text: `Path` drops it, and
222
+ # with it the only sign that `newdir/` (not there yet) is meant as a folder.
223
+ trailing_separator = isinstance(dest, str) and dest.endswith(("/", "\\"))
221
224
  dest = Path(dest).expanduser()
222
- looks_like_dir = dest.is_dir() or str(dest).endswith(("/", "\\"))
223
- if looks_like_dir:
225
+ if trailing_separator or dest.is_dir():
224
226
  return dest / default_bundle_name(project_path, hostname)
225
227
  return dest
226
228
 
@@ -17,8 +17,9 @@ were not compared, rather than stalling a diff on a gigabyte.
17
17
  """
18
18
 
19
19
  import math
20
- from difflib import unified_diff
20
+ from difflib import SequenceMatcher, unified_diff
21
21
 
22
+ from silloncommon.codeversion import source_hash
22
23
  from silloncommon.source_store import read_source
23
24
 
24
25
  from silloncore.glob import glob_descriptors, read_glob
@@ -28,7 +29,7 @@ from silloncore.glob import glob_descriptors, read_glob
28
29
  # still covering most of what people actually compare.
29
30
  DEFAULT_MAX_COMPARE_BYTES = 64 * 1024 * 1024
30
31
 
31
- __all__ = ["diff_runs", "diff_across", "percent_delta", "DEFAULT_MAX_COMPARE_BYTES"]
32
+ __all__ = ["diff_runs", "compare_code", "diff_across", "percent_delta", "DEFAULT_MAX_COMPARE_BYTES"]
32
33
 
33
34
 
34
35
  # ==========================================
@@ -172,62 +173,160 @@ def _code_files(snapshot) -> dict:
172
173
  return version.get("files") or {}
173
174
 
174
175
 
176
+ # A version recovered by `backfill_code_versions` names its one file this way.
177
+ ENTRY_PLACEHOLDER = "<entry script>"
178
+
179
+
180
+ class _Lazy:
181
+ """A value computed on first use: a run's main source is an HDF5 read,
182
+ needed only when the source store lacks a file."""
183
+
184
+ def __init__(self, compute):
185
+ self._compute, self._done, self._value = compute, compute is None, None
186
+
187
+ def get(self):
188
+ if not self._done:
189
+ self._value, self._done = self._compute(), True
190
+ return self._value
191
+
192
+
193
+ def _read_text(storage_root, hashes: dict, main: _Lazy):
194
+ """A file's text from the source store; for an entry script logged before
195
+ the store kept it, the run's own copy (same hash, same text)."""
196
+ digest = hashes.get("source_hash")
197
+ if not digest:
198
+ return None
199
+ text = read_source(storage_root, digest)
200
+ if text is None:
201
+ recorded = main.get()
202
+ if recorded is not None and source_hash(recorded) == digest:
203
+ text = recorded
204
+ return text
205
+
206
+
207
+ # Below this, a placeholder and a file are unrelated scripts, not two versions of one.
208
+ _SAME_SCRIPT = 0.5
209
+
210
+
211
+ def _closest(storage_root, hashes: dict, main: _Lazy, candidates: dict, other_main: _Lazy):
212
+ """The candidate file most like the script behind `hashes`, if any is alike."""
213
+ for name, candidate in candidates.items():
214
+ if candidate.get("source_hash") == hashes.get("source_hash"):
215
+ return name
216
+ text = _read_text(storage_root, hashes, main)
217
+ if text is None:
218
+ return None
219
+ best, score = None, _SAME_SCRIPT
220
+ for name, candidate in candidates.items():
221
+ other = _read_text(storage_root, candidate, other_main)
222
+ if other is None:
223
+ continue
224
+ ratio = SequenceMatcher(None, text, other, autojunk=False).quick_ratio()
225
+ if ratio > score:
226
+ best, score = name, ratio
227
+ return best
228
+
229
+
230
+ def _file_status(a: dict, b: dict) -> str:
231
+ if a.get("logic_hash") != b.get("logic_hash"):
232
+ return "changed"
233
+ if a.get("ast_hash") != b.get("ast_hash"):
234
+ return "constants" # same program, different literals
235
+ if a.get("source_hash") != b.get("source_hash"):
236
+ return "cosmetic" # comments or formatting only
237
+ return "same"
238
+
239
+
240
+ def compare_code(storage_root, files_a: dict, files_b: dict, label_a: str, label_b: str,
241
+ main_a=None, main_b=None) -> dict:
242
+ """Compares two sets of recorded code files, down to the changed lines.
243
+
244
+ Args:
245
+ storage_root: The project's storage root (holds the source store).
246
+ files_a, files_b (dict): `{name: {"source_hash", "ast_hash",
247
+ "logic_hash"}}`, as in `sillon.code.version`.
248
+ label_a, label_b (str): What each side is called in the diff headers
249
+ (a run name, a version prefix).
250
+ main_a, main_b (callable, optional): Return the side's recorded main
251
+ source, used when the store lacks the entry script. Called at most
252
+ once, and only when needed.
253
+
254
+ Returns:
255
+ dict: `{"files": {name: {"status", "diff", "missing"}},
256
+ "constants_differ", "source_diff"}`. `status` is one of
257
+ added, removed, changed, constants, cosmetic, same; `diff` is that
258
+ file's unified diff; `missing` is True when its text could not be
259
+ read, so no diff could be made.
260
+ """
261
+ mains = (_Lazy(main_a), _Lazy(main_b))
262
+ files_a, files_b = dict(files_a), dict(files_b)
263
+ # A backfilled version knows its entry script only as a placeholder: pair
264
+ # it with the file it most resembles on the other side rather than report
265
+ # one file removed and another added.
266
+ for this, other, sides in ((files_a, files_b, mains), (files_b, files_a, mains[::-1])):
267
+ if ENTRY_PLACEHOLDER in this and ENTRY_PLACEHOLDER not in other:
268
+ name = _closest(storage_root, this[ENTRY_PLACEHOLDER], sides[0],
269
+ {n: h for n, h in other.items() if n not in this}, sides[1])
270
+ if name:
271
+ this[name] = this.pop(ENTRY_PLACEHOLDER)
272
+
273
+ files, diffs, constants = {}, [], False
274
+ for name in sorted(set(files_a) | set(files_b)):
275
+ a, b = files_a.get(name), files_b.get(name)
276
+ if a is None:
277
+ status = "added"
278
+ elif b is None:
279
+ status = "removed"
280
+ else:
281
+ status = _file_status(a, b)
282
+ constants = constants or status == "constants"
283
+ info = {"status": status, "diff": "", "missing": False}
284
+ if status != "same":
285
+ text_a = "" if a is None else _read_text(storage_root, a, mains[0])
286
+ text_b = "" if b is None else _read_text(storage_root, b, mains[1])
287
+ if text_a is None or text_b is None:
288
+ info["missing"] = True
289
+ else:
290
+ info["diff"] = "".join(
291
+ unified_diff(
292
+ text_a.splitlines(keepends=True),
293
+ text_b.splitlines(keepends=True),
294
+ fromfile="/dev/null" if a is None else f"{name} @ {label_a}",
295
+ tofile="/dev/null" if b is None else f"{name} @ {label_b}",
296
+ )
297
+ )
298
+ if info["diff"] and not info["diff"].endswith("\n"):
299
+ info["diff"] += "\n"
300
+ diffs.append(info["diff"])
301
+ files[name] = info
302
+
303
+ return {"files": files, "constants_differ": constants, "source_diff": "".join(diffs)}
304
+
305
+
175
306
  def _diff_code(storage_root, snap_a, snap_b) -> dict:
176
307
  """Compare the code behind two runs, using the recorded version hashes.
177
308
 
178
309
  The useful distinction, and the reason code versions exist: *same logic,
179
310
  only a constant differs* is a comparable pair; a changed expression is not.
180
311
  """
312
+ from silloncore.engine import load_run_source
313
+
181
314
  files_a, files_b = _code_files(snap_a), _code_files(snap_b)
182
315
  version_a = snap_a.get("logic_version")
183
316
  version_b = snap_b.get("logic_version")
184
317
 
185
- result = {
318
+ compared = compare_code(
319
+ storage_root, files_a, files_b, snap_a["name"], snap_b["name"],
320
+ main_a=lambda: load_run_source(storage_root, snap_a),
321
+ main_b=lambda: load_run_source(storage_root, snap_b),
322
+ )
323
+ return {
186
324
  "logic_version": (version_a, version_b),
187
325
  "same_logic": bool(version_a) and version_a == version_b,
188
326
  "known": bool(files_a or files_b or version_a or version_b),
189
- "files": {},
190
- "constants_differ": False,
191
- "source_diff": "",
327
+ **compared,
192
328
  }
193
329
 
194
- diffs = []
195
- for name in sorted(set(files_a) | set(files_b)):
196
- a, b = files_a.get(name), files_b.get(name)
197
- if a is None:
198
- result["files"][name] = {"status": "added"}
199
- continue
200
- if b is None:
201
- result["files"][name] = {"status": "removed"}
202
- continue
203
-
204
- if a["logic_hash"] != b["logic_hash"]:
205
- status = "changed"
206
- elif a["ast_hash"] != b["ast_hash"]:
207
- status = "constants" # same program, different literals
208
- result["constants_differ"] = True
209
- elif a["source_hash"] != b["source_hash"]:
210
- status = "cosmetic" # comments or formatting only
211
- else:
212
- status = "same"
213
- result["files"][name] = {"status": status}
214
-
215
- if status in ("changed", "constants"):
216
- text_a = read_source(storage_root, a["source_hash"])
217
- text_b = read_source(storage_root, b["source_hash"])
218
- if text_a is not None and text_b is not None:
219
- diffs.extend(
220
- unified_diff(
221
- text_a.splitlines(keepends=True),
222
- text_b.splitlines(keepends=True),
223
- fromfile=f"{name} @ {snap_a['name']}",
224
- tofile=f"{name} @ {snap_b['name']}",
225
- )
226
- )
227
-
228
- result["source_diff"] = "".join(diffs)
229
- return result
230
-
231
330
 
232
331
  # ==========================================
233
332
  # PAIRWISE
@@ -373,6 +373,8 @@ __all__ = [
373
373
  "print_projects",
374
374
  "print_code_versions",
375
375
  "print_code_version_files",
376
+ "print_code_version_runs",
377
+ "print_code_version_diff",
376
378
  "print_diff",
377
379
  "print_source_diff",
378
380
  "print_diff_across",
@@ -486,6 +488,69 @@ def print_code_version_files(detail: dict) -> None:
486
488
  )
487
489
 
488
490
 
491
+ def print_code_version_runs(detail: dict) -> None:
492
+ """Prints a `silloncore.engine.get_code_version_runs` payload."""
493
+ table = themed_table(padding=(0, 2))
494
+ table.add_column("Run", style=f"bold {c('spray')}", overflow="fold", ratio=1)
495
+ table.add_column("Status")
496
+ table.add_column("Date", style=S_DIM)
497
+ table.add_column("Tags", style=c("wake"))
498
+ for run in detail["runs"]:
499
+ table.add_row(
500
+ Text(run["name"]),
501
+ status_text(run["status"]),
502
+ relative_time(run["date"]) if run["date"] else "—",
503
+ ", ".join(str(t) for t in run["tags"]) or "—",
504
+ )
505
+ count = len(detail["runs"])
506
+ summary = f"{count} run{'s' if count != 1 else ''} used this version"
507
+ if detail.get("partial"):
508
+ summary += " — entry script only"
509
+ subtitle = Text(summary, style=f"italic {c('ember')}")
510
+ console.print(
511
+ themed_panel(
512
+ Group(subtitle, Text(""), table),
513
+ title=f"version · {short_id(detail['logic_version'])}",
514
+ )
515
+ )
516
+
517
+
518
+ _CODE_STATUS = {
519
+ "added": ("added", "#6FCF8E"),
520
+ "removed": ("removed", "#E06C75"),
521
+ "changed": ("logic changed", "#E06C75"),
522
+ "constants": ("constants only", None),
523
+ "cosmetic": ("comments or formatting", None),
524
+ }
525
+
526
+
527
+ def print_code_version_diff(result: dict) -> None:
528
+ """Prints a `silloncore.engine.diff_code_versions` payload: which files
529
+ moved, then the unified source diff."""
530
+ old, new = (short_id(v) for v in result["versions"])
531
+ moved = {n: f for n, f in result["files"].items() if f["status"] != "same"}
532
+ title = f"{old} → {new}"
533
+ if not moved:
534
+ console.print(themed_panel(
535
+ Text("The two versions have the same source.", style=S_DIM), title=title))
536
+ return
537
+
538
+ table = themed_table(padding=(0, 2))
539
+ table.add_column("File", style=f"bold {c('spray')}", overflow="fold", ratio=1)
540
+ table.add_column("Change")
541
+ table.add_column("", style=S_DIM)
542
+ for name, info in moved.items():
543
+ label, colour = _CODE_STATUS.get(info["status"], (info["status"], None))
544
+ note = "source not recorded" if info["missing"] else ""
545
+ table.add_row(Text(name), Text(label, style=colour or c("ember")), note)
546
+ same = len(result["files"]) - len(moved)
547
+ subtitle = Text(f"{same} file(s) unchanged", style=f"italic {c('slate')}")
548
+ if any(result.get("partial") or ()):
549
+ subtitle.append(" — a version recovered by --backfill covers its entry script only")
550
+ console.print(themed_panel(Group(table, Text(""), subtitle), title=title))
551
+ print_source_diff(result["source_diff"])
552
+
553
+
489
554
  def _fmt_delta(pct):
490
555
  if pct is None:
491
556
  return ""
@@ -1453,6 +1453,22 @@ def get_code_versions(engine) -> list:
1453
1453
  return out
1454
1454
 
1455
1455
 
1456
+ def _find_code_version(groups: list, logic_version: str) -> dict:
1457
+ """The one group of `get_code_versions` whose version starts with `logic_version`."""
1458
+ matches = [
1459
+ group
1460
+ for group in groups
1461
+ if group["logic_version"] and group["logic_version"].startswith(logic_version)
1462
+ ]
1463
+ if not matches:
1464
+ raise LookupError(f"No code version matching '{logic_version}'.")
1465
+ if len(matches) > 1:
1466
+ raise LookupError(
1467
+ f"'{logic_version}' matches {len(matches)} code versions — use more characters."
1468
+ )
1469
+ return matches[0]
1470
+
1471
+
1456
1472
  def get_code_version_files(engine, logic_version: str) -> dict:
1457
1473
  """The per-file hashes of one code version.
1458
1474
 
@@ -1466,18 +1482,7 @@ def get_code_version_files(engine, logic_version: str) -> dict:
1466
1482
  Returns:
1467
1483
  dict: `{"logic_version": str, "files": {name: {hashes}}, "run_count": int}`.
1468
1484
  """
1469
- matches = [
1470
- group
1471
- for group in get_code_versions(engine)
1472
- if group["logic_version"] and group["logic_version"].startswith(logic_version)
1473
- ]
1474
- if not matches:
1475
- raise LookupError(f"No code version matching '{logic_version}'.")
1476
- if len(matches) > 1:
1477
- raise LookupError(
1478
- f"'{logic_version}' matches {len(matches)} code versions — use more characters."
1479
- )
1480
- group = matches[0]
1485
+ group = _find_code_version(get_code_versions(engine), logic_version)
1481
1486
  return {
1482
1487
  "logic_version": group["logic_version"],
1483
1488
  "files": group["files"],
@@ -1485,6 +1490,94 @@ def get_code_version_files(engine, logic_version: str) -> dict:
1485
1490
  }
1486
1491
 
1487
1492
 
1493
+ def get_code_version_runs(engine, logic_version: str) -> dict:
1494
+ """Every run that one code version produced, newest first.
1495
+
1496
+ Args:
1497
+ engine (Engine): The active SQLAlchemy database engine.
1498
+ logic_version (str): A full version hash or an unambiguous prefix.
1499
+
1500
+ Raises:
1501
+ LookupError: If no version matches, or a prefix matches several.
1502
+
1503
+ Returns:
1504
+ dict: `{"logic_version", "partial", "files", "runs"}`, where each run
1505
+ is `{"name", "uuid", "date", "status", "tags"}`.
1506
+ """
1507
+ group = _find_code_version(get_code_versions(engine), logic_version)
1508
+ entries = [e for e in select_run_index(engine) if e.get("logic_version") == group["logic_version"]]
1509
+ entries.sort(key=lambda e: e.get("when") or "", reverse=True)
1510
+ return {
1511
+ "logic_version": group["logic_version"],
1512
+ "partial": group["partial"],
1513
+ "files": group["files"],
1514
+ "runs": [
1515
+ {
1516
+ "name": e["name"],
1517
+ "uuid": e["uuid"],
1518
+ "date": e.get("date"),
1519
+ "status": e.get("status"),
1520
+ "tags": list(e.get("tag") or []),
1521
+ }
1522
+ for e in entries
1523
+ ],
1524
+ }
1525
+
1526
+
1527
+ def diff_code_versions(engine, storage_root, version_a: str, version_b: str) -> dict:
1528
+ """The source change between two code versions, file by file.
1529
+
1530
+ Texts come from the project's source store. An entry script logged before
1531
+ the store kept it is read from a run of that version instead.
1532
+
1533
+ Args:
1534
+ engine (Engine): The active SQLAlchemy database engine.
1535
+ storage_root (str | Path): The project storage root.
1536
+ version_a (str): The baseline version (hash or unambiguous prefix).
1537
+ version_b (str): The version compared with it.
1538
+
1539
+ Raises:
1540
+ LookupError: If either version cannot be found unambiguously.
1541
+
1542
+ Returns:
1543
+ dict: `{"versions": (a, b), "partial": (bool, bool)}` plus the keys of
1544
+ `silloncore.diff.compare_code`: `files` (name -> `status`, `diff`,
1545
+ `missing`), `constants_differ` and `source_diff`.
1546
+ """
1547
+ from silloncore.diff import compare_code
1548
+
1549
+ groups = get_code_versions(engine)
1550
+ group_a = _find_code_version(groups, version_a)
1551
+ group_b = _find_code_version(groups, version_b)
1552
+ index = select_run_index(engine)
1553
+
1554
+ def main_of(group):
1555
+ def load():
1556
+ for entry in index:
1557
+ if entry.get("logic_version") == group["logic_version"]:
1558
+ text = load_run_source(storage_root, entry)
1559
+ if text is not None:
1560
+ return text
1561
+ return None
1562
+
1563
+ return load
1564
+
1565
+ compared = compare_code(
1566
+ storage_root,
1567
+ group_a["files"],
1568
+ group_b["files"],
1569
+ group_a["logic_version"][:8],
1570
+ group_b["logic_version"][:8],
1571
+ main_a=main_of(group_a),
1572
+ main_b=main_of(group_b),
1573
+ )
1574
+ return {
1575
+ "versions": (group_a["logic_version"], group_b["logic_version"]),
1576
+ "partial": (group_a["partial"], group_b["partial"]),
1577
+ **compared,
1578
+ }
1579
+
1580
+
1488
1581
  def backfill_code_versions(engine, storage_root, dry_run: bool = False) -> dict:
1489
1582
  """Computes code versions for runs logged before versioning existed.
1490
1583
 
@@ -17,11 +17,12 @@ from silloncommon.database import get_engine, migrate_schema, sqlite_url
17
17
  resolve_storage_root = project_config.resolve_storage_root
18
18
 
19
19
 
20
- def resolve_engine(project_path):
21
- """Connects to a project's SQLite database, wherever it was created.
20
+ def resolve_db_path(project_path) -> Path:
21
+ """Where a project's SQLite database is, wherever it was created.
22
22
 
23
23
  Handles both the default layout (`.sillon/database.sql`) and layouts
24
- produced with a custom storage root.
24
+ produced with a custom storage root. Split from `resolve_engine` so a
25
+ read-only reader (the GUI) opens exactly the file the CLI would.
25
26
 
26
27
  Args:
27
28
  project_path (str | Path): The project root (folder containing `.sillon`).
@@ -30,13 +31,12 @@ def resolve_engine(project_path):
30
31
  FileNotFoundError: If no database can be located for the project.
31
32
 
32
33
  Returns:
33
- Engine: A SQLAlchemy engine connected to the project database.
34
+ Path: The database file.
34
35
  """
35
36
  project_path = Path(project_path).expanduser().resolve()
36
- sillon_dir = project_path / ".sillon"
37
-
38
- if (sillon_dir / "database.sql").exists():
39
- return get_engine(project_path)
37
+ default = project_path / ".sillon" / "database.sql"
38
+ if default.exists():
39
+ return default
40
40
 
41
41
  storage_root = resolve_storage_root(project_path)
42
42
  for candidate in (
@@ -44,11 +44,30 @@ def resolve_engine(project_path):
44
44
  storage_root / ".sillon" / "database.sql",
45
45
  ):
46
46
  if candidate.exists():
47
- return migrate_schema(create_engine(sqlite_url(candidate)))
47
+ return candidate
48
48
 
49
49
  raise FileNotFoundError(f"No sillon database found for project {project_path}")
50
50
 
51
51
 
52
+ def resolve_engine(project_path):
53
+ """Connects to a project's SQLite database, wherever it was created.
54
+
55
+ Args:
56
+ project_path (str | Path): The project root (folder containing `.sillon`).
57
+
58
+ Raises:
59
+ FileNotFoundError: If no database can be located for the project.
60
+
61
+ Returns:
62
+ Engine: A SQLAlchemy engine connected to the project database.
63
+ """
64
+ project_path = Path(project_path).expanduser().resolve()
65
+ db_path = resolve_db_path(project_path)
66
+ if db_path == project_path / ".sillon" / "database.sql":
67
+ return get_engine(project_path)
68
+ return migrate_schema(create_engine(sqlite_url(db_path)))
69
+
70
+
52
71
  def resolve_project_name(project_path) -> str:
53
72
  """The project's own name, as recorded in its config.
54
73