semantic_release.version.declaration module

class semantic_release.version.declaration.PatternVersionDeclaration(path: Path | str, search_text: str)[source]

Bases: VersionDeclarationABC

VersionDeclarationABC implementation representing a version number in a particular file. The version number is identified by a regular expression, which should be provided in search_text.

parse() set[semantic_release.version.version.Version][source]

Return the versions matching this pattern. Because a pattern can match in multiple places, this method returns a set of matches. Generally, there should only be one element in this set (i.e. even if the version is specified in multiple places, it should be the same version in each place), but it falls on the caller to check for this condition.

replace(new_version: Version) str[source]

Update the versions. This method reads the underlying file, replaces each occurrence of the matched pattern, then writes the updated file. :param new_version: The new version number as a Version instance

class semantic_release.version.declaration.TomlVersionDeclaration(path: Path | str, search_text: str)[source]

Bases: VersionDeclarationABC

VersionDeclarationABC implementation which manages toml-format source files.

parse() set[semantic_release.version.version.Version][source]

Look for the version in the source content

replace(new_version: Version) str[source]

Replace the version in the source content with new_version, and return the updated content.

class semantic_release.version.declaration.VersionDeclarationABC(path: Path | str, search_text: str)[source]

Bases: ABC

ABC for classes representing a location in which a version is declared somewhere within the source tree of the repository

property content: str

The content of the source file in which the version is stored. This property is cached in the instance variable _content

abstract parse() set[semantic_release.version.version.Version][source]

Return a set of the versions which can be parsed from the file. Because a source can match in multiple places, this method returns a set of matches. Generally, there should only be one element in this set (i.e. even if the version is specified in multiple places, it should be the same version in each place), but enforcing that condition is not mandatory or expected.

abstract replace(new_version: Version) str[source]

Update the versions. This method reads the underlying file, replaces each occurrence of the matched pattern, then writes the updated file. :param new_version: The new version number as a Version instance

write(content: str) None[source]

Write new content back to the source path. Use alongside .replace(): >>> class MyVD(VersionDeclarationABC): … def parse(self): … … def replace(self, new_version: Version): … … def write(self, content: str): …

>>> new_version = Version.parse("1.2.3")
>>> vd = MyVD("path", r"__version__ = (?P<version>\d+\d+\d+)")
>>> vd.write(vd.replace(new_version))