SemVer Versioning Utilities

Utilities.

class reasoner_validator.versioning.SemVer(prefix, major, minor, patch, prerelease, buildmetadata)

Bases: NamedTuple

Methods

count(value, /)

Return number of occurrences of value.

from_string(string[, ignore_prefix, ...])

Initializes a SemVer from a string.

index(value[, start, stop])

Return first index of value.

buildmetadata: str | None

Alias for field number 5

classmethod from_string(string: str, ignore_prefix: bool = False, core_fields: List[str] = ('major', 'minor', 'patch'), ext_fields: List[str] = ('prerelease', 'buildmetadata'))

Initializes a SemVer from a string. This is an ‘augmented’ SemVer which may also have an alphabetic prefix (for example, a ‘v’ for ‘version’ designation of a GitHub release). Note that the string may be a YAML file (path) name. In such a case, the SemVer is assumed to be encoded as a suffix in the root file name just before the .yaml file extension - e.g. my_schema_3.2.1-beta5.yaml - where the version suffix string is assumed to be delimited by a leading underscore character (i.e. “3.2.1-beta5” in the above example).

Parameters:
  • string – str, string encoding the SemVer.

  • ignore_prefix – bool, if set, any alphabetic prefix of the SemVer string is ignored (not recorded) the SemVer string value, e.g. a Git Release ‘v’ character (i.e. v1.2.3); Default: False.

  • core_fields – List[str], list of names of core SemVer field to explicitly set (may NOT be empty?) (default: [‘major’, ‘minor’, ‘patch’]).

  • ext_fields – List[str], list of names of extended SemVer fields to explicitly set (maybe empty?) (default: [‘prerelease’, ‘buildmetadata’]).

Returns:

major: int

Alias for field number 1

minor: int

Alias for field number 2

patch: int

Alias for field number 3

prefix: str

Alias for field number 0

prerelease: str | None

Alias for field number 4

exception reasoner_validator.versioning.SemVerError

Bases: Exception

Invalid semantic version.

exception reasoner_validator.versioning.SemVerUnderspecified

Bases: SemVerError

Semantic version underspecified.

reasoner_validator.versioning.get_latest_version(release_tag: str | None) str | None

Return the latest TRAPI version corresponding to the release tag given. Note that if the release tag looks like a YAML file, then it is assumed to be a direct schema specification. If a Git branch name in the schema repository, the branch name is also passed on.

Parameters:

release_tag – (possibly partial) SemVer string, Git branch name, or YAML schema file name identifying a release.

Returns:

‘best’ latest release of SemVer specification or the YAML file directly returned.