semantic_release.history package

History

class semantic_release.history.PatternVersionDeclaration(path: str, pattern: str)[source]

Bases: VersionDeclaration

Represent a version number in a particular file.

The version number is identified by a regular expression. Methods are provided both the read the version number from the file, and to update the file with a new version number. Use the load_version_patterns() factory function to create the version patterns specified in the config files.

parse() Set[str][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: str)[source]

Update the versions matching this pattern.

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 string

class semantic_release.history.TomlVersionDeclaration(path, key)[source]

Bases: VersionDeclaration

parse() Set[str][source]

Return the versions.

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 it falls on the caller to check for this condition.

replace(new_version: str) None[source]

Update the versions.

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 string

class semantic_release.history.VersionDeclaration(path: Union[str, Path])[source]

Bases: ABC

static from_pattern(config_str: str)[source]

Instantiate a PatternVersionDeclaration from a string specifying a path and a regular expression matching the version number.

static from_toml(config_str: str)[source]

Instantiate a TomlVersionDeclaration from a string specifying a path and a key matching the version number.

static from_variable(config_str: str)[source]

Instantiate a PatternVersionDeclaration from a string specifying a path and a variable name.

abstract parse() Set[str][source]

Return the versions.

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 it falls on the caller to check for this condition.

abstract replace(new_version: str)[source]

Update the versions.

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 string

semantic_release.history.get_commit_release_version_pattern()[source]
semantic_release.history.get_current_release_version() str[source]

Get current release version from tag or commit message (no going back in config file), depending on configuration. This will return the current release version (NOT prerelease), instead of just the current version

Returns:

A string with the current version number

semantic_release.history.get_current_release_version_by_commits() str[source]

Return the current release version (NOT prerelease) version.

Returns:

A string with the current version number.

semantic_release.history.get_current_release_version_by_tag() str[source]

Find the current version of the package in the current working directory using git tags.

Returns:

A string with the version number or 0.0.0 on failure.

semantic_release.history.get_current_version() str[source]

Get current version from tag or version variable, depending on configuration. This can be either a release or prerelease version

Returns:

A string with the current version number

semantic_release.history.get_current_version_by_config_file() str[source]

Get current version from the version variable defined in the configuration.

Returns:

A string with the current version number

Raises:

ImproperConfigurationError – if either no versions are found, or

multiple versions are found.

semantic_release.history.get_current_version_by_tag() str[source]

Find the current version of the package in the current working directory using git tags.

Returns:

A string with the version number or 0.0.0 on failure.

semantic_release.history.get_new_version(current_version: str, current_release_version: str, level_bump: str, prerelease: bool = False, prerelease_patch: bool = True) str[source]

Calculate the next version based on the given bump level with semver.

Parameters:
  • current_version – The version the package has now.

  • level_bump – The level of the version number that should be bumped. Should be ‘major’, ‘minor’ or ‘patch’.

  • prerelease – Should the version bump be marked as a prerelease

Returns:

A string with the next version number.

semantic_release.history.get_pattern_with_commit_subject(pattern)[source]
semantic_release.history.get_prerelease_pattern()[source]
semantic_release.history.get_previous_release_version(version: str) Optional[str][source]

Return the version prior to the given version.

Parameters:

version – A string with the version number.

Returns:

A string with the previous version number.

semantic_release.history.get_previous_version(version: str) Optional[str][source]

Return the version prior to the given version.

Parameters:

version – A string with the version number.

Returns:

A string with the previous version number.

semantic_release.history.get_release_version_pattern()[source]
semantic_release.history.get_version_pattern()[source]
semantic_release.history.load_version_declarations() List[VersionDeclaration][source]

Create the VersionDeclaration objects specified by the config file.

semantic_release.history.set_new_version(new_version: str) bool[source]

Update the version number in each configured location.

Parameters:

new_version – The new version number as a string.

Returns:

True if it succeeded.

Submodules