lightcone-cli 0.6.0rc1__tar.gz → 0.6.0rc2__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 (54) hide show
  1. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/PKG-INFO +1 -1
  2. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/cli/commands.py +31 -12
  3. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/dataset.py +6 -1
  4. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/github.py +24 -3
  5. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/materialize.py +30 -24
  6. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/plan.py +3 -4
  7. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/project.py +2 -1
  8. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/publish.py +67 -22
  9. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/sandbox/policy.py +48 -50
  10. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/worker.py +1 -1
  11. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/.gitignore +0 -0
  12. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/LICENSE +0 -0
  13. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/README.md +0 -0
  14. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/pyproject.toml +0 -0
  15. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/_sandbox_exec.py +0 -0
  16. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/cli/__init__.py +0 -0
  17. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/cli/compute.py +0 -0
  18. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/__init__.py +0 -0
  19. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/commits.py +0 -0
  20. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/compute/__init__.py +0 -0
  21. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/compute/catalog.py +0 -0
  22. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/compute/local.py +0 -0
  23. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/compute/local_runtime.py +0 -0
  24. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/compute/model.py +0 -0
  25. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/compute/output.py +0 -0
  26. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/compute/runtime.py +0 -0
  27. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/compute/slurm.py +0 -0
  28. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/compute/slurm_bootstrap.py +0 -0
  29. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/container.py +0 -0
  30. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/content.py +0 -0
  31. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/execution_resources.py +0 -0
  32. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/identity.py +0 -0
  33. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/image.py +0 -0
  34. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/run.py +0 -0
  35. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/sandbox/__init__.py +0 -0
  36. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/sandbox/boundary.py +0 -0
  37. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/sandbox/denial.py +0 -0
  38. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/sandbox/landlock.py +0 -0
  39. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/sandbox/model.py +0 -0
  40. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/sandbox/oci.py +0 -0
  41. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/sandbox/profiles/base.sbpl +0 -0
  42. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/sandbox/profiles/network.sbpl +0 -0
  43. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/sandbox/profiles/platform-defaults.sbpl +0 -0
  44. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/sandbox/seatbelt.py +0 -0
  45. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/templates/__init__.py +0 -0
  46. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/templates/files/data-README.md.tmpl +0 -0
  47. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/templates/files/datalad-config.tmpl +0 -0
  48. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/templates/files/gitattributes.tmpl +0 -0
  49. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/templates/files/gitignore.tmpl +0 -0
  50. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/templates/files/index.md.tmpl +0 -0
  51. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/templates/files/myst.yml.tmpl +0 -0
  52. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/templates/files/pyproject.toml.tmpl +0 -0
  53. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/templates/files/results-README.md.tmpl +0 -0
  54. {lightcone_cli-0.6.0rc1 → lightcone_cli-0.6.0rc2}/src/lightcone/engine/units.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: lightcone-cli
3
- Version: 0.6.0rc1
3
+ Version: 0.6.0rc2
4
4
  Summary: Lightcone Research's agentic execution layer
5
5
  Project-URL: Repository, https://github.com/LightconeResearch/lightcone-cli
6
6
  Author: Lightcone Research
@@ -6,6 +6,7 @@ from __future__ import annotations
6
6
  import functools
7
7
  import json
8
8
  import logging
9
+ import shlex
9
10
  import sys
10
11
  from collections.abc import Iterable
11
12
  from pathlib import Path
@@ -140,7 +141,8 @@ def init(directory: Path, check_only: bool, as_json: bool) -> None:
140
141
  """Converge DIRECTORY into a standard Lightcone project (idempotent).
141
142
 
142
143
  Safe to re-run at any time: creates whatever is missing, repairs the
143
- pieces lightcone manages, and never overwrites files you own.
144
+ pieces lightcone manages, and never overwrites files you own. Changes
145
+ are not committed: review and commit the project files before publishing.
144
146
 
145
147
  In a clone it sets up git-annex, which enables the store the project
146
148
  declares for its data, so `lc fetch` works from there. It creates
@@ -163,10 +165,15 @@ def init(directory: Path, check_only: bool, as_json: bool) -> None:
163
165
  else:
164
166
  _render_init_output(report, directory, dry_run=check_only)
165
167
  if write and not report.blocked and not report.online:
168
+ # `lc publish` publishes the current directory, which the project
169
+ # just converged need not be.
170
+ cd = "" if directory == Path.cwd().resolve() else (
171
+ f"cd -- {shlex.quote(str(directory))} && "
172
+ )
166
173
  click.echo(
167
- "\n Not online yet. To back it up and share it, choose who can read it:\n"
168
- f" lc publish github.com/OWNER/{directory.name} --private\n"
169
- f" lc publish github.com/OWNER/{directory.name} --public"
174
+ "\n Not online yet. Commit any project changes, then choose who can read it:\n"
175
+ f" {cd}lc publish github.com/OWNER/{directory.name} --private\n"
176
+ f" {cd}lc publish github.com/OWNER/{directory.name} --public"
170
177
  )
171
178
 
172
179
  if check_only and not report.converged:
@@ -353,8 +360,8 @@ def build(as_json: bool) -> None:
353
360
  "--refresh",
354
361
  is_flag=True,
355
362
  help=(
356
- "Also remake results that are behind — still what the analysis "
357
- "asks for, but made under an earlier environment."
363
+ "Remake the requested results even when current; without targets, "
364
+ "remake every result. Dependencies are remade only where stale or missing."
358
365
  ),
359
366
  )
360
367
  @click.option(
@@ -387,9 +394,11 @@ def materialize(
387
394
  otherwise.
388
395
 
389
396
  A result made under an earlier environment is reported as behind and
390
- left alone: it is still what the analysis asks for, and its record
391
- names the environment and the commit that produced it. Pass
392
- --refresh to remake those too.
397
+ left alone. Pass --refresh to remake the targets regardless of their
398
+ state, or every result without targets. This also reruns a result
399
+ after editing a script the analysis does not declare as an input.
400
+ Dependencies are remade only where stale or missing, unless they
401
+ are also targets.
393
402
  """
394
403
  from lightcone.engine import container as engine_container
395
404
  from lightcone.engine import materialize as engine
@@ -443,7 +452,7 @@ def materialize(
443
452
  else:
444
453
  if report.notes:
445
454
  click.echo("\n".join(["", *report.notes]), err=True)
446
- _render_materialize_output(report, root, dry_run=check_only)
455
+ _render_materialize_output(report, root, dry_run=check_only, refresh=refresh)
447
456
 
448
457
  if not report.ok or (check_only and not report.up_to_date):
449
458
  sys.exit(1)
@@ -742,7 +751,9 @@ def publish(
742
751
  # =============================================================================
743
752
 
744
753
 
745
- def _render_materialize_output(report: MaterializeReport, root: Path, *, dry_run: bool) -> None:
754
+ def _render_materialize_output(
755
+ report: MaterializeReport, root: Path, *, dry_run: bool, refresh: bool
756
+ ) -> None:
746
757
  """Print what ran, or what would.
747
758
 
748
759
  Engine prose and paths are escaped — they are data, not markup, and a
@@ -780,8 +791,11 @@ def _render_materialize_output(report: MaterializeReport, root: Path, *, dry_run
780
791
  # On the verdict line as well as in the listing: on a large analysis the
781
792
  # listing scrolls away, and this is the one state that reports something
782
793
  # rather than doing it.
794
+ # With --refresh, what is still behind is what the targets read.
783
795
  if report.behind:
784
- verdict += f" · {len(report.behind)} behind — `--refresh` remakes them"
796
+ verdict += f" · {len(report.behind)} behind" + (
797
+ ", read by the targets" if refresh else " — `--refresh` remakes them"
798
+ )
785
799
 
786
800
  if lines:
787
801
  lines.append("")
@@ -834,6 +848,11 @@ def _render_publish_output(report: PublishReport, *, dry_run: bool) -> None:
834
848
  lines.append(f" {_DONE} commits {report.branch} at {report.commit[:7]} → {target}")
835
849
  if report.unpushed:
836
850
  lines.append(f" {_TODO} commits {report.unpushed} of {report.branch} to send → {target}")
851
+ if report.shown_first and not report.created:
852
+ lines.append(
853
+ f" {_DONE} default {report.shown_first}, now shown first on GitHub in place of "
854
+ "git-annex's log"
855
+ )
837
856
  if report.made_public:
838
857
  lines.append(f" {_DONE} license {escape(report.license)}")
839
858
  lines.append(
@@ -39,10 +39,15 @@ from lightcone.engine import github, project
39
39
  def init_git(directory: Path) -> None:
40
40
  """Create the repository the project's history lives in.
41
41
 
42
+ Its first branch is ``main``, as GitHub names a new repository's,
43
+ unless git is set to name it otherwise (``init.defaultBranch``): left
44
+ to itself, git before 3.0 names it ``master``.
45
+
42
46
  Args:
43
47
  directory: Where to run ``git init``.
44
48
  """
45
- _git(["init", "-q"], cwd=directory)
49
+ named = (_ask(["config", "--get", "init.defaultBranch"], cwd=directory) or "").strip()
50
+ _git(["init", "-q", *([] if named else ["--initial-branch=main"])], cwd=directory)
46
51
 
47
52
 
48
53
  def init_annex(directory: Path) -> None:
@@ -3,9 +3,9 @@
3
3
  GitHub is where a project is published: its repository holds the commits
4
4
  and git-annex's log of which store holds what. git itself moves both, with
5
5
  whatever credentials git already has. This module is the rest: reading
6
- which repository a URL names, and the three things only GitHub's REST API
7
- does — saying who can read a repository, creating one, and making one
8
- public.
6
+ which repository a URL names, and what only GitHub's REST API does —
7
+ saying who can read a repository, creating one, making one public,
8
+ and choosing its default branch.
9
9
 
10
10
  The API is called with Python's standard library and a token found in the
11
11
  environment, or from ``gh`` where that happens to be installed and logged
@@ -203,6 +203,27 @@ def make_public(repository: Repository, token: str) -> None:
203
203
  )
204
204
 
205
205
 
206
+ def show_first(repository: Repository, token: str, branch: str) -> None:
207
+ """Make *branch* the one *repository* shows first, and a clone checks out.
208
+
209
+ Args:
210
+ repository: The repository.
211
+ token: A token allowed to administer it.
212
+ branch: A branch it holds.
213
+
214
+ Raises:
215
+ ProjectError: In GitHub's own words, if it refuses.
216
+ """
217
+ code, answer = _call(
218
+ "PATCH", f"/repos/{repository.owner}/{repository.name}", token, {"default_branch": branch}
219
+ )
220
+ if code != 200:
221
+ raise project.ProjectError(
222
+ f"GitHub would not make `{branch}` the default branch of {repository.slug}: "
223
+ f"{_said(answer)}"
224
+ )
225
+
226
+
206
227
  def _said(answer: dict[str, Any]) -> str:
207
228
  """GitHub's own message, with each error it lists."""
208
229
  errors = "; ".join(
@@ -36,7 +36,7 @@ import posixpath
36
36
  import re
37
37
  import shlex
38
38
  from collections import Counter
39
- from collections.abc import Iterable, Iterator, Sequence
39
+ from collections.abc import Collection, Iterable, Iterator, Sequence
40
40
  from contextlib import contextmanager, suppress
41
41
  from dataclasses import asdict, dataclass, field, replace
42
42
  from pathlib import Path
@@ -135,7 +135,7 @@ def check(root: Path, targets: Sequence[str], *, refresh: bool = False) -> Mater
135
135
  Args:
136
136
  root: The project root.
137
137
  targets: What to classify; empty means everything.
138
- refresh: Whether a result that is merely behind would be remade.
138
+ refresh: Whether to remake the requested results regardless of state.
139
139
 
140
140
  Returns:
141
141
  ``planned`` naming each result that would run and why, ``behind``
@@ -148,8 +148,9 @@ def check(root: Path, targets: Sequence[str], *, refresh: bool = False) -> Mater
148
148
  """
149
149
  report = MaterializeReport()
150
150
  graph, environment = _graph(root, targets, report)
151
+ asked = graph.resolve(list(targets)) if targets else list(graph.tasks)
151
152
  blocked: set[ResultId] = set()
152
- for found in _classify(root, graph, environment, refresh=refresh):
153
+ for found in _classify(root, graph, environment, refresh=asked if refresh else ()):
153
154
  verdict = found.verdict
154
155
  # What a run leaves alone reads nothing, so nothing it reads blocks it.
155
156
  stale = {
@@ -158,12 +159,12 @@ def check(root: Path, targets: Sequence[str], *, refresh: bool = False) -> Mater
158
159
  if dep not in graph.tasks and (why := worker.unreadable(graph.checked.statuses[dep]))
159
160
  }
160
161
  reads_blocked = bool(stale) or bool(blocked.intersection(found.task.depends_on))
161
- if found.may_run(refresh=refresh) and reads_blocked:
162
+ if found.may_run() and reads_blocked:
162
163
  blocked.add(found.task.id)
163
164
  report.blocked.append(found.task.id)
164
165
  report.warnings.extend(f"{dep}: {why}" for dep, why in stale.items())
165
- elif verdict.calls_for_a_remake(refresh=refresh):
166
- report.planned[found.task.id] = verdict.why
166
+ elif verdict.calls_for_a_remake(refresh=found.refresh):
167
+ report.planned[found.task.id] = verdict.why or "requested with --refresh"
167
168
  elif found.upstream:
168
169
  # Nothing here can know whether a rebuild comes out
169
170
  # byte-identical, and assuming it will would under-report.
@@ -193,20 +194,22 @@ class _Classified:
193
194
  verdict: plan.Verdict
194
195
  #: A task upstream of this one that may run, or empty.
195
196
  upstream: ResultId
197
+ #: Whether this result was explicitly requested with ``--refresh``.
198
+ refresh: bool
196
199
 
197
- def may_run(self, *, refresh: bool) -> bool:
200
+ def may_run(self) -> bool:
198
201
  """Whether a run has to hand this task to a worker."""
199
- return bool(self.upstream) or self.verdict.calls_for_a_remake(refresh=refresh)
202
+ return bool(self.upstream) or self.verdict.calls_for_a_remake(refresh=self.refresh)
200
203
 
201
- def certain(self, *, refresh: bool) -> bool:
204
+ def certain(self) -> bool:
202
205
  """Whether a run is sure to make this result again: nothing it
203
206
  makes first can leave it standing."""
204
- through = self.verdict.through_reads and bool(self.upstream)
205
- return self.verdict.calls_for_a_remake(refresh=refresh) and not through
207
+ through = not self.refresh and self.verdict.through_reads and bool(self.upstream)
208
+ return self.verdict.calls_for_a_remake(refresh=self.refresh) and not through
206
209
 
207
210
 
208
211
  def _classify(
209
- root: Path, graph: Graph, environment: str, *, refresh: bool
212
+ root: Path, graph: Graph, environment: str, *, refresh: Collection[ResultId]
210
213
  ) -> list[_Classified]:
211
214
  """Classify every task of *graph*, upstream first.
212
215
 
@@ -220,8 +223,8 @@ def _classify(
220
223
  root: The project root.
221
224
  graph: The tasks to classify, each after the tasks it reads.
222
225
  environment: The IRI of the project's environment.
223
- refresh: Whether behind results count as running, which is what
224
- decides whether their dependents may run too.
226
+ refresh: The results explicitly requested with ``--refresh``. Their
227
+ dependencies are remade only where stale or missing.
225
228
 
226
229
  Returns:
227
230
  One entry per task, in the graph's order.
@@ -250,6 +253,7 @@ def _classify(
250
253
  "the results it lacks are — `lc init` sets it up."
251
254
  )
252
255
  held = dataset.holders(root, list(away.values()))
256
+ refreshed = set(refresh)
253
257
  may_run: set[ResultId] = set()
254
258
  classified = []
255
259
  for key, task in graph.tasks.items():
@@ -261,8 +265,9 @@ def _classify(
261
265
  remotes,
262
266
  plan.classify(found=found, environment=environment, remotes=remotes),
263
267
  next((dep for dep in task.depends_on if dep in may_run), ""),
268
+ key in refreshed,
264
269
  )
265
- if entry.may_run(refresh=refresh):
270
+ if entry.may_run():
266
271
  may_run.add(key)
267
272
  classified.append(entry)
268
273
  return classified
@@ -355,7 +360,7 @@ def status(root: Path) -> StatusReport:
355
360
  Reads records through ASTRA's checker, and git-annex's log of which
356
361
  remote holds the bytes this clone lacks; runs nothing, fetches
357
362
  nothing, commits nothing, and does not care whether the tree is
358
- clean. Classified with ``refresh=False``, because this says what the
363
+ clean. Classified with nothing refreshed, because this says what the
359
364
  project *is* rather than what some run would do to it.
360
365
 
361
366
  Args:
@@ -378,7 +383,7 @@ def status(root: Path) -> StatusReport:
378
383
  answer.environment = environment
379
384
  answer.online = dataset.target(root) is not None
380
385
  checked = graph.checked.to_json()["statuses"]
381
- for found in _classify(root, graph, environment, refresh=False):
386
+ for found in _classify(root, graph, environment, refresh=()):
382
387
  held = found.found.bytes
383
388
  unfetched = found.verdict.state in ("ok", "behind") and not (
384
389
  held is None or held.state == "present"
@@ -489,7 +494,7 @@ def fetch(root: Path, targets: Sequence[str]) -> FetchReport:
489
494
  report.failed[name] = f"its bytes are kept by {kept.kept_by}, not git-annex"
490
495
  else:
491
496
  wanted[declared] = name
492
- for found in _classify(root, graph, environment, refresh=False):
497
+ for found in _classify(root, graph, environment, refresh=()):
493
498
  key, held = found.task.id, found.found.bytes
494
499
  if key not in asked:
495
500
  continue
@@ -535,7 +540,7 @@ def materialize(
535
540
  root: The project root.
536
541
  targets: Results to make, with what they read; empty means every one.
537
542
  cluster_id: The name or immutable ID returned by ``lc compute launch``.
538
- refresh: Also remake results made under an earlier environment.
543
+ refresh: Remake the requested results regardless of state.
539
544
 
540
545
  Returns:
541
546
  What was made, left alone, failed or blocked, and why.
@@ -565,8 +570,9 @@ def materialize(
565
570
  if changes := dataset.status(root):
566
571
  raise ProjectError(_dirty(root, changes, _written(graph)))
567
572
  worker.require_in_commit(root, graph.specs)
568
- classified = _classify(root, graph, environment, refresh=refresh)
569
- running = [found.task for found in classified if found.may_run(refresh=refresh)]
573
+ asked = graph.resolve(list(targets)) if targets else list(graph.tasks)
574
+ classified = _classify(root, graph, environment, refresh=asked if refresh else ())
575
+ running = [found.task for found in classified if found.may_run()]
570
576
  if not running:
571
577
  # Nothing is submitted, so no allocation is needed.
572
578
  for found in classified:
@@ -581,7 +587,7 @@ def materialize(
581
587
  root,
582
588
  graph,
583
589
  running,
584
- {found.task.id for found in classified if found.certain(refresh=refresh)},
590
+ {found.task.id for found in classified if found.certain()},
585
591
  )
586
592
  dsid = dataset.dataset_id(root)
587
593
  with cluster_for_run(cluster_id) as scheduler:
@@ -647,7 +653,7 @@ def materialize(
647
653
  report.failed.append(task.id)
648
654
  report.warnings.append(f"{task.id}: {why}")
649
655
  continue
650
- if not found.may_run(refresh=refresh):
656
+ if not found.may_run():
651
657
  pending[task.id] = _left_alone(found, report)
652
658
  continue
653
659
  at = {plan.at_commit(root, path) for path in task.inputs.values()}
@@ -679,7 +685,7 @@ def materialize(
679
685
  found.found,
680
686
  found.remotes,
681
687
  context,
682
- refresh,
688
+ found.refresh,
683
689
  *[pending[dep] for dep in task.depends_on],
684
690
  key=task.id,
685
691
  resources=requirements[task.id],
@@ -463,16 +463,15 @@ class Verdict:
463
463
  def calls_for_a_remake(self, *, refresh: bool) -> bool:
464
464
  """Whether a run would make this result again.
465
465
 
466
- ``stale`` and ``missing`` always; ``behind`` only when asked,
467
- because nothing about it is wrong.
466
+ ``stale`` and ``missing`` always; any state when explicitly refreshed.
468
467
 
469
468
  Args:
470
- refresh: Whether the caller asked for behind results too.
469
+ refresh: Whether the caller explicitly asked to remake this result.
471
470
 
472
471
  Returns:
473
472
  Whether to run the recipe.
474
473
  """
475
- return self.state in ("stale", "missing") or (refresh and self.state == "behind")
474
+ return refresh or self.state in ("stale", "missing")
476
475
 
477
476
 
478
477
  def classify(
@@ -175,7 +175,8 @@ def converge(directory: Path, *, write: bool = True) -> ConvergenceReport:
175
175
 
176
176
  Creates whatever is missing, repairs the pieces lightcone manages, and
177
177
  never overwrites a file the user owns. A directory that already holds
178
- an ``astra.yaml`` is adopted, not rejected.
178
+ an ``astra.yaml`` is adopted, not rejected. Project files are left
179
+ uncommitted for the user to review, including in a new repository.
179
180
 
180
181
  Args:
181
182
  directory: The project root, created if absent.
@@ -29,7 +29,8 @@ what the store already took. It sends what the commit names, the current
29
29
  versions, with the results the analysis reads at commits it declares in
30
30
  this repository. It sends no tag and no other branch, deletes nothing
31
31
  anywhere, and merges nothing: where GitHub's branch has commits this
32
- clone lacks, it refuses.
32
+ clone lacks, it refuses. GitHub shows that branch first, never
33
+ git-annex's log, in a repository lc creates.
33
34
  """
34
35
 
35
36
  from __future__ import annotations
@@ -106,6 +107,9 @@ class PublishReport:
106
107
  commit: str = ""
107
108
  #: How many commits this call sent.
108
109
  commits: int = 0
110
+ #: The branch this call made the one GitHub shows first, in place of
111
+ #: git-annex's log; empty where it changed nothing.
112
+ shown_first: str = ""
109
113
  #: Check mode: how many commits GitHub lacks.
110
114
  unpushed: int = 0
111
115
  #: Changes that are not committed, which no publication sends.
@@ -187,13 +191,20 @@ def publish(
187
191
  raise ProjectError(
188
192
  "HEAD is not on a branch, and lc publishes a branch: `git switch` to one."
189
193
  )
190
- report.target, report.branch, report.commit = target.slug, branch, dataset.head(root)
194
+ commit = dataset._ask(["rev-parse", "--verify", "HEAD"], cwd=root)
195
+ if commit is None:
196
+ raise ProjectError(
197
+ "this project has no commit to publish. `lc init` leaves project files "
198
+ "uncommitted: review them with `git status`, then `git add` the files you "
199
+ "want to publish and `git commit`. Run `lc publish` again afterwards."
200
+ )
201
+ report.target, report.branch, report.commit = target.slug, branch, commit.strip()
191
202
  dataset.populate(root)
192
203
  dataset.enable_store(root)
193
204
  token = github.token(root)
194
205
 
195
206
  # --- What stands, before anything is done ------------------------------
196
- heads, said = _heads(root, origin or target.url)
207
+ heads, first, said = _heads(root, origin or target.url)
197
208
  creating = heads is None
198
209
  if creating:
199
210
  if check:
@@ -277,8 +288,11 @@ def publish(
277
288
  dataset.confirm(root, remote, _settings(declared, address))
278
289
  report.confirmed = True
279
290
  report.store = _described(declared, target)
280
- if heads:
281
- # GitHub's copy of git-annex's log says what others already sent.
291
+ # GitHub's copy of git-annex's log says what others already sent, unless
292
+ # it is the very one this clone last fetched or pushed. Each connection
293
+ # to GitHub costs seconds over ssh (measured).
294
+ fetched = dataset._ask(["rev-parse", "-q", "--verify", "origin/git-annex"], cwd=root) or ""
295
+ if heads and heads.get("git-annex", "") != fetched.strip():
282
296
  dataset._git([*dataset.reaching(root), "fetch", "-q", "origin"], cwd=root)
283
297
  unsent, report.nowhere = _lacking(root, declared, files, kinds)
284
298
 
@@ -297,11 +311,27 @@ def publish(
297
311
  # the store would reach clones as results to make again.
298
312
  return report
299
313
  report.commits = _commits(root, theirs, report.commit)
300
- _push(root, branch, target)
314
+ _push(root, branch, target, heads or {})
301
315
  if going_public and not creating:
302
316
  assert token is not None
303
317
  github.make_public(target, token)
304
318
  report.made_public, report.visibility = True, "public"
319
+ # GitHub shows first a branch of its choosing among those the first push
320
+ # to a repository brings, and chose git-annex's log over the analysis
321
+ # (measured).
322
+ if creating or first == "git-annex":
323
+ if token is None:
324
+ report.warnings.append(
325
+ f"GitHub shows git-annex's log first on {target.slug}, not the analysis: make "
326
+ f"`{branch}` its default branch in the repository's settings, or publish again "
327
+ "with a GitHub token."
328
+ )
329
+ else:
330
+ try:
331
+ github.show_first(target, token, branch)
332
+ report.shown_first = branch
333
+ except ProjectError as refused:
334
+ report.warnings.append(str(refused))
305
335
  return report
306
336
 
307
337
 
@@ -344,19 +374,26 @@ def _target(origin: str, url: str) -> github.Repository | None:
344
374
  return current
345
375
 
346
376
 
347
- def _heads(root: Path, address: str) -> tuple[dict[str, str] | None, str]:
348
- """The branches the repository at *address* holds, each with its commit;
349
- or None, with git's own words, where git cannot reach it."""
377
+ def _heads(root: Path, address: str) -> tuple[dict[str, str] | None, str, str]:
378
+ """The remote branches, its default branch, and git's error if unreachable.
379
+
380
+ Git credentials suffice even for a private repository: no API token
381
+ is needed to learn which branch a clone would check out.
382
+ """
350
383
  asked = project._run(
351
- ["git", *dataset.reaching(root), "ls-remote", "--heads", address], cwd=root
384
+ ["git", *dataset.reaching(root), "ls-remote", "--symref", address,
385
+ "HEAD", "refs/heads/*"], cwd=root
352
386
  )
353
387
  if asked.returncode != 0:
354
- return None, (asked.stderr or "").strip()
355
- heads = {}
388
+ return None, "", (asked.stderr or "").strip()
389
+ heads, first = {}, ""
356
390
  for line in (asked.stdout or "").splitlines():
357
391
  commit, _, ref = line.partition("\t")
358
- heads[ref.removeprefix("refs/heads/")] = commit
359
- return heads, ""
392
+ if ref == "HEAD" and commit.startswith("ref: refs/heads/"):
393
+ first = commit.removeprefix("ref: refs/heads/")
394
+ elif ref.startswith("refs/heads/"):
395
+ heads[ref.removeprefix("refs/heads/")] = commit
396
+ return heads, first, ""
360
397
 
361
398
 
362
399
  def _require_creatable(target: github.Repository, token: str | None, said: str) -> None:
@@ -460,24 +497,32 @@ def _commits(root: Path, theirs: str, commit: str) -> int:
460
497
  return int(dataset._git(["rev-list", "--count", span], cwd=root).strip())
461
498
 
462
499
 
463
- def _push(root: Path, branch: str, target: github.Repository) -> None:
500
+ def _push(
501
+ root: Path, branch: str, target: github.Repository, heads: dict[str, str]
502
+ ) -> None:
464
503
  """Send git-annex's log, then the branch, to GitHub.
465
504
 
466
505
  The log first has to hold what this clone noted and what GitHub's copy
467
- says (``dataset.record_copies``). Both refs go or neither does. Where
468
- GitHub refuses, someone published in between: their log is taken in
469
- and the push tried once more, unless the branch itself moved, which is
470
- theirs to pull.
506
+ says (``dataset.record_copies``). Both refs go or neither does; where
507
+ GitHub's *heads* are both already, and the branch is set up to pull
508
+ from it, nothing goes. Where GitHub refuses, someone published in
509
+ between: their log is taken in and the push tried once more, unless
510
+ the branch itself moved, which is theirs to pull.
471
511
 
472
512
  Raises:
473
513
  ProjectError: If the branch moved, or GitHub refuses again, in
474
514
  git's own words.
475
515
  """
516
+ refs = [f"refs/heads/{branch}", "refs/heads/git-annex"]
476
517
  push = [
477
518
  "git", *dataset.reaching(root), "push", "-q", "--atomic", "origin",
478
- f"refs/heads/{branch}:refs/heads/{branch}", "refs/heads/git-annex:refs/heads/git-annex",
519
+ *(f"{ref}:{ref}" for ref in refs),
479
520
  ] # fmt: skip
480
521
  dataset.record_copies(root)
522
+ tracked = (dataset._ask(["config", "--get", f"branch.{branch}.remote"], cwd=root) or "").strip()
523
+ held = [heads.get(ref.removeprefix("refs/heads/"), "") for ref in refs]
524
+ if tracked and dataset._git(["rev-parse", *refs], cwd=root).split() == held:
525
+ return
481
526
  if project._run(push, cwd=root).returncode != 0:
482
527
  dataset._git([*dataset.reaching(root), "fetch", "-q", "origin"], cwd=root)
483
528
  moved = dataset._ask(
@@ -500,7 +545,7 @@ def _push(root: Path, branch: str, target: github.Repository) -> None:
500
545
  "the store stays there."
501
546
  )
502
547
  # So that `git pull`, with nothing more, takes in what others publish.
503
- if not (dataset._ask(["config", "--get", f"branch.{branch}.remote"], cwd=root) or "").strip():
548
+ if not tracked:
504
549
  dataset._git(["branch", "-q", f"--set-upstream-to=origin/{branch}", branch], cwd=root)
505
550
 
506
551
 
@@ -745,7 +790,7 @@ def _files(root: Path, report: PublishReport) -> tuple[dict[str, str], dict[str,
745
790
  graph, environment = materialize._graph(root, [], scan)
746
791
  states = Counter(
747
792
  found.verdict.state
748
- for found in materialize._classify(root, graph, environment, refresh=False)
793
+ for found in materialize._classify(root, graph, environment, refresh=())
749
794
  )
750
795
  except ProjectError as unread:
751
796
  report.warnings.append(
@@ -24,12 +24,11 @@ which Landlock cannot do at all.
24
24
 
25
25
  from __future__ import annotations
26
26
 
27
- import functools
28
27
  import os
29
28
  import shutil
29
+ import struct
30
30
  import tempfile
31
31
  from collections.abc import Iterable, Sequence
32
- from fnmatch import fnmatch
33
32
  from pathlib import Path
34
33
 
35
34
  from lightcone.engine.project import ProjectError
@@ -140,18 +139,8 @@ _WRITE_BASELINE = (
140
139
  "/dev/null", "/dev/zero", "/dev/full", "/dev/tty", "/dev/pts", "/dev/ptmx",
141
140
  ) # fmt: skip
142
141
 
143
- #: The ELF interpreter. Landlock checks EXECUTE on the *loader's* open,
144
- #: so without these every dynamically linked binary — bash and python
145
- #: included — fails EACCES and the sandbox is unusable. Globbed rather
146
- #: than hardcoded: the path differs
147
- #: across glibc/musl and architectures.
148
- _ELF_LOADER_GLOBS = (
149
- "/lib64/ld-linux-*.so.*",
150
- "/lib/ld-linux*.so.*",
151
- "/lib/ld-musl-*.so.*",
152
- "/usr/lib/ld-linux*.so.*",
153
- "/usr/lib64/ld-linux-*.so.*",
154
- )
142
+ #: The ELF program header type naming a binary's loader.
143
+ _PT_INTERP = 3
155
144
 
156
145
  #: Prefixes shared with the rest of the host. An interpreter installed
157
146
  #: into one of these does not bring its own tree with it, so only the
@@ -398,7 +387,7 @@ def _stdlib_root(python: Path | None) -> list[Path]:
398
387
 
399
388
 
400
389
  def _exec_set(env_dir: Path, python: Path | None) -> list[Path]:
401
- """The two exec tiers: the environment, and the utility allowlist.
390
+ """The two exec tiers, the environment and the utility allowlist, plus their loaders.
402
391
 
403
392
  Grants are per *file* for the utilities, never per directory:
404
393
  ``/usr/bin`` holds ``bash`` and ``latex`` alike, so a directory grant
@@ -443,48 +432,57 @@ def _exec_set(env_dir: Path, python: Path | None) -> list[Path]:
443
432
  found = utility(name)
444
433
  if found is not None:
445
434
  paths.append(found)
446
- paths.extend(elf_loaders())
435
+ loaders = [_elf_interpreter(path) for path in paths]
436
+ paths.extend(loader for loader in loaders if loader is not None)
447
437
  return paths
448
438
 
449
439
 
450
- @functools.cache
451
- def elf_loaders() -> tuple[Path, ...]:
452
- """Find the dynamic loaders present on this host.
440
+ def _elf_interpreter(binary: Path) -> Path | None:
441
+ """The realpath of the loader an ELF binary names, if it names one.
442
+
443
+ Landlock checks EXECUTE on the loader's own open, so a granted binary
444
+ whose loader is not granted fails ``EACCES`` before it starts — bash
445
+ and python included. The loader is read from the binary rather than
446
+ looked for at the FHS paths, because a binary may name one anywhere
447
+ and the FHS path may hold a different file — a NixOS binary names a
448
+ glibc inside its own store path, while ``/lib64`` holds a stub or
449
+ nix-ld.
450
+
451
+ Only little-endian ELF64 is read: on Linux lc installs only for x86_64
452
+ and aarch64. A 32-bit tool on such a host gets no loader grant, so it
453
+ fails with a denial rather than running unsandboxed.
453
454
 
454
- Landlock checks EXECUTE on the loader's open, so without these every
455
- dynamically linked binary fails ``EACCES``. Scans each distinct
456
- directory once rather than globbing five patterns — on a merged-
457
- ``/usr`` system all five resolve to the same directory, and globbing
458
- re-lists ~8000 entries per pattern, which measured as 95% of the
459
- policy build.
455
+ The path is read up to its first NUL, as the kernel reads it, and kept
456
+ only when it is absolute and resolves to a file. A malformed entry
457
+ must never grant a directory.
460
458
 
461
459
  Returns:
462
- The realpath'd loaders. Cached: the answer cannot change while
463
- the process runs.
460
+ ``None`` for anything else: a script, a static binary, a Mach-O,
461
+ a directory, a malformed loader entry.
464
462
  """
465
- found: set[Path] = set()
466
- for directory, patterns in _loader_patterns().items():
467
- try:
468
- entries = list(os.scandir(directory))
469
- except OSError:
470
- continue
471
- for entry in entries:
472
- # Cheap prefix reject before fnmatch: almost nothing in a
473
- # library directory starts with `ld-`.
474
- if entry.name.startswith("ld-") and any(
475
- fnmatch(entry.name, pattern) for pattern in patterns
476
- ):
477
- found.add(Path(entry.path).resolve())
478
- return tuple(sorted(found))
479
-
480
-
481
- def _loader_patterns() -> dict[str, set[str]]:
482
- """The loader globs, grouped by the real directory they name."""
483
- grouped: dict[str, set[str]] = {}
484
- for pattern in _ELF_LOADER_GLOBS:
485
- directory, _, name = pattern.rpartition("/")
486
- grouped.setdefault(os.path.realpath(directory), set()).add(name)
487
- return grouped
463
+ try:
464
+ with binary.open("rb") as f:
465
+ header = f.read(64)
466
+ if header[:6] != b"\x7fELF\x02\x01":
467
+ return None
468
+ (table_offset,) = struct.unpack_from("<Q", header, 32)
469
+ entry_size, count = struct.unpack_from("<HH", header, 54)
470
+ f.seek(table_offset)
471
+ table = f.read(entry_size * count)
472
+ for index in range(count):
473
+ kind, _, offset, _, _, size = struct.unpack_from(
474
+ "<IIQQQQ", table, index * entry_size
475
+ )
476
+ if kind == _PT_INTERP:
477
+ f.seek(offset)
478
+ name = f.read(size).split(b"\0", 1)[0]
479
+ if not name.startswith(b"/"):
480
+ return None
481
+ loader = Path(os.fsdecode(name)).resolve()
482
+ return loader if loader.is_file() else None
483
+ except (OSError, struct.error):
484
+ return None
485
+ return None
488
486
 
489
487
 
490
488
  def _declared(paths: Iterable[Path]) -> tuple[Path, ...]:
@@ -192,7 +192,7 @@ def materialize(
192
192
  that hold them, as the driver found them: whether a run can
193
193
  fetch them is git-annex's to say, and a task asks git nothing.
194
194
  context: The run's driver-resolved facts.
195
- refresh: Whether to remake a result that is merely behind.
195
+ refresh: Whether this result was explicitly requested to be remade.
196
196
  *upstream: The results of this task's dependencies, arriving as
197
197
  the futures it was given — which is what makes Dask the
198
198
  scheduler rather than a loop here.