Version-bump your software with a single command
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Comprehensive configuration system supporting multiple file formats with validation, environment variable overrides, and automatic discovery. Provides both high-level configuration management and low-level configuration file operations.
Primary functions for loading and managing bump-my-version configuration from various sources.
def get_configuration(
config_file: Optional[str] = None,
**overrides: Any
) -> Config:
"""
Load configuration from files and apply overrides.
Discovers configuration files automatically or uses specified file,
validates settings, and applies environment variable and keyword overrides.
Args:
config_file: Specific configuration file path (optional)
**overrides: Configuration values to override
Returns:
Validated Config object with all settings
Raises:
ConfigurationError: Invalid configuration or file not found
"""
def set_config_defaults(
parsed_config: Dict[str, Any],
**overrides: Any
) -> Dict[str, Any]:
"""
Apply default values and overrides to parsed configuration.
Args:
parsed_config: Raw configuration dictionary
**overrides: Values to override
Returns:
Configuration dictionary with defaults applied
"""
def check_current_version(config: Config) -> str:
"""
Validate and return current version from configuration.
Args:
config: Configuration object
Returns:
Current version string
Raises:
ConfigurationError: Current version not found or invalid
"""Main configuration class with comprehensive validation and settings management.
class Config(BaseSettings):
"""
Main configuration class with Pydantic validation.
Contains all bump-my-version settings with automatic validation,
environment variable support, and default value management.
"""
# Version settings
current_version: str
parse: str = r"(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)"
serialize: List[str] = ["{major}.{minor}.{patch}"]
search: str = "{current_version}"
replace: str = "{new_version}"
regex: bool = False
ignore_missing_version: bool = False
# File settings
files: List[FileChange] = []
# SCM settings
commit: bool = False
tag: bool = False
sign_tags: bool = False
tag_name: str = "v{new_version}"
tag_message: str = "Bump version: {current_version} → {new_version}"
allow_dirty: bool = False
message: str = "Bump version: {current_version} → {new_version}"
commit_args: str = ""
# Hook settings
setup_hooks: List[str] = []
pre_commit_hooks: List[str] = []
post_commit_hooks: List[str] = []
# Version component settings
parts: Dict[str, VersionComponentSpec] = {}
@property
def version_config(self) -> VersionConfig:
"""Get VersionConfig object for version operations."""
@property
def scm_info(self) -> Optional[SCMInfo]:
"""Get SCM information for current repository."""
class FileChange(BaseModel):
"""
Configuration for file modification operations.
Defines how version strings should be found and replaced
in specific files with customizable patterns and options.
"""
filename: str
glob: Optional[str] = None
key_path: Optional[str] = None
search: Optional[str] = None
replace: Optional[str] = None
regex: bool = False
ignore_missing_version: bool = False
ignore_missing_file: bool = False
class VersionComponentSpec(BaseModel):
"""
Specification for version component behavior.
Defines how individual version components should increment,
their valid values, and special behaviors like calendar versioning.
"""
type: str = "numeric"
values: Optional[List[str]] = None
optional_value: Optional[str] = None
first_value: Optional[str] = None
independent: bool = False
always_increment: bool = False
calver_format: Optional[str] = None
class GlobalDefaults(BaseModel):
"""Default configuration values."""
current_version: str = "0.1.0"
parse: str = r"(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)"
serialize: List[str] = ["{major}.{minor}.{patch}"]
search: str = "{current_version}"
replace: str = "{new_version}"Functions for locating and reading configuration files from various sources.
def find_config_file(explicit_file: Optional[str] = None) -> Optional[Path]:
"""
Locate configuration file using standard search order.
Searches for configuration files in the following order:
1. Explicit file parameter
2. pyproject.toml (with [tool.bumpversion] section)
3. .bumpversion.toml
4. .bumpversion.cfg (legacy)
5. setup.cfg (legacy, with [bumpversion] section)
Args:
explicit_file: Specific file path to use
Returns:
Path to configuration file or None if not found
"""
def read_config_file(config_file: Optional[str] = None) -> Dict[str, Any]:
"""
Read and parse configuration from file.
Supports TOML and INI format files with automatic format detection
and legacy configuration migration.
Args:
config_file: Configuration file path
Returns:
Dictionary of configuration values
Raises:
ConfigurationError: File not found or invalid format
"""
def read_toml_file(file_path: Path) -> Dict[str, Any]:
"""
Read TOML configuration file.
Args:
file_path: Path to TOML file
Returns:
Configuration dictionary from TOML file
"""
def update_config_file(
config_file: Path,
current_version: str,
new_version: str,
is_new_version: bool
) -> None:
"""
Update configuration file with new version.
Args:
config_file: Path to configuration file
current_version: Current version string
new_version: New version string
is_new_version: Whether this is a new version
"""Support for modern Python project metadata and version management.
def get_pep621_info(config_file: Optional[str] = None) -> Optional[PEP621Info]:
"""
Extract PEP 621 project metadata from pyproject.toml.
Reads project version and metadata according to PEP 621 specification
for modern Python project configuration.
Args:
config_file: Path to pyproject.toml file
Returns:
PEP621Info object with project metadata or None
"""
class PEP621Info:
"""
Container for PEP 621 project metadata.
Holds version information and project details from pyproject.toml
according to Python packaging standards.
"""
project_name: str
version: Optional[str] = None
dynamic_version: bool = False
version_file: Optional[str] = None
@property
def has_version(self) -> bool:
"""Whether project has version information."""
@property
def is_dynamic_version(self) -> bool:
"""Whether version is marked as dynamic."""Interactive and automated configuration file generation.
def create_configuration(destination: str, prompt: bool) -> TOMLDocument:
"""
Create new configuration file interactively or with defaults.
Generates bump-my-version configuration through interactive prompts
or using default values for automated setup.
Args:
destination: Output file path
prompt: Whether to use interactive prompts
Returns:
TOMLDocument with generated configuration
"""
def get_defaults_from_dest(destination: str) -> Tuple[Dict, TOMLDocument]:
"""
Generate default configuration based on destination file.
Args:
destination: Target configuration file path
Returns:
Tuple of (defaults dictionary, TOML document)
"""Modern TOML-based configuration in pyproject.toml or .bumpversion.toml:
[tool.bumpversion]
current_version = "1.0.0"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
serialize = ["{major}.{minor}.{patch}"]
search = "{current_version}"
replace = "{new_version}"
regex = false
ignore_missing_version = false
tag = true
commit = true
message = "Bump version: {current_version} → {new_version}"
[[tool.bumpversion.files]]
filename = "setup.py"
search = "version='{current_version}'"
replace = "version='{new_version}'"
[[tool.bumpversion.files]]
filename = "src/mypackage/__init__.py"
[tool.bumpversion.parts.dev]
values = ["release", "dev"]Legacy configuration in .bumpversion.cfg or setup.cfg:
[bumpversion]
current_version = 1.0.0
commit = True
tag = True
[bumpversion:file:setup.py]
search = version='{current_version}'
replace = version='{new_version}'
[bumpversion:part:dev]
values = release,devConfiguration values can be overridden using environment variables with BMP_ prefix:
export BMP_CURRENT_VERSION="1.0.0"
export BMP_COMMIT="true"
export BMP_TAG="true"
export BMP_TAG_NAME="v{new_version}"
export BMP_MESSAGE="Release {new_version}"from bumpversion.config import get_configuration
# Load configuration automatically
config = get_configuration()
# Load specific configuration file
config = get_configuration(config_file="pyproject.toml")
# Load with overrides
config = get_configuration(
current_version="2.0.0",
commit=True,
tag=True
)
print(f"Current version: {config.current_version}")
print(f"Will commit: {config.commit}")
print(f"Files to update: {len(config.files)}")from bumpversion.config.files import find_config_file, read_config_file
# Find configuration file
config_path = find_config_file()
if config_path:
print(f"Found configuration: {config_path}")
# Read configuration
config_data = read_config_file(str(config_path))
print(f"Current version: {config_data.get('current_version')}")from bumpversion.config.create import create_configuration
# Create configuration interactively
toml_doc = create_configuration(
destination="pyproject.toml",
prompt=True
)
# Create with defaults
toml_doc = create_configuration(
destination=".bumpversion.toml",
prompt=False
)from bumpversion.config.files import get_pep621_info
# Get PEP 621 project information
pep621_info = get_pep621_info("pyproject.toml")
if pep621_info and pep621_info.has_version:
print(f"Project: {pep621_info.project_name}")
print(f"Version: {pep621_info.version}")
print(f"Dynamic version: {pep621_info.is_dynamic_version}")Install with Tessl CLI
npx tessl i tessl/pypi-bump-my-version