bump2version Documentation

repository·master·Indexed 22 days ago

https://github.com/c4urself/bump2version

A command-line tool to automate incrementing version numbers in source code files. It supports configurable versioning patterns, multiple file management via .bumpversion.cfg, and integration with Git or Mercurial for automated commits and tagging. It is language-agnostic and supports Python 3 and PyPy3. Note: bump2version is no longer maintained; the recommended successor is bump-my-version.

Tokens
5K
Snippets
17
Records
22
Agent score
78%

What's inside bump2version

  1. Overview of bump2version capabilities

    master

    bump2version is a command-line tool designed to simplify software releases by updating version strings across multiple files.

    Key features:

    • Configurable formats: Versioning patterns are highly customizable.
    • VCS Integration: Works with Git and Mercurial to read tags and write commits/tags, but can also function without any Version Control System.
    • Language Agnostic: It operates on text files, making it compatible with any programming language.
    • Runtime Support: Supports Python 3 and PyPy3. (For Python 2, use pip>=9 or pin bump2version<1).
  2. Compare bump2version with changelog building tools

    master

    If your goal is specifically to automate changelog generation, consider these tools:

    • towncrier: Assembles a changelog file from multiple snippets found within individual merge commits.
    • releases: Helps build a changelog specifically for Sphinx ReStructuredText.
    • gitchangelog: Generates a configurable changelog by searching through git commit history.
  3. How version parts work and how to customize them

    master

    A version string is composed of parts (e.g., 1.2.3 has major, minor, and patch). By default, these are numeric and incremented as integers.

    You can define custom parts (like alpha, beta, or build) using the [bumpversion:part:<name>] section. This is useful for non-numeric versioning schemes.

    [bumpversion:part:release_name]
    values =
      witty-warthog
      ridiculous-rat
      marvelous-mantis
  4. Compare bump2version with similar versioning tools

    master

    Depending on your workflow, you might consider these alternatives to bump2version:

    General Versioning Alternatives

    • bumpversion: The original project from which bump2version was forked.
    • tbump: A complete rewrite with a focus on UX and support for running hooks (commands) before or after a bump. Note: Currently only works for Git repositories.
    • zest.releaser: Manages Python package releases and centralizes the version number.
    • setuptools-scm: Determines version numbers based on version control tags and the working copy state.
    • incremental: Integrates with setuptools to maintain the version number in a _version.py file.
    • python-semantic-release: Automatically bumps semantic version numbers based on commit types (breaking, new, or bugfix).
    • PyCalVer: Similar to bump2version but specifically supports Calendar Versioning (CalVer).
    • Invocations (packaging.release): A set of tasks for invoke that assumes versioning is handled in _version.py using semantic versioning.
  5. Create a .bumpversion.cfg configuration file

    master

    To avoid specifying options on the command line every time, you can create a .bumpversion.cfg file in your project root. This file should be committed to your Version Control System (VCS).

    Precedence Rules:

    1. Command line options (highest)
    2. Configuration file
    3. Environment variables
    4. Defaults (lowest)

    If .bumpversion.cfg is not found, bump2version will look for setup.cfg.

    [bumpversion]
    current_version = 0.2.9
    commit = True
    tag = True
    
    [bumpversion:file:setup.py]
  6. Install bump2version via pip

    master

    Install or upgrade to the latest version of bump2version using pip. Note that installing bumpversion will also install the latest bump2version.

    Warning: bump2version is no longer maintained. It is recommended to switch to bump-my-version.

    pip install --upgrade bump2version
  7. Implement a Semantic Versioning workflow with bumpversion

    master

    You can use bumpversion to manage a full release lifecycle, moving from a stable version through development builds and release candidates to a final release.

    Typical workflow sequence:

    1. Initial Release: Start at a stable version (e.g., 1.0.0).
    2. Start Development: Use bumpversion patch to move to a development state (e.g., 1.0.1-dev1).
    3. Iterate Builds: Use bumpversion build to increment the build number during development (e.g., 1.0.1-dev2).
    4. Release Candidate: Use bumpversion release to transition to a release candidate (e.g., 1.0.1-rc1).
    5. Final Release: Use bumpversion release again to reach the final stable version (e.g., 1.0.1).
    # 1. Start development from 1.0.0
    bumpversion patch
    # Result: 1.0.1-dev1
    
    # 2. Increment build number
    bumpversion build
    # Result: 1.0.1-dev2
    
    # 3. Move to release candidate
    bumpversion release
    # Result: 1.0.1-rc1
    
    # 4. Increment build number for RC
    bumpversion build
    # Result: 1.0.1-rc2
    
    # 5. Finalize the release
    bumpversion release
    # Result: 1.0.1
  8. Use bump2version for single-file version bumping

    master

    You can use bump2version directly from the command line for simple, single-file operations without a configuration file.

    Syntax: bump2version [options] part [file]

    Arguments:

    • part (required): The segment of the version to increment (e.g., major, minor, patch).
    • file (optional): The specific file to modify. If omitted, no files are modified unless a configuration file is present.

    Note: If you have a configuration file but only want to modify the file passed via the CLI, use the --no-configured-files flag.

    # Bumping 0.5.1 to 0.6.0 in a specific file
    bump2version --current-version 0.5.1 minor src/VERSION
    
    # Bumping 1.1.9 to 2.0.0 in setup.py
    bump2version --current-version 1.1.9 major setup.py
  9. Maintain Go module versions in go.mod using parse and serialize

    master

    In Go projects, major versions (v2+) require the version number to be part of the module path in go.mod. You can automate this by using the parse and serialize options in your .bumpversion.cfg to extract and re-insert the version number into the module string.

    Configuration Example

    Add a section for go.mod in your .bumpversion.cfg:

    [bumpversion]
    current_version = 2.0.0
    commit = True
    
    [bumpversion:file:go.mod]
    parse = (?P<major>\d+)
    serialize = {major}
    search = module github.com/myorg/myproject/v{current_version}
    replace = module github.com/myorg/myproject/v{new_version}

    Usage

    If your go.mod contains module github.com/myorg/myproject/v2, running the following command will update it to v3:

    bump2version --new-version 3.0.0 major
    [bumpversion]
    current_version = 2.0.0
    commit = True
    
    [bumpversion:file:go.mod]
    parse = (?P<major>\d+)
    serialize = {major}
    search = module github.com/myorg/myproject/v{current_version}
    replace = module github.com/myorg/myproject/v{new_version}

    Command to execute the bump:

    bump2version --new-version 3.0.0 major

  10. Configure global bump2version settings

    master

    Global settings are defined in the [bumpversion] section of your configuration file. These settings apply to the entire bumping process.

    [bumpversion]
    current_version = 0.5.1
    new_version = 0.6.1
    tag = True
    sign_tags = False
    tag_name = v{new_version}
    tag_message = Bump version: {current_version} → {new_version}
    commit = True
    message = Bump version: {current_version} → {new_version}
    commit_args = -s
  11. Configure version bumping via CLI templates

    master

    When running bumpversion, you can use templates for searching and replacing version strings. These templates support context variables like {current_version}, {new_version}, and individual parts like {major}, {minor}, and {patch}.

    Commonly used flags for customization:

    • --search: The template for the string to find in files.
    • --replace: The template for the string to replace it with.
    • --tag-name: The template for the VCS tag name.
    • --message: The template for the commit message.
    # Example using custom search/replace templates
    bumpversion minor --search "Version: {current_version}" --replace "Version: {new_version}"