Post-transactions#
Solver transactions can be extended with the
conda_post_transaction_actions
plugin hook. This plugin hook accepts a subclass of
Action
which will be instantiated and appended to the end of conda's transaction
action list. When defining the class you must define the following methods:
execute
: this is the primary place to put code you wish to run during the action.verify
: this is run before the action is executed. This is a good place to check for conditions that would cause the action to fail.cleanup
: this is run after the action is executed. This is a good place to clean up any resources that were created during the action.reverse
: in the case of a failure, this allows you to define any reversal procedures.
- class CondaPostTransactionAction#
Return type to use when defining a post-transaction action hook.
For details on how this is used, see
conda_post_transaction_actions()
.- Parameters:
name -- Post transaction name (this is just a label)
action -- Action class which implements plugin behavior. See
Action
for implementation details
- action#
- name#
- conda_post_transaction_actions()#
Register post-transaction hooks.
Post-transaction hooks run after all other actions run in a UnlinkLinkTransaction. For information about the Action class, see
Action
.Example:
from conda import plugins from conda.core.path_actions import Action class PrintAction(Action): def verify(self): print("Performing verification...") self._verified = True def execute(self): print( self.transaction_context, self.target_prefix, self.unlink_precs, self.link_precs, self.remove_specs, self.update_specs, self.neutered_specs, ) def reverse(self): print("Reversing only happens when `execute` raises an exception.") def cleanup(self): print("Carrying out cleanup...") class PrintActionPlugin: @plugins.hookimpl def conda_post_transaction_actions( self, ) -> Iterable[plugins.CondaPostTransactionAction]: yield plugins.CondaPostTransactionAction( name="example-post-transaction-action", action=PrintAction, )