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¶
_contains_change_pattern
¶
_contains_change_pattern(
search_expression: Pattern,
raw_search_expression: str,
version: Version,
context: MutableMapping,
) -> bool
Does the file contain the change pattern?
Parameters:
search_expression
-
The compiled search expression
TYPE:
Pattern
raw_search_expression
-
The raw search expression
TYPE:
str
version
-
The version to check, in case it’s not the same as the original
TYPE:
Version
context
-
The context to use
TYPE:
MutableMapping
Raises:
-
VersionNotFoundError
-
if the version number isn’t present in this file.
Returns:
-
bool
-
True if the version number is in fact present.
_get_serialized_version
¶
_get_serialized_version(
context_key: str,
version: Version,
context: MutableMapping,
) -> str
Get the serialized version.
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.
DataFileUpdater
¶
DataFileUpdater(
file_change: FileChange,
version_part_configs: Dict[str, VersionComponentSpec],
)
A class to handle updating files.
Functions¶
_update_toml_file
¶
_update_toml_file(
search_for: Pattern,
raw_search_pattern: str,
replace_with: str,
dry_run: bool = False,
) -> None
Update a TOML file.
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,
)
Functions¶
contains_pattern
¶
contains_pattern(search: 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
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
DEFAULT:
None
replace
-
The replace pattern to use instead of any configured replace pattern
DEFAULT:
None
Returns:
-
List[ConfiguredFile]
-
A list of ConfiguredFiles