From 559231a59db0907ec66f587be8c09e9befb7695b Mon Sep 17 00:00:00 2001 From: Aaron Niskin Date: Mon, 25 Aug 2025 21:55:09 -0700 Subject: [PATCH 1/3] added `Commit.dag_name` and dags aren't added to dags map until commit Dags are hashable now. To achieve this, we move the dags map insert to commit, and add a `dag_name` property to the `Commit` object. This is a good idea anyway as there is currently no way to really tell which dag was added in a commit (i.e. there's no connection between a dag's commit message and the dag itself -- this fixes that). --- src/daggerml_cli/api.py | 1 - src/daggerml_cli/repo.py | 17 ++++++++++------- tests/test_api.py | 1 + tests/test_repo.py | 1 + 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/daggerml_cli/api.py b/src/daggerml_cli/api.py index b80eeae..95d9703 100644 --- a/src/daggerml_cli/api.py +++ b/src/daggerml_cli/api.py @@ -616,7 +616,6 @@ def walk_nodes(x): return out = [*heads, *[x for x in reversed(nodes.values()) if x not in heads]] return out - # return print(json.dumps([asdict(x) for x in out], indent=2, sort_keys=True)) def revert_commit(config, commit): diff --git a/src/daggerml_cli/repo.py b/src/daggerml_cli/repo.py index fcb8c3c..3acaf38 100644 --- a/src/daggerml_cli/repo.py +++ b/src/daggerml_cli/repo.py @@ -248,6 +248,7 @@ class Commit: author: str committer: str message: str + dag_name: Optional[str] = None # -> dag name in tree created: str = field(default_factory=now) modified: str = field(default_factory=now) @@ -630,7 +631,7 @@ def merge_trees(base, a, b): author or self.user, self.user, message or f"merge {c2.id} with {c1.id}", - created or now(), + created=created or now(), ) ) @@ -757,12 +758,13 @@ def begin(self, *, message, name=None, dump=None): ctx = Ctx.from_head(self.head) if dump is None: dag = self(Dag([], {}, None, None)) - ctx.dags[name] = dag else: + loaded = self.load_ref(dump) + assert loaded is not None, "failed to load dump" with self.tx(True): - argv = self(Node(Argv(self.load_ref(dump)))) + argv = self(Node(Argv(loaded))) dag = self(FnDag([argv], {}, None, None, argv)) - commit = Commit([ctx.head.commit], self(ctx.tree), self.user, self.user, message) + commit = Commit([ctx.head.commit], self(ctx.tree), self.user, self.user, message, dag_name=name) index = self(Index(self(commit), dag)) return index @@ -773,10 +775,9 @@ def put_node(self, data, index: Ref, name=None, doc=None): ctx.dag.nodes.append(node) if name: ctx.dag.names[name] = node - self(ctx.head.dag, ctx.dag) ctx.commit.tree = self(ctx.tree) ctx.commit.created = ctx.commit.modified = now() - self(index, Index(self(ctx.commit), ctx.head.dag)) + self(index, Index(self(ctx.commit), self(ctx.dag))) return node def get_node_value(self, ref: Ref): @@ -828,9 +829,11 @@ def commit(self, res_or_err, index: Ref): assert (ctx.dag.result or ctx.dag.error) is None, "dag has been committed already" ctx.dag.result = result ctx.dag.error = error + ref = self(ctx.dag) + if ctx.commit.dag_name is not None: + ctx.tree.dags[ctx.commit.dag_name] = ref ctx.commit.tree = self(ctx.tree) ctx.commit.created = ctx.commit.modified = now() - ref = self(dag, ctx.dag) commit = self.merge(self.get(self.head).commit, self(ctx.commit)) self.set_head(self.head, commit) self.delete(index) diff --git a/tests/test_api.py b/tests/test_api.py index 7c7afdc..0f7a413 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -46,6 +46,7 @@ def test_create_dag(self): with d0.tx(): assert d0.get_node("n0") == n0 assert n0().doc == "This is my data." + assert d0.unroll(n0) == data d0.commit(n0) d0.test_close(self) with SimpleApi.begin("d1", config_dir=config_dir, cache_path=config_dir) as d1: diff --git a/tests/test_repo.py b/tests/test_repo.py index bcd748b..2646442 100644 --- a/tests/test_repo.py +++ b/tests/test_repo.py @@ -15,6 +15,7 @@ def tmp_repo(cache_path=None): tmpdirs = [tempfile.mkdtemp() for _ in range(2)] repo = Repo(tmpdirs[0], user="test", create=True, cache_path=cache_path or tmpdirs[1]) if cache_path is None: + assert repo.cache_path is not None with Repo(repo.cache_path, create=True): pass try: From 9f3f527cdea9f422ae362257c9dfc42709292e05 Mon Sep 17 00:00:00 2001 From: Aaron Niskin Date: Mon, 25 Aug 2025 22:06:25 -0700 Subject: [PATCH 2/3] missed the most important part -- not hashing Dags and FnDags. --- src/daggerml_cli/repo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/daggerml_cli/repo.py b/src/daggerml_cli/repo.py index 3acaf38..e5c918b 100644 --- a/src/daggerml_cli/repo.py +++ b/src/daggerml_cli/repo.py @@ -259,7 +259,7 @@ class Tree: dags: dict[str, Ref] # -> dag -@repo_type(hash=[]) +@repo_type @dataclass class Dag: nodes: list[Ref] # -> node @@ -271,7 +271,7 @@ def nameof(self, ref): return {v: k for k, v in self.names.items()}.get(ref) -@repo_type(hash=[]) +@repo_type @dataclass class FnDag(Dag): argv: Optional[Ref] = None # -> node(expr) (in this dag) From 5598be051eb6884ef8841b04c20e01e9a033b1fc Mon Sep 17 00:00:00 2001 From: Aaron Niskin Date: Mon, 25 Aug 2025 22:21:54 -0700 Subject: [PATCH 3/3] wip --- src/daggerml_cli/repo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/daggerml_cli/repo.py b/src/daggerml_cli/repo.py index e5c918b..8b9ec49 100644 --- a/src/daggerml_cli/repo.py +++ b/src/daggerml_cli/repo.py @@ -628,9 +628,9 @@ def merge_trees(base, a, b): Commit( [c1, c2], merge_trees(self.get(c0).tree, self.get(c1).tree, self.get(c2).tree), - author or self.user, - self.user, - message or f"merge {c2.id} with {c1.id}", + author=author or self.user, + committer=self.user, + message=message or f"merge {c2.id} with {c1.id}", created=created or now(), ) )