Version-bump your software with a single command
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Command-line interface providing comprehensive version management functionality. The CLI is the primary user interface for bump-my-version, offering interactive commands with extensive configuration options for automating version workflows.
The primary CLI command group that provides the foundation for all bump-my-version operations.
@click.group(
context_settings={"help_option_names": ["-h", "--help"]},
add_help_option=True,
)
@click.version_option(version=__version__)
@click.pass_context
def cli(ctx: Context) -> None:
"""Version bump your Python project."""Usage:
bump-my-version --help
bump-my-version --versionPrimary command for incrementing version numbers and updating project files. Supports both component-based bumping (patch, minor, major) and explicit version setting.
@cli.command(context_settings={"ignore_unknown_options": True})
@click.argument("args", nargs=-1, type=str)
@config_option("--config-file", envvar="BUMPVERSION_CONFIG_FILE", help="Config file to read most of the variables from.")
@click.option("-v", "--verbose", count=True, required=False, envvar="BUMPVERSION_VERBOSE", help="Print verbose logging to stderr. Can specify several times for more verbosity.")
@click.option("--allow-dirty/--no-allow-dirty", default=None, required=False, envvar="BUMPVERSION_ALLOW_DIRTY", help="Don't abort if working directory is dirty, or explicitly abort if dirty.")
@click.option("--current-version", metavar="VERSION", required=False, envvar="BUMPVERSION_CURRENT_VERSION", help="Version that needs to be updated")
@click.option("--new-version", metavar="VERSION", required=False, envvar="BUMPVERSION_NEW_VERSION", help="New version that should be in the files")
@click.option("--parse", metavar="REGEX", required=False, envvar="BUMPVERSION_PARSE", help="Regex parsing the version string")
@click.option("--serialize", metavar="FORMAT", multiple=True, envvar="BUMPVERSION_SERIALIZE", help="How to format what is parsed back to a version")
@click.option("--search", metavar="SEARCH", required=False, envvar="BUMPVERSION_SEARCH", help="Template for search string")
@click.option("--replace", metavar="REPLACE", required=False, envvar="BUMPVERSION_REPLACE", help="Template for replace string")
@click.option("--regex/--no-regex", default=None, envvar="BUMPVERSION_REGEX", help="Treat the search parameter as a regex pattern")
@click.option("--no-configured-files", is_flag=True, envvar="BUMPVERSION_NO_CONFIGURED_FILES", help="Only update files specified on the command line")
@click.option("--ignore-missing-files", is_flag=True, envvar="BUMPVERSION_IGNORE_MISSING_FILES", help="Ignore missing files when searching")
@click.option("--ignore-missing-version", is_flag=True, envvar="BUMPVERSION_IGNORE_MISSING_VERSION", help="Ignore missing version in files when searching")
@click.option("--dry-run", "-n", is_flag=True, envvar="BUMPVERSION_DRY_RUN", help="Don't write any files, just pretend.")
@click.option("--commit/--no-commit", default=None, envvar="BUMPVERSION_COMMIT", help="Commit to version control")
@click.option("--tag/--no-tag", default=None, envvar="BUMPVERSION_TAG", help="Create a tag in version control")
@click.option("--sign-tags/--no-sign-tags", default=None, envvar="BUMPVERSION_SIGN_TAGS", help="Sign tags if created")
@click.option("--tag-name", metavar="TAG_NAME", required=False, envvar="BUMPVERSION_TAG_NAME", help="Tag name (only works with --tag)")
@click.option("--tag-message", metavar="TAG_MESSAGE", required=False, envvar="BUMPVERSION_TAG_MESSAGE", help="Tag message")
@click.option("-m", "--message", metavar="COMMIT_MSG", required=False, envvar="BUMPVERSION_MESSAGE", help="Commit message")
@click.option("--commit-args", metavar="COMMIT_ARGS", required=False, envvar="BUMPVERSION_COMMIT_ARGS", help="Extra arguments to commit command")
def bump(
args: List[str],
config_file: Optional[str],
verbose: int,
allow_dirty: Optional[bool],
current_version: Optional[str],
new_version: Optional[str],
parse: Optional[str],
serialize: Optional[List[str]],
search: Optional[str],
replace: Optional[str],
regex: Optional[bool],
no_configured_files: bool,
ignore_missing_files: bool,
ignore_missing_version: bool,
dry_run: bool,
commit: Optional[bool],
tag: Optional[bool],
sign_tags: Optional[bool],
tag_name: Optional[str],
tag_message: Optional[str],
message: Optional[str],
commit_args: Optional[str],
) -> None:
"""
Change the version by bumping VERSION_PART or setting a NEW_VERSION.
Bump version components (major, minor, patch) or set explicit version.
Updates files, creates commits and tags according to configuration.
"""Usage Examples:
# Bump version components
bump-my-version bump patch
bump-my-version bump minor
bump-my-version bump major
# Set specific version
bump-my-version bump --new-version 2.1.0
# Bump with options
bump-my-version bump patch --commit --tag --dry-run
# Bump specific files only
bump-my-version bump patch setup.py __init__.pyDisplay current configuration, version information, and potential version changes in various output formats.
@click.command()
@click.argument("args", nargs=-1, type=str)
@click.option("--config-file", type=str, help="Configuration file to use")
@click.option("--format",
type=click.Choice(['default', 'yaml', 'json']),
default='default',
help="Output format")
@click.option("--increment", type=str, help="Version part to increment for preview")
def show(
args: Tuple[str, ...],
config_file: Optional[str] = None,
format: str = 'default',
increment: Optional[str] = None
) -> None:
"""
Show current configuration information and version components.
Display configuration values, current version, or preview version changes.
Supports multiple output formats and can show specific configuration keys.
"""Usage Examples:
# Show all configuration
bump-my-version show
# Show specific values
bump-my-version show current_version
bump-my-version show new_version --increment patch
# Show in different formats
bump-my-version show --format yaml
bump-my-version show --format json
# Show with increment preview
bump-my-version show new_version --increment minorReplace version strings in files without performing SCM operations. Useful for testing version changes or manual file updates.
@click.command()
@click.argument("files", nargs=-1, type=str)
@click.option("--config-file", type=str, help="Configuration file to use")
@click.option("--current-version", type=str, help="Current version to replace")
@click.option("--new-version", type=str, required=True, help="New version to set")
@click.option("--parse", type=str, help="Regex pattern to parse version")
@click.option("--serialize", type=str, multiple=True, help="Serialization format")
@click.option("--search", type=str, help="Template for search string")
@click.option("--replace", type=str, help="Template for replace string")
@click.option("--regex/--no-regex", default=False, help="Use regex for search")
@click.option("--dry-run", is_flag=True, help="Don't modify files")
@click.option("--ignore-missing-version", is_flag=True, help="Ignore missing version in files")
@click.option("--ignore-missing-files", is_flag=True, help="Ignore missing files")
@click.option("--verbose", "-v", count=True, help="Increase verbosity")
def replace(
files: Tuple[str, ...],
config_file: Optional[str] = None,
current_version: Optional[str] = None,
new_version: str = None,
parse: Optional[str] = None,
serialize: Tuple[str, ...] = (),
search: Optional[str] = None,
replace: Optional[str] = None,
regex: bool = False,
dry_run: bool = False,
ignore_missing_version: bool = False,
ignore_missing_files: bool = False,
verbose: int = 0
) -> None:
"""
Replace version strings in files without SCM operations.
Updates version strings in specified files without creating commits or tags.
Useful for testing version changes or manual file updates.
"""Usage Examples:
# Replace version in specific files
bump-my-version replace --new-version 2.1.0 setup.py __init__.py
# Replace with custom patterns
bump-my-version replace --new-version 2.1.0 --search "version = '{current_version}'" file.py
# Dry run replacement
bump-my-version replace --new-version 2.1.0 --dry-run setup.pyGenerate sample configuration files interactively or with default settings to bootstrap new projects.
@click.command(name="sample-config")
@click.option("--no-prompt", "--prompt", is_flag=True, help="Skip interactive prompts")
@click.option("--destination", type=str, default=".bumpversion.toml", help="Output file path")
def sample_config(prompt: bool, destination: str) -> None:
"""
Generate a sample configuration file.
Creates configuration file with default settings or through interactive prompts.
Supports both automated and interactive configuration setup.
"""Usage Examples:
# Generate with prompts
bump-my-version sample-config
# Generate with defaults
bump-my-version sample-config --no-prompt
# Specify output location
bump-my-version sample-config --destination pyproject.tomlVisualize potential version bump paths showing how each version component would change from current or specified version.
@click.command(name="show-bump")
@click.argument("version", nargs=1, type=str, required=False, default="")
@click.option("--config-file", type=str, help="Configuration file to use")
@click.option("--ascii", is_flag=True, help="Use ASCII characters only")
@click.option("--verbose", "-v", count=True, help="Increase verbosity")
def show_bump(
version: str,
config_file: Optional[str] = None,
ascii: bool = False,
verbose: int = 0
) -> None:
"""
Visualize version bump possibilities.
Shows tree diagram of potential version changes for each component.
Helps understand how version bumping affects different parts.
"""Usage Examples:
# Show bumps for current version
bump-my-version show-bump
# Show bumps for specific version
bump-my-version show-bump 1.2.3
# ASCII-only output
bump-my-version show-bump --asciiAvailable across all commands:
--config-file: Specify configuration file path (default: auto-detected)--verbose, -v: Increase output verbosity (can be repeated)--help, -h: Show help message--version: Show version informationCommands support reading configuration from:
pyproject.toml (under [tool.bumpversion]).bumpversion.toml.bumpversion.cfg (legacy format)setup.cfg (legacy format)Configuration can be overridden using environment variables with BMP_ prefix:
export BMP_CURRENT_VERSION="1.0.0"
export BMP_COMMIT="true"
export BMP_TAG="true"# In CI pipeline
bump-my-version bump patch --commit --tag
git push --follow-tags# .pre-commit-config.yaml integration
- repo: local
hooks:
- id: bump-version
name: Bump version
entry: bump-my-version bump patch --dry-run
language: system- name: Bump version and push tag
run: |
bump-my-version bump patch --commit --tag
git push --follow-tagsInstall with Tessl CLI
npx tessl i tessl/pypi-bump-my-version