Skip to content

files

Methods for changing files.

Classes

ConfiguredFile

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

A file to modify in a configured way.

Functions

get_file_contents
get_file_contents() -> str

Return the contents of the file.

Raises:

FileNotFoundError

if the file doesn’t exist

Returns:

str

The contents of the file

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

Make the change to the file.

write_file_contents
write_file_contents(contents: str) -> None

Write the contents of the file.

DataFileUpdater

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

A class to handle updating files.

Functions

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

Update the files.

FileUpdater

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

A class to handle updating files.

Functions

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

Update the files.

Functions

contains_pattern

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

Does the search pattern match any part of the contents?

log_changes

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

TYPE: str

file_content_before

The file contents before the change

TYPE: str

file_content_after

The file contents after the change

TYPE: str

dry_run

True if this is a report-only job

TYPE: bool

DEFAULT: False

modify_files

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

TYPE: List[ConfiguredFile]

current_version

The current version

TYPE: Version

new_version

The next version

TYPE: Version

context

The context used for rendering the version

TYPE: MutableMapping

dry_run

True if this should be a report-only job

TYPE: bool

DEFAULT: False

resolve_file_config

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

TYPE: List[FileChange]

version_config

How the version should be changed

TYPE: VersionConfig

search

The search pattern to use instead of any configured search pattern

TYPE: Optional[str]

DEFAULT: None

replace

The replace pattern to use instead of any configured replace pattern

TYPE: Optional[str]

DEFAULT: None

Returns:

List[ConfiguredFile]

A list of ConfiguredFiles