semantic_release.version.declaration module¶
- class semantic_release.version.declaration.VersionDeclarationABC(*args, **kwargs)[source]¶
Bases:
ABC
ABC for classes representing a location in which a version is declared somewhere within the source tree of the repository
Deprecated since version 9.20.0: Refactored to composition paradigm using the new IVersionReplacer interface. This class will be removed in a future release
- 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[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))