diff --git a/src/machinable/element.py b/src/machinable/element.py index eade55a8..05b16e3a 100644 --- a/src/machinable/element.py +++ b/src/machinable/element.py @@ -561,6 +561,8 @@ def config(self) -> DictConfig: self.__model__.config = OmegaConf.to_container(self._config) OmegaConf.clear_resolver("config_method") + + self.on_after_configure() except Exception as _ex: raise ConfigurationError(str(_ex)) from _ex @@ -661,6 +663,12 @@ def on_configure(self) -> None: that are applied at a later stage. """ + def on_after_configure(self) -> None: + """Configuration event operating on the resolved, read-only configuration + This may be used to validate given the interface instance. If validation + can be performed without the instance, use a config schema instead. + """ + def _clear_caches(self) -> None: self._config = None self.__model__.config = None diff --git a/src/machinable/interface.py b/src/machinable/interface.py index ba61ea94..69db3bad 100644 --- a/src/machinable/interface.py +++ b/src/machinable/interface.py @@ -242,6 +242,8 @@ def commit(self) -> Self: if index.find_by_id(self.uuid) is not None: return self + self.on_before_commit() + self.__model__.context = context = self.compute_context() self.__model__.uuid = update_uuid_payload(self.__model__.uuid, context) @@ -249,6 +251,8 @@ def commit(self) -> Self: assert self.config is not None self.__model__.predicate = self.compute_predicate() + self.on_commit() + # commit to index for k, v in self.__related__.items(): if v is None: @@ -277,8 +281,20 @@ def commit(self) -> Self: self.save_file(filepath, data) self._deferred_data = {} + self.on_after_commit() + return self + def on_before_commit(self): + """Event hook before interface is committed.""" + + def on_commit(self): + """Event hook during interface commit when uuid, config, context + and predicate have been computed and commit is about to be performed""" + + def on_after_commit(self): + """Event hook after interface has been committed.""" + @belongs_to def project(): from machinable.project import Project