Skip to content

Commit

Permalink
Expose staging API
Browse files Browse the repository at this point in the history
  • Loading branch information
frthjf committed Jun 4, 2024
1 parent 442b98c commit b073712
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/machinable/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,17 @@ def push_related(self, key: str, value: "Interface") -> None:
self.__related__[key] = value
self._relation_cache[key] = True

def is_staged(self):
return self.__model__.uuid[-12:] != "0" * 12

def stage(self):
self.__model__.context = context = self.compute_context()
self.__model__.uuid = update_uuid_payload(self.__model__.uuid, context)

# ensure that configuration and predicate has been computed
assert self.config is not None
self.__model__.predicate = self.compute_predicate()

def is_committed(self) -> bool:
from machinable.index import Index

Expand All @@ -307,12 +318,8 @@ def commit(self) -> Self:
# allow on_before_commit to abort
return self

self.__model__.context = context = self.compute_context()
self.__model__.uuid = update_uuid_payload(self.__model__.uuid, context)

# ensure that configuration and predicate has been computed
assert self.config is not None
self.__model__.predicate = self.compute_predicate()
if not self.is_staged():
self.stage()

if self.on_commit() is False:
# allow on_commit to abort
Expand Down
5 changes: 5 additions & 0 deletions tests/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ def test_interface_commit(tmp_storage):
with Project("./tests/samples/project"):
Interface.make("interface.dummy").commit()

i = Interface()
assert not i.is_staged()
i.commit()
assert i.is_staged()


def tes_interface_save_file(tmp_storage):
component = Interface().commit()
Expand Down

0 comments on commit b073712

Please sign in to comment.