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.
DataFileUpdater
¶
DataFileUpdater(
file_change: FileChange,
version_part_configs: Dict[str, VersionComponentSpec],
)
FileUpdater
¶
FileUpdater(
file_change: FileChange,
version_config: VersionConfig,
search: Optional[str] = None,
replace: Optional[str] = None,
)
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
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