semantic_release.version.declarations.file module

class semantic_release.version.declarations.file.FileVersionDeclaration(path: Path | str, stamp_format: VersionStampType)[source]

Bases: IVersionReplacer

IVersionReplacer implementation that replaces the entire file content with the version string.

This is useful for files that contain only a version number, such as VERSION files or similar single-line version storage files.

property content: str

A cached property that stores the content of the configured source file.

classmethod from_string_definition(replacement_def: str) FileVersionDeclaration[source]

Create an instance of self from a string representing one item of the “version_variables” list in the configuration.

This method expects a definition in the format: “file:*:format_type”

where: - file is the path to the file - * is the literal asterisk character indicating file replacement - format_type is either “nf” (number format) or “tf” (tag format)

parse() set[Version][source]

Deprecated since version 10.6.0: Function is unused and will be removed in a future release

replace(new_version: Version) str[source]

Replace the file content with the new version string.

Parameters:

new_version – The new version number as a Version instance

Returns:

The new content (just the version string)

update_file_w_version(new_version: Version, noop: bool = False) Path | None[source]

This method reads the underlying file, replaces each occurrence of the matched pattern, then writes the updated file.

Parameters:

new_version – The new version number as a Version instance