sillon 2.0.2__tar.gz → 2.1.2__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.
- {sillon-2.0.2 → sillon-2.1.2}/PKG-INFO +10 -1
- {sillon-2.0.2 → sillon-2.1.2}/README.md +9 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/common/src/silloncommon/__init__.py +1 -1
- {sillon-2.0.2 → sillon-2.1.2}/packages/common/src/silloncommon/database.py +261 -43
- sillon-2.1.2/packages/common/src/silloncommon/project_config.py +149 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/common/src/silloncommon/registry.py +77 -3
- {sillon-2.0.2 → sillon-2.1.2}/packages/common/src/silloncommon/source_store.py +21 -13
- sillon-2.1.2/packages/common/src/silloncommon/timestamps.py +97 -0
- sillon-2.1.2/packages/core/src/silloncore/bundle.py +398 -0
- sillon-2.1.2/packages/core/src/silloncore/check.py +423 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/core/src/silloncore/diff.py +2 -14
- {sillon-2.0.2 → sillon-2.1.2}/packages/core/src/silloncore/display.py +353 -5
- {sillon-2.0.2 → sillon-2.1.2}/packages/core/src/silloncore/engine.py +231 -26
- {sillon-2.0.2 → sillon-2.1.2}/packages/core/src/silloncore/envhandler.py +43 -105
- {sillon-2.0.2 → sillon-2.1.2}/packages/core/src/silloncore/project_paths.py +7 -29
- sillon-2.1.2/packages/core/src/silloncore/projects.py +216 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/core/src/silloncore/simulation.py +8 -2
- sillon-2.1.2/packages/core/src/silloncore/transfer.py +374 -0
- sillon-2.1.2/packages/interface/cli/src/silloncli/commands/check.py +24 -0
- sillon-2.1.2/packages/interface/cli/src/silloncli/commands/export.py +103 -0
- sillon-2.1.2/packages/interface/cli/src/silloncli/commands/import_cmd.py +87 -0
- sillon-2.1.2/packages/interface/cli/src/silloncli/commands/init.py +71 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/cli/src/silloncli/commands/list.py +3 -2
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/cli/src/silloncli/commands/prune.py +7 -3
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/cli/src/silloncli/commands/report.py +4 -3
- sillon-2.1.2/packages/interface/cli/src/silloncli/context.py +22 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/cli/src/silloncli/main.py +48 -5
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/sillonlab/src/sillonlab/__init__.py +1 -2
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/sillonlab/src/sillonlab/project.py +204 -12
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/sillonlab/src/sillonlab/projects.py +2 -32
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/sillonlab/src/sillonlab/run.py +147 -18
- {sillon-2.0.2 → sillon-2.1.2}/packages/pyapi/src/sillonpy/tracker.py +17 -2
- {sillon-2.0.2 → sillon-2.1.2}/sillon.egg-info/PKG-INFO +10 -1
- {sillon-2.0.2 → sillon-2.1.2}/sillon.egg-info/SOURCES.txt +10 -0
- sillon-2.0.2/packages/core/src/silloncore/projects.py +0 -108
- {sillon-2.0.2 → sillon-2.1.2}/LICENSE +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/common/src/silloncommon/access_log.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/common/src/silloncommon/codeversion.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/common/src/silloncommon/commands.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/common/src/silloncommon/framing.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/common/src/silloncommon/hashing.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/common/src/silloncommon/hdf5_staging.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/common/src/silloncommon/rpcHandler.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/common/src/silloncommon/socket_path.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/common/src/silloncommon/transport.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/common/src/silloncommon/user_paths.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/core/src/silloncore/__init__.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/core/src/silloncore/glob.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/core/src/silloncore/server/__init__.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/core/src/silloncore/server/main.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/core/src/silloncore/server/server.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/core/src/silloncore/server/visitor.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/core/src/silloncore/versioncontrol.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/cli/src/silloncli/__init__.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/cli/src/silloncli/commands/__init__.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/cli/src/silloncli/commands/add.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/cli/src/silloncli/commands/delete.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/cli/src/silloncli/commands/diff.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/cli/src/silloncli/commands/fetch.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/cli/src/silloncli/commands/like.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/cli/src/silloncli/commands/lineage.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/cli/src/silloncli/commands/projects.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/cli/src/silloncli/commands/query.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/cli/src/silloncli/commands/rename.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/cli/src/silloncli/commands/show.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/cli/src/silloncli/commands/trace.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/cli/src/silloncli/commands/versions.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/interface/sillonlab/src/sillonlab/display.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/pyapi/src/sillonpy/__init__.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/pyapi/src/sillonpy/api.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/pyapi/src/sillonpy/daemon.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/pyapi/src/sillonpy/metadata.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/packages/pyapi/src/sillonpy/serverCom.py +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/pyproject.toml +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/setup.cfg +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/sillon.egg-info/dependency_links.txt +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/sillon.egg-info/entry_points.txt +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/sillon.egg-info/requires.txt +0 -0
- {sillon-2.0.2 → sillon-2.1.2}/sillon.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sillon
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.1.2
|
|
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
|
|
@@ -154,6 +154,13 @@ never element by element.
|
|
|
154
154
|
**Files remember their run.** Everything is content-hashed, so
|
|
155
155
|
`sillon trace figures/fit.png` tells you which run produced a file you found.
|
|
156
156
|
|
|
157
|
+
**Runs travel.** `sillon export` writes one file holding everything needed to
|
|
158
|
+
rebuild a set of runs elsewhere — arrays, artifacts, figures, lineage, code
|
|
159
|
+
versions — and `sillon import` adds whatever the project does not already have.
|
|
160
|
+
Union, never overwrite, so importing twice is a no-op and nothing local can be
|
|
161
|
+
lost. On one machine you skip the file entirely: `sillon import ../other-project`,
|
|
162
|
+
or `sillon import --scan ~/Code/phd` to fold in a tree of them.
|
|
163
|
+
|
|
157
164
|
**It stays out of the way.** Zero configuration, a background daemon you never
|
|
158
165
|
start, and heavy arrays offloaded without you thinking about it.
|
|
159
166
|
|
|
@@ -166,6 +173,8 @@ start, and heavy arrays offloaded without you thinking about it.
|
|
|
166
173
|
| [Logging runs](docs/guide/logging.md) | the whole logging API |
|
|
167
174
|
| [Querying and analysis](docs/guide/analysis.md) | working with many runs |
|
|
168
175
|
| [Provenance and lineage](docs/guide/provenance.md) | code versions, automatic lineage, figures, hashes |
|
|
176
|
+
| [Moving runs between machines](docs/guide/transfer.md) | bundles, merging projects, the shared drive |
|
|
177
|
+
| [Working with projects](docs/guide/projects.md) | finding, naming, moving them |
|
|
169
178
|
| [CLI reference](docs/reference/cli.md) | every command |
|
|
170
179
|
| [Troubleshooting](docs/guide/troubleshooting.md) | when something breaks |
|
|
171
180
|
|
|
@@ -113,6 +113,13 @@ never element by element.
|
|
|
113
113
|
**Files remember their run.** Everything is content-hashed, so
|
|
114
114
|
`sillon trace figures/fit.png` tells you which run produced a file you found.
|
|
115
115
|
|
|
116
|
+
**Runs travel.** `sillon export` writes one file holding everything needed to
|
|
117
|
+
rebuild a set of runs elsewhere — arrays, artifacts, figures, lineage, code
|
|
118
|
+
versions — and `sillon import` adds whatever the project does not already have.
|
|
119
|
+
Union, never overwrite, so importing twice is a no-op and nothing local can be
|
|
120
|
+
lost. On one machine you skip the file entirely: `sillon import ../other-project`,
|
|
121
|
+
or `sillon import --scan ~/Code/phd` to fold in a tree of them.
|
|
122
|
+
|
|
116
123
|
**It stays out of the way.** Zero configuration, a background daemon you never
|
|
117
124
|
start, and heavy arrays offloaded without you thinking about it.
|
|
118
125
|
|
|
@@ -125,6 +132,8 @@ start, and heavy arrays offloaded without you thinking about it.
|
|
|
125
132
|
| [Logging runs](docs/guide/logging.md) | the whole logging API |
|
|
126
133
|
| [Querying and analysis](docs/guide/analysis.md) | working with many runs |
|
|
127
134
|
| [Provenance and lineage](docs/guide/provenance.md) | code versions, automatic lineage, figures, hashes |
|
|
135
|
+
| [Moving runs between machines](docs/guide/transfer.md) | bundles, merging projects, the shared drive |
|
|
136
|
+
| [Working with projects](docs/guide/projects.md) | finding, naming, moving them |
|
|
128
137
|
| [CLI reference](docs/reference/cli.md) | every command |
|
|
129
138
|
| [Troubleshooting](docs/guide/troubleshooting.md) | when something breaks |
|
|
130
139
|
|
|
@@ -16,7 +16,7 @@ from sqlmodel import (
|
|
|
16
16
|
from sqlalchemy import Column, event
|
|
17
17
|
from sqlalchemy.types import JSON
|
|
18
18
|
from sqlalchemy.engine import Engine
|
|
19
|
-
from sqlalchemy.exc import OperationalError
|
|
19
|
+
from sqlalchemy.exc import IntegrityError, OperationalError
|
|
20
20
|
from sqlalchemy.orm.attributes import flag_modified
|
|
21
21
|
|
|
22
22
|
if TYPE_CHECKING:
|
|
@@ -28,6 +28,7 @@ if TYPE_CHECKING:
|
|
|
28
28
|
# ==========================================
|
|
29
29
|
|
|
30
30
|
from silloncommon import __version__ as sillon_VERSION
|
|
31
|
+
from silloncommon import timestamps
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
def _configure_sqlite_connection(dbapi_connection, _connection_record):
|
|
@@ -61,12 +62,118 @@ def make_engine(db_path) -> Engine:
|
|
|
61
62
|
return engine
|
|
62
63
|
|
|
63
64
|
|
|
65
|
+
# Bumped when the schema gains something a reader needs. Stored in the file
|
|
66
|
+
# header via `PRAGMA user_version`, so it costs no table and no ORM model.
|
|
67
|
+
# 0 legacy — anything written before the pragma was set
|
|
68
|
+
# 1 the 2.0 schema (parents, logic_version, figure and analysis tables)
|
|
69
|
+
# 2 started_at, and a unique index on uuid
|
|
70
|
+
SCHEMA_VERSION = 2
|
|
71
|
+
|
|
72
|
+
# One run must not appear twice. uuid is client-side uuid4, so a collision is
|
|
73
|
+
# not the worry — importing the same run twice is. Readers take `.first()`, so
|
|
74
|
+
# a duplicate becomes an invisible shadow row that the index and query paths
|
|
75
|
+
# nonetheless count. Named apart from `ix_simulationtable_uuid` because that
|
|
76
|
+
# one already exists non-unique in every project, and `checkfirst` matches on
|
|
77
|
+
# the name, so reusing it would silently skip the uniqueness.
|
|
78
|
+
UUID_UNIQUE_INDEX = "ix_simulationtable_uuid_unique"
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def schema_version(engine: Engine) -> int:
|
|
82
|
+
"""The schema version recorded in a database file, or 0 if none is."""
|
|
83
|
+
try:
|
|
84
|
+
with engine.connect() as conn:
|
|
85
|
+
return int(conn.exec_driver_sql("PRAGMA user_version").scalar() or 0)
|
|
86
|
+
except (OperationalError, TypeError, ValueError):
|
|
87
|
+
return 0
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _add_missing_columns(conn) -> None:
|
|
91
|
+
"""ALTER in any column the ORM declares and the file lacks.
|
|
92
|
+
|
|
93
|
+
Covers all four tables. It used to cover `simulationtable` only, so a
|
|
94
|
+
column added to artifacts, figures or analyses was never backfilled into an
|
|
95
|
+
existing project — `create_all` skips a table that is already there.
|
|
96
|
+
"""
|
|
97
|
+
for table in SQLModel.metadata.tables.values():
|
|
98
|
+
rows = list(conn.exec_driver_sql(f"PRAGMA table_info({table.name})"))
|
|
99
|
+
if not rows:
|
|
100
|
+
continue # create_all() just made it, so it is current
|
|
101
|
+
existing = {row[1] for row in rows}
|
|
102
|
+
for col in table.columns:
|
|
103
|
+
if col.name in existing:
|
|
104
|
+
continue
|
|
105
|
+
coltype = "JSON" if isinstance(col.type, JSON) else "TEXT"
|
|
106
|
+
conn.exec_driver_sql(
|
|
107
|
+
f"ALTER TABLE {table.name} ADD COLUMN {col.name} {coltype}"
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _create_indexes(engine: Engine) -> None:
|
|
112
|
+
"""Create every declared index, plus the uuid uniqueness guard.
|
|
113
|
+
|
|
114
|
+
`create_all()` skips a table that already exists and skips its indexes with
|
|
115
|
+
it, so an existing project never picks up a newly declared index unless it
|
|
116
|
+
is created explicitly.
|
|
117
|
+
|
|
118
|
+
Each index gets its own transaction: the unique one fails on a database
|
|
119
|
+
that already holds duplicate uuids, and that must not take the others down
|
|
120
|
+
with it. `sillon check` is where those duplicates get reported.
|
|
121
|
+
"""
|
|
122
|
+
for table in SQLModel.metadata.tables.values():
|
|
123
|
+
for index in table.indexes:
|
|
124
|
+
try:
|
|
125
|
+
with engine.begin() as conn:
|
|
126
|
+
index.create(bind=conn, checkfirst=True)
|
|
127
|
+
except (OperationalError, IntegrityError):
|
|
128
|
+
pass
|
|
129
|
+
|
|
130
|
+
try:
|
|
131
|
+
with engine.begin() as conn:
|
|
132
|
+
conn.exec_driver_sql(
|
|
133
|
+
f"CREATE UNIQUE INDEX IF NOT EXISTS {UUID_UNIQUE_INDEX} "
|
|
134
|
+
"ON simulationtable (uuid)"
|
|
135
|
+
)
|
|
136
|
+
except (OperationalError, IntegrityError):
|
|
137
|
+
pass
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _backfill_started_at(conn) -> None:
|
|
141
|
+
"""Give older runs an offset-aware timestamp derived from their `date`.
|
|
142
|
+
|
|
143
|
+
The offset used is the one this machine had *on that date*, so a summer run
|
|
144
|
+
keeps its summer offset. That is a guess — the run may have been logged
|
|
145
|
+
elsewhere — but it is the only information the row carries, and it is right
|
|
146
|
+
for the overwhelmingly common case of a project that has only ever lived
|
|
147
|
+
here. Runs imported from another machine arrive with a real `started_at`.
|
|
148
|
+
"""
|
|
149
|
+
probe = conn.exec_driver_sql(
|
|
150
|
+
"SELECT 1 FROM simulationtable WHERE started_at IS NULL LIMIT 1"
|
|
151
|
+
).first()
|
|
152
|
+
if probe is None:
|
|
153
|
+
return
|
|
154
|
+
|
|
155
|
+
rows = conn.exec_driver_sql(
|
|
156
|
+
"SELECT id, date FROM simulationtable WHERE started_at IS NULL"
|
|
157
|
+
).fetchall()
|
|
158
|
+
for row_id, date_str in rows:
|
|
159
|
+
moment = timestamps.to_aware(date_str)
|
|
160
|
+
if moment is None:
|
|
161
|
+
continue
|
|
162
|
+
conn.exec_driver_sql(
|
|
163
|
+
"UPDATE simulationtable SET started_at = ? WHERE id = ?",
|
|
164
|
+
(moment.isoformat(timespec="seconds"), row_id),
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
|
|
64
168
|
def migrate_schema(engine: Engine) -> Engine:
|
|
65
169
|
"""Brings an existing database up to the current schema, idempotently.
|
|
66
170
|
|
|
67
|
-
Creates
|
|
68
|
-
|
|
69
|
-
|
|
171
|
+
Creates missing tables, adds any column the ORM declares and the file
|
|
172
|
+
lacks, creates the declared indexes, backfills `started_at`, and records
|
|
173
|
+
the schema version so a reader can tell what it is looking at.
|
|
174
|
+
|
|
175
|
+
Best-effort throughout: a database that cannot be migrated — read-only
|
|
176
|
+
media, a pre-existing duplicate blocking an index — must still open.
|
|
70
177
|
|
|
71
178
|
Args:
|
|
72
179
|
engine (Engine): The SQLAlchemy engine to migrate.
|
|
@@ -75,28 +182,30 @@ def migrate_schema(engine: Engine) -> Engine:
|
|
|
75
182
|
Engine: The same engine (for chaining).
|
|
76
183
|
"""
|
|
77
184
|
SQLModel.metadata.create_all(engine)
|
|
185
|
+
|
|
78
186
|
try:
|
|
79
187
|
with engine.begin() as conn:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
188
|
+
_add_missing_columns(conn)
|
|
189
|
+
except OperationalError:
|
|
190
|
+
pass
|
|
191
|
+
|
|
192
|
+
_create_indexes(engine)
|
|
193
|
+
|
|
194
|
+
try:
|
|
195
|
+
with engine.begin() as conn:
|
|
196
|
+
_backfill_started_at(conn)
|
|
197
|
+
except OperationalError:
|
|
198
|
+
pass
|
|
199
|
+
|
|
200
|
+
# Never downgrade the marker: a file written by a newer sillon keeps its
|
|
201
|
+
# version, so that sillon can still tell this one touched it.
|
|
202
|
+
try:
|
|
203
|
+
if schema_version(engine) < SCHEMA_VERSION:
|
|
204
|
+
with engine.begin() as conn:
|
|
205
|
+
conn.exec_driver_sql(f"PRAGMA user_version = {SCHEMA_VERSION}")
|
|
98
206
|
except OperationalError:
|
|
99
|
-
pass
|
|
207
|
+
pass
|
|
208
|
+
|
|
100
209
|
return engine
|
|
101
210
|
|
|
102
211
|
|
|
@@ -173,6 +282,11 @@ class SimulationTable(SQLModel, table=True):
|
|
|
173
282
|
uuid: str = Field(index=True)
|
|
174
283
|
name: str = Field(index=True)
|
|
175
284
|
date: Optional[str] = Field(default=None, index=True)
|
|
285
|
+
# The same instant as `date`, but ISO-8601 with an offset. `date` is naive
|
|
286
|
+
# local time, which sorts correctly only within one machine: merge two and
|
|
287
|
+
# a 14:00 in Paris sorts after a 13:00 in Boston that happened four hours
|
|
288
|
+
# later. `date` stays as the thing people read; this is what orders them.
|
|
289
|
+
started_at: Optional[str] = Field(default=None, index=True)
|
|
176
290
|
|
|
177
291
|
# JSON Data Columns
|
|
178
292
|
parameters: Dict[str, Any] = Field(default_factory=dict, sa_column=Column(JSON))
|
|
@@ -432,6 +546,7 @@ def insert_simulation(run: "Simulation", session: Session) -> SimulationTable:
|
|
|
432
546
|
uuid=run.run_id,
|
|
433
547
|
name=run.run_name,
|
|
434
548
|
date=run.date,
|
|
549
|
+
started_at=getattr(run, "started_at", None),
|
|
435
550
|
parameters=run.parameters,
|
|
436
551
|
results=clean_results,
|
|
437
552
|
meta_data=run.metadata,
|
|
@@ -446,7 +561,10 @@ def insert_simulation(run: "Simulation", session: Session) -> SimulationTable:
|
|
|
446
561
|
hashes=asdict(run.hashes),
|
|
447
562
|
organisation=run.organisation,
|
|
448
563
|
project=run.project_name,
|
|
449
|
-
|
|
564
|
+
# The version that produced the run. An import must carry the original
|
|
565
|
+
# rather than restamping with the importing machine's, or the record of
|
|
566
|
+
# which sillon actually wrote the run is destroyed.
|
|
567
|
+
sillonversion=getattr(run, "sillonversion", None) or sillon_VERSION,
|
|
450
568
|
status=run.status,
|
|
451
569
|
logic_version=getattr(run, "logic_version", None),
|
|
452
570
|
runtime=run.runtime,
|
|
@@ -463,6 +581,71 @@ def insert_simulation(run: "Simulation", session: Session) -> SimulationTable:
|
|
|
463
581
|
return table
|
|
464
582
|
|
|
465
583
|
|
|
584
|
+
# The columns a run row owns. `id` is excluded on purpose: it is a machine-local
|
|
585
|
+
# autoincrement rowid and the child tables point at it, so an imported run must
|
|
586
|
+
# be given a fresh one rather than carrying the one it had elsewhere.
|
|
587
|
+
_RUN_COLUMNS = tuple(
|
|
588
|
+
col.name for col in SimulationTable.__table__.columns if col.name != "id"
|
|
589
|
+
)
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
def insert_imported_run(
|
|
593
|
+
record: Dict[str, Any], session: Session, name: str = None
|
|
594
|
+
) -> SimulationTable:
|
|
595
|
+
"""Inserts a run that was produced somewhere else, as it was.
|
|
596
|
+
|
|
597
|
+
The sibling of `insert_simulation`, which is duck-typed on a live
|
|
598
|
+
`Simulation` and therefore cannot be used here: `Simulation.__init__`
|
|
599
|
+
stamps `date = now()` and mints a name, so a run inserted through it loses
|
|
600
|
+
the identity it is supposed to be keeping.
|
|
601
|
+
|
|
602
|
+
Everything the row carried is preserved -- uuid, both timestamps, status,
|
|
603
|
+
runtime, hostname, author and the sillon version that wrote it -- except
|
|
604
|
+
the integer primary keys, which are machine-local. Child rows are attached
|
|
605
|
+
through the relationship, so SQLAlchemy assigns each a fresh `run_id` on
|
|
606
|
+
commit, exactly as it does for a freshly logged run.
|
|
607
|
+
|
|
608
|
+
Unknown keys in `record` are ignored rather than raising, so a bundle
|
|
609
|
+
written by a newer sillon imports its fields that this one understands and
|
|
610
|
+
says so, instead of refusing outright.
|
|
611
|
+
|
|
612
|
+
Args:
|
|
613
|
+
record (dict): `{"run": {...}, "artifacts": [...], "figures": [...],
|
|
614
|
+
"analyses": [...]}`, as `select_run_snapshot` produces it.
|
|
615
|
+
session (Session): The active session. Not committed here -- the caller
|
|
616
|
+
owns the transaction, so a whole import succeeds or fails together.
|
|
617
|
+
name (str, optional): A replacement name, for when the original
|
|
618
|
+
collides with a local run. Defaults to the recorded name.
|
|
619
|
+
|
|
620
|
+
Returns:
|
|
621
|
+
SimulationTable: The pending row, added to the session.
|
|
622
|
+
"""
|
|
623
|
+
run = dict(record.get("run") or {})
|
|
624
|
+
fields = {key: run.get(key) for key in _RUN_COLUMNS if key in run}
|
|
625
|
+
if name is not None:
|
|
626
|
+
fields["name"] = name
|
|
627
|
+
|
|
628
|
+
def _children(table, rows):
|
|
629
|
+
out = []
|
|
630
|
+
for row in rows or []:
|
|
631
|
+
payload = {
|
|
632
|
+
col.name: row.get(col.name)
|
|
633
|
+
for col in table.__table__.columns
|
|
634
|
+
if col.name in row and col.name not in ("id", "run_id")
|
|
635
|
+
}
|
|
636
|
+
out.append(table(**payload))
|
|
637
|
+
return out
|
|
638
|
+
|
|
639
|
+
table = SimulationTable(
|
|
640
|
+
**fields,
|
|
641
|
+
artifacts=_children(ArtifactTable, record.get("artifacts")),
|
|
642
|
+
figures=_children(FigureTable, record.get("figures")),
|
|
643
|
+
analyses=_children(AnalysisTable, record.get("analyses")),
|
|
644
|
+
)
|
|
645
|
+
session.add(table)
|
|
646
|
+
return table
|
|
647
|
+
|
|
648
|
+
|
|
466
649
|
# ==========================================
|
|
467
650
|
# DATA STRUCTURES & PARSERS
|
|
468
651
|
# ==========================================
|
|
@@ -1007,10 +1190,14 @@ def select_metadata_all(engine: Engine) -> Sequence[Any]:
|
|
|
1007
1190
|
return session.exec(select(SimulationTable.meta_data)).all()
|
|
1008
1191
|
|
|
1009
1192
|
|
|
1010
|
-
def select_uuids(engine: Engine) ->
|
|
1011
|
-
"""
|
|
1193
|
+
def select_uuids(engine: Engine) -> set:
|
|
1194
|
+
"""Every run uuid in the database.
|
|
1195
|
+
|
|
1196
|
+
Also the set an import dedups against: a uuid already here means that run
|
|
1197
|
+
is already here, so importing it again is a no-op rather than a duplicate.
|
|
1198
|
+
"""
|
|
1012
1199
|
with Session(engine) as session:
|
|
1013
|
-
return session.exec(select(SimulationTable.uuid)).all()
|
|
1200
|
+
return set(session.exec(select(SimulationTable.uuid)).all())
|
|
1014
1201
|
|
|
1015
1202
|
|
|
1016
1203
|
def select_run_index(engine: Engine) -> List[Dict[str, Any]]:
|
|
@@ -1058,6 +1245,11 @@ def select_run_index(engine: Engine) -> List[Dict[str, Any]]:
|
|
|
1058
1245
|
"uuid": run.uuid,
|
|
1059
1246
|
"name": run.name,
|
|
1060
1247
|
"date": run.date,
|
|
1248
|
+
"started_at": run.started_at,
|
|
1249
|
+
# Chronological and timezone-correct, unlike `date`, which
|
|
1250
|
+
# is naive local time. Precomputed here because every
|
|
1251
|
+
# caller that sorts or bounds by time wants the same key.
|
|
1252
|
+
"when": timestamps.sort_key(run.date, run.started_at),
|
|
1061
1253
|
"status": run.status,
|
|
1062
1254
|
"logic_version": run.logic_version,
|
|
1063
1255
|
"author": run.author,
|
|
@@ -1091,7 +1283,8 @@ def select_run_identities(engine: Engine) -> List[Dict[str, Any]]:
|
|
|
1091
1283
|
engine (Engine): The SQLAlchemy engine.
|
|
1092
1284
|
|
|
1093
1285
|
Returns:
|
|
1094
|
-
List[dict]: One `{id, name, uuid, date}` per run
|
|
1286
|
+
List[dict]: One `{id, name, uuid, date, started_at, when}` per run,
|
|
1287
|
+
where `when` is the timezone-correct sort key.
|
|
1095
1288
|
"""
|
|
1096
1289
|
with Session(engine) as session:
|
|
1097
1290
|
rows = session.exec(
|
|
@@ -1100,11 +1293,19 @@ def select_run_identities(engine: Engine) -> List[Dict[str, Any]]:
|
|
|
1100
1293
|
SimulationTable.name,
|
|
1101
1294
|
SimulationTable.uuid,
|
|
1102
1295
|
SimulationTable.date,
|
|
1296
|
+
SimulationTable.started_at,
|
|
1103
1297
|
)
|
|
1104
1298
|
).all()
|
|
1105
1299
|
return [
|
|
1106
|
-
{
|
|
1107
|
-
|
|
1300
|
+
{
|
|
1301
|
+
"id": run_id,
|
|
1302
|
+
"name": name,
|
|
1303
|
+
"uuid": uuid,
|
|
1304
|
+
"date": date,
|
|
1305
|
+
"started_at": started_at,
|
|
1306
|
+
"when": timestamps.sort_key(date, started_at),
|
|
1307
|
+
}
|
|
1308
|
+
for run_id, name, uuid, date, started_at in rows
|
|
1108
1309
|
]
|
|
1109
1310
|
|
|
1110
1311
|
|
|
@@ -1146,12 +1347,39 @@ def db_delete_runs(engine: Engine, identifiers: List[str]) -> List[str]:
|
|
|
1146
1347
|
return deleted
|
|
1147
1348
|
|
|
1148
1349
|
|
|
1350
|
+
def resolve_available_name(name: str, existing) -> str:
|
|
1351
|
+
"""The first free name in the series `name`, `name_2`, `name_3`, ...
|
|
1352
|
+
|
|
1353
|
+
The pure half of `next_available_name`, so a caller holding many names to
|
|
1354
|
+
place — an import — can fetch the taken set once instead of querying per
|
|
1355
|
+
run.
|
|
1356
|
+
|
|
1357
|
+
Args:
|
|
1358
|
+
name (str): The desired base name.
|
|
1359
|
+
existing (set[str]): Names already taken.
|
|
1360
|
+
|
|
1361
|
+
Returns:
|
|
1362
|
+
str: A name not in `existing`.
|
|
1363
|
+
"""
|
|
1364
|
+
if name not in existing:
|
|
1365
|
+
return name
|
|
1366
|
+
index = 2
|
|
1367
|
+
while f"{name}_{index}" in existing:
|
|
1368
|
+
index += 1
|
|
1369
|
+
return f"{name}_{index}"
|
|
1370
|
+
|
|
1371
|
+
|
|
1372
|
+
def select_names(engine: Engine) -> set:
|
|
1373
|
+
"""Every run name in the database."""
|
|
1374
|
+
with Session(engine) as session:
|
|
1375
|
+
return set(session.exec(select(SimulationTable.name)).all())
|
|
1376
|
+
|
|
1377
|
+
|
|
1149
1378
|
def next_available_name(engine: Engine, name: str, taken: Sequence[str] = ()) -> str:
|
|
1150
1379
|
"""Returns a unique run name, appending an increment on collision.
|
|
1151
1380
|
|
|
1152
1381
|
A name is considered taken if it already exists in the database or appears
|
|
1153
|
-
in `taken` (in-flight runs not yet committed).
|
|
1154
|
-
series `name`, `name_2`, `name_3`, ... is returned.
|
|
1382
|
+
in `taken` (in-flight runs not yet committed).
|
|
1155
1383
|
|
|
1156
1384
|
Args:
|
|
1157
1385
|
engine (Engine): The SQLAlchemy engine.
|
|
@@ -1162,17 +1390,7 @@ def next_available_name(engine: Engine, name: str, taken: Sequence[str] = ()) ->
|
|
|
1162
1390
|
Returns:
|
|
1163
1391
|
str: A run name guaranteed not to collide with existing or in-flight runs.
|
|
1164
1392
|
"""
|
|
1165
|
-
|
|
1166
|
-
existing = set(session.exec(select(SimulationTable.name)).all())
|
|
1167
|
-
existing.update(taken)
|
|
1168
|
-
|
|
1169
|
-
if name not in existing:
|
|
1170
|
-
return name
|
|
1171
|
-
|
|
1172
|
-
index = 2
|
|
1173
|
-
while f"{name}_{index}" in existing:
|
|
1174
|
-
index += 1
|
|
1175
|
-
return f"{name}_{index}"
|
|
1393
|
+
return resolve_available_name(name, select_names(engine) | set(taken))
|
|
1176
1394
|
|
|
1177
1395
|
|
|
1178
1396
|
# ==========================================
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"""`.sillon/config.toml` — the one place that reads and writes it.
|
|
2
|
+
|
|
3
|
+
Three modules used to parse this file independently: the daemon's two
|
|
4
|
+
environment handlers and `silloncore.project_paths`. They disagreed. The
|
|
5
|
+
daemon honoured `[storage].storage_root`, the readers had the same lines
|
|
6
|
+
commented out and always assumed `.sillon`, so moving a project left readers
|
|
7
|
+
working while the next run the daemon logged wrote its data to the old path.
|
|
8
|
+
|
|
9
|
+
It lives in `silloncommon` because all three sides need the same answer: the
|
|
10
|
+
client (`sillonpy`) writes staged arrays and source text, the daemon writes
|
|
11
|
+
runs, and the interfaces (`silloncli`, `sillonlab`) read them.
|
|
12
|
+
|
|
13
|
+
The storage root is stored **relative to the project root whenever it is
|
|
14
|
+
inside it**, so copying or moving a project does not invalidate it. An
|
|
15
|
+
external root — heavy data on a different disk — is necessarily absolute and
|
|
16
|
+
does not travel; `resolve_storage_root` falls back rather than pointing at a
|
|
17
|
+
path that is not there, and `sillon check` reports it.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
|
|
22
|
+
import toml
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"SILLON_DIR",
|
|
26
|
+
"config_path",
|
|
27
|
+
"find_project_root",
|
|
28
|
+
"read_config",
|
|
29
|
+
"write_config",
|
|
30
|
+
"resolve_storage_root",
|
|
31
|
+
"store_storage_root",
|
|
32
|
+
"project_id",
|
|
33
|
+
"project_name",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
SILLON_DIR = ".sillon"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def sillon_dir(project_path) -> Path:
|
|
40
|
+
"""The `.sillon` directory of a project."""
|
|
41
|
+
return Path(project_path).expanduser().resolve() / SILLON_DIR
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def config_path(project_path) -> Path:
|
|
45
|
+
"""Where a project's config lives."""
|
|
46
|
+
return sillon_dir(project_path) / "config.toml"
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def read_config(project_path) -> dict:
|
|
50
|
+
"""The project's config, or `{}` when there is none or it is unreadable.
|
|
51
|
+
|
|
52
|
+
A corrupt config must not stop a run from being logged, so this never
|
|
53
|
+
raises — the callers all have a sensible default.
|
|
54
|
+
"""
|
|
55
|
+
try:
|
|
56
|
+
return toml.load(config_path(project_path))
|
|
57
|
+
except (OSError, toml.TomlDecodeError):
|
|
58
|
+
return {}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def write_config(project_path, config: dict) -> None:
|
|
62
|
+
"""Replace a project's config."""
|
|
63
|
+
target = config_path(project_path)
|
|
64
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
65
|
+
with open(target, "w", encoding="utf-8") as handle:
|
|
66
|
+
toml.dump(config, handle)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def store_storage_root(project_path, storage_root) -> str:
|
|
70
|
+
"""How a storage root should be written into the config.
|
|
71
|
+
|
|
72
|
+
Relative to the project root when it is inside it (so the project can be
|
|
73
|
+
moved or copied), absolute otherwise. POSIX separators, so a config
|
|
74
|
+
written on Windows still reads on macOS.
|
|
75
|
+
"""
|
|
76
|
+
project_path = Path(project_path).expanduser().resolve()
|
|
77
|
+
storage_root = Path(storage_root).expanduser().resolve()
|
|
78
|
+
try:
|
|
79
|
+
return storage_root.relative_to(project_path).as_posix()
|
|
80
|
+
except ValueError:
|
|
81
|
+
return str(storage_root)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def resolve_storage_root(project_path) -> Path:
|
|
85
|
+
"""The folder holding a project's `glob`, `artifact` and `figure` dirs.
|
|
86
|
+
|
|
87
|
+
Reads `[storage].storage_root`, resolving a relative value against the
|
|
88
|
+
project root. Defaults to `.sillon`.
|
|
89
|
+
|
|
90
|
+
A recorded root that no longer exists is ignored in favour of `.sillon` —
|
|
91
|
+
that is a project which was moved while its data was on another disk, and
|
|
92
|
+
answering with the old path would only produce confusing errors further
|
|
93
|
+
in. `sillon check` is where that gets reported.
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
project_path (str | Path): The project root (the folder with `.sillon`).
|
|
97
|
+
|
|
98
|
+
Returns:
|
|
99
|
+
Path: The resolved storage root.
|
|
100
|
+
"""
|
|
101
|
+
project_path = Path(project_path).expanduser().resolve()
|
|
102
|
+
default = project_path / SILLON_DIR
|
|
103
|
+
|
|
104
|
+
recorded = (read_config(project_path).get("storage") or {}).get("storage_root")
|
|
105
|
+
if not recorded:
|
|
106
|
+
return default
|
|
107
|
+
|
|
108
|
+
root = Path(recorded).expanduser()
|
|
109
|
+
if not root.is_absolute():
|
|
110
|
+
root = project_path / root
|
|
111
|
+
root = root.resolve()
|
|
112
|
+
|
|
113
|
+
if root == default or root.exists():
|
|
114
|
+
return root
|
|
115
|
+
return default
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def project_id(project_path) -> str:
|
|
119
|
+
"""The project's own id, stable across copies. `""` when unknown."""
|
|
120
|
+
return (read_config(project_path).get("Environment") or {}).get("project_id") or ""
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def project_name(project_path) -> str:
|
|
124
|
+
"""The project's own name, as recorded in its config. `""` when unset."""
|
|
125
|
+
return (read_config(project_path).get("Environment") or {}).get("project_name") or ""
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def find_project_root(start=None):
|
|
129
|
+
"""The project a path is inside, searching upward. None if there is none.
|
|
130
|
+
|
|
131
|
+
Like git: standing in `analysis/figures/` should work, because that is
|
|
132
|
+
where you are when you want to look something up. Stops at the filesystem
|
|
133
|
+
root, and at a mount point only in the sense that it will keep walking --
|
|
134
|
+
a project above a mount is still your project.
|
|
135
|
+
|
|
136
|
+
Args:
|
|
137
|
+
start (str | Path, optional): Where to start. Defaults to the current
|
|
138
|
+
directory.
|
|
139
|
+
|
|
140
|
+
Returns:
|
|
141
|
+
Path | None: The project root, or None if no ancestor has `.sillon/`.
|
|
142
|
+
"""
|
|
143
|
+
current = Path(start or Path.cwd()).expanduser().resolve()
|
|
144
|
+
if current.is_file():
|
|
145
|
+
current = current.parent
|
|
146
|
+
for candidate in (current, *current.parents):
|
|
147
|
+
if (candidate / SILLON_DIR).is_dir():
|
|
148
|
+
return candidate
|
|
149
|
+
return None
|