Skip to content
Back to top
View this page

# semantic_release.version.declarations.pattern module

class semantic_release.version.declarations.pattern.PatternVersionDeclaration(path: Path | str, search_text: str, stamp_format: VersionStampType)

  Bases: `IVersionReplacer`

  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.

  property content: str

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

  classmethod from_string_definition(replacement_def: str, tag_format: str) → PatternVersionDeclaration

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

  parse() → set[Version]

    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.

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

  replace(new_version: Version) → str

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

    Parameters:

      new_version – The new version number as a Version instance

  update_file_w_version(new_version: Version, noop: bool = False) → Path | None

    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

class semantic_release.version.declarations.pattern.VersionSwapper(new_version_str: str, group_match_name: str)

  Bases: `object`

  Callable to replace a version number in a string with a new version number.