Pre-commands#
Conda commands can be extended with the conda_pre_commands plugin hook.
By specifying the set of commands you would like to use in the run_for configuration
option, you can execute code via the action option before these commands are run.
The functions are provided a command argument representing the name
of the command currently running.
If you would like to target conda env commands, prefix the command name with env_.
For example, conda env list would be passed to run_for as env_list.
- class CondaPreCommand#
Return type to use when defining a conda pre-command plugin hook.
For details on how this is used, see
conda_pre_commands().- Parameters:
name -- Pre-command name (e.g.,
custom_plugin_pre_commands).action -- Callable which contains the code to be run.
run_for -- Represents the command(s) this will be run on (e.g.
installorcreate).
- action: collections.abc.Callable[[str], None]#
- conda_pre_commands() collections.abc.Iterable[conda.plugins.types.CondaPreCommand]#
Register pre-command functions in conda.
Shell activation commands avoid loading the plugin manager for startup performance. These hooks run for
conda shell.* activate,deactivate,reactivate, andhookonly if the plugin manager was already loaded by another code path.Note
Pre-command hooks for
conda runand shell activation commands (activate,deactivate,reactivate, andhook) are pending deprecation. Hook support for these commands will be deprecated in 27.3 and removed in 27.9. Matching hooks continue to run during the deprecation period.Warnings are emitted when hook definitions are collected, even for other commands. These
run_forvalues remain supported for plugin subcommands with the same names.Example:
from conda import plugins def example_pre_command(command): print("pre-command action") @plugins.hookimpl def conda_pre_commands(): yield plugins.types.CondaPreCommand( name="example-pre-command", action=example_pre_command, run_for={"install", "create"}, )