Skip to content

bumpversion.files ​

Methods for changing files.

logger ​

python
logger = get_indented_logger(__name__)

contains_pattern ​

python
def contains_pattern(search: re.Pattern, contents: str) -> bool

Does the search pattern match any part of the contents?

log_changes ​

python
def log_changes(file_path: str, file_content_before: str, file_content_after: str, dry_run: bool = False) -> None

Log the changes that would be made to the file.

Parameters

  • file_path: The path to the file
  • file_content_before: The file contents before the change
  • file_content_after: The file contents after the change
  • dry_run: True if this is a report-only job

ConfiguredFile ​

python
class ConfiguredFile(file_change: FileChange, version_config: VersionConfig, search: Optional[str] = None, replace: Optional[str] = None)

A file to modify in a configured way.

get_file_contents ​

python
def get_file_contents() -> str

Return the contents of the file.

Returns

  • The contents of the file

Raises

  • FileNotFoundError: if the file doesn't exist

write_file_contents ​

python
def write_file_contents(contents: str) -> None

Write the contents of the file.

make_file_change ​

python
def make_file_change(current_version: Version, new_version: Version, context: MutableMapping, dry_run: bool = False) -> None

Make the change to this file and write it, unless this is a dry run.

Prefer modify_files() for several files: it writes nothing unless every file could be changed.

get_changed_contents ​

python
def get_changed_contents(current_version: Version, new_version: Version, context: MutableMapping, file_contents: Optional[str] = None, dry_run: bool = False) -> Optional[str]

Return the contents of the file with the change made, without writing anything.

Parameters

  • current_version: The current version
  • new_version: The next version
  • context: The context used for rendering the version
  • file_contents: The contents to change instead of the file on disk, ex. with earlier changes not yet written
  • dry_run: True if this is a report-only job (only changes the wording of the log)

Returns

  • The changed contents, or None if the file or the version is missing and that is ignored.

Raises

  • FileNotFoundError: if the file doesn't exist and missing files are not ignored

resolve_file_config ​

python
def resolve_file_config(files: List[FileChange], version_config: VersionConfig, search: Optional[str] = None, replace: Optional[str] = None) -> List[ConfiguredFile]

Resolve the files, searching and replacing values according to the FileConfig.

Parameters

  • files: A list of file configurations
  • version_config: How the version should be changed
  • search: The search pattern to use instead of any configured search pattern
  • replace: The replace pattern to use instead of any configured replace pattern

Returns

  • A list of ConfiguredFiles

modify_files ​

python
def modify_files(files: List[ConfiguredFile], current_version: Version, new_version: Version, context: MutableMapping, dry_run: bool = False) -> None

Modify the files, searching and replacing values according to the FileConfig.

Parameters

  • files: The list of configured files
  • current_version: The current version
  • new_version: The next version
  • context: The context used for rendering the version
  • dry_run: True if this should be a report-only job

FileUpdater ​

python
class FileUpdater(file_change: FileChange, version_config: VersionConfig, search: Optional[str] = None, replace: Optional[str] = None)

A class to handle updating files.

update_file ​

python
def update_file(current_version: Version, new_version: Version, context: MutableMapping, dry_run: bool = False) -> None

Update the files.

DataFileUpdater ​

python
class DataFileUpdater(file_change: FileChange, version_part_configs: Dict[str, VersionComponentSpec])

A class to handle updating files.

update_file ​

python
def update_file(current_version: Version, new_version: Version, context: MutableMapping, dry_run: bool = False) -> None

Update the files.