bumpversion.hooks
Implementation of the hook interface.
PREFIX
PREFIX = 'BVHOOK_'logger
logger = get_indented_logger(__name__)SHELL_SYNTAX_RE
SHELL_SYNTAX_RE = re.compile('[|;&`$<>()\\n\\r]')has_shell_syntax
def has_shell_syntax(script: str) -> boolReturn True if the command string contains shell metacharacters.
run_command
def run_command(script: str, environment: Optional[dict] = None) -> subprocess.CompletedProcessRun a command using argv-based execution (shell=False).
base_env
def base_env(config: Config) -> Dict[str, str]Provide the base environment variables.
scm_env
def scm_env(config: Config) -> Dict[str, str]Provide the scm environment variables.
version_env
def version_env(version: Version, version_prefix: str) -> Dict[str, str]Provide the environment variables for each version component with a prefix.
new_version_env
def new_version_env(config: Config, current_version: Version, new_version: Version) -> Dict[str, str]Provide the environment dictionary for new_version serialized and tag name.
hook_context
def hook_context(config: Config, current_version: Version, new_version: Optional[Version] = None) -> Dict[str, str]Build a context dictionary for formatting hook command strings.
Only version-related keys are included so that unrelated braces in a hook command are not accidentally substituted.
format_hooks
def format_hooks(hooks: List[str], context: Dict[str, str]) -> List[str]Replace known version placeholders in hook command strings.
Placeholders that do not match a key in context are left untouched. Values are shell-quoted (except on Windows) so whitespace or quotes in a value cannot add argv elements.
get_setup_hook_env
def get_setup_hook_env(config: Config, current_version: Version) -> Dict[str, str]Provide the environment dictionary for setup_hooks.
get_pre_commit_hook_env
def get_pre_commit_hook_env(config: Config, current_version: Version, new_version: Version) -> Dict[str, str]Provide the environment dictionary for pre_commit_hooks.
get_post_commit_hook_env
def get_post_commit_hook_env(config: Config, current_version: Version, new_version: Version) -> Dict[str, str]Provide the environment dictionary for post_commit_hooks.
run_hooks
def run_hooks(hooks: List[str], env: Dict[str, str], dry_run: bool = False, allow_shell_hooks: bool = False, context: Optional[Dict[str, str]] = None) -> NoneRun a list of command-line programs, defaulting to safe argv-based execution.
context is used for placeholder substitution only when it is not None and allow_shell_hooks is false; None and {} both mean no substitution.
run_setup_hooks
def run_setup_hooks(config: Config, current_version: Version, dry_run: bool = False) -> NoneRun the setup hooks.
run_pre_commit_hooks
def run_pre_commit_hooks(config: Config, current_version: Version, new_version: Version, dry_run: bool = False) -> NoneRun the pre-commit hooks.
run_post_commit_hooks
def run_post_commit_hooks(config: Config, current_version: Version, new_version: Version, dry_run: bool = False) -> NoneRun the post-commit hooks.