bumpversion.files
Methods for changing files.
logger
logger = get_indented_logger(__name__)contains_pattern
def contains_pattern(search: re.Pattern, contents: str) -> boolDoes the search pattern match any part of the contents?
log_changes
def log_changes(file_path: str, file_content_before: str, file_content_after: str, dry_run: bool = False) -> NoneLog the changes that would be made to the file.
Parameters
file_path: The path to the filefile_content_before: The file contents before the changefile_content_after: The file contents after the changedry_run: True if this is a report-only job
ConfiguredFile
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
def get_file_contents() -> strReturn the contents of the file.
Returns
- The contents of the file
Raises
FileNotFoundError: if the file doesn't exist
write_file_contents
def write_file_contents(contents: str) -> NoneWrite the contents of the file.
make_file_change
def make_file_change(current_version: Version, new_version: Version, context: MutableMapping, dry_run: bool = False) -> NoneMake 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
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 versionnew_version: The next versioncontext: The context used for rendering the versionfile_contents: The contents to change instead of the file on disk, ex. with earlier changes not yet writtendry_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
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 configurationsversion_config: How the version should be changedsearch: The search pattern to use instead of any configured search patternreplace: The replace pattern to use instead of any configured replace pattern
Returns
- A list of ConfiguredFiles
modify_files
def modify_files(files: List[ConfiguredFile], current_version: Version, new_version: Version, context: MutableMapping, dry_run: bool = False) -> NoneModify the files, searching and replacing values according to the FileConfig.
Parameters
files: The list of configured filescurrent_version: The current versionnew_version: The next versioncontext: The context used for rendering the versiondry_run: True if this should be a report-only job
FileUpdater
class FileUpdater(file_change: FileChange, version_config: VersionConfig, search: Optional[str] = None, replace: Optional[str] = None)A class to handle updating files.
update_file
def update_file(current_version: Version, new_version: Version, context: MutableMapping, dry_run: bool = False) -> NoneUpdate the files.
DataFileUpdater
class DataFileUpdater(file_change: FileChange, version_part_configs: Dict[str, VersionComponentSpec])A class to handle updating files.
update_file
def update_file(current_version: Version, new_version: Version, context: MutableMapping, dry_run: bool = False) -> NoneUpdate the files.