fastsandpm.versioning.library_version API

Semantic version representation and comparison.

This module provides the LibraryVersion class for parsing, representing, and comparing semantic versions. Versions follow the semantic versioning specification with optional pre-release identifiers.

Supported Version Formats:
  • Standard: major.minor.patch (e.g., “1.2.3”)

  • Pre-release with dash: major.minor.patch-pre (e.g., “1.2.3-alpha”)

  • Pre-release with dot: major.minor.patch.pre (e.g., “1.2.3.rc1”)

  • Pre-release abbreviated: major.minor.patchpre (e.g., “1.2.3b2”)

Pre-release Stages (in order):
  • alpha (a): Development/testing phase

  • beta (b): Feature-complete but may have bugs

  • rc (release-candidate): Ready for release

Classes:

Example

>>> v1 = LibraryVersion("1.2.3")
>>> v2 = LibraryVersion("1.2.3-alpha")
>>> v1 > v2  # Release versions are greater than pre-release
True

Classes

class fastsandpm.versioning.library_version.LibraryVersion(version: str)[source]
class fastsandpm.versioning.library_version.LibraryVersion(*, major: int, minor: int, patch: int)
class fastsandpm.versioning.library_version.LibraryVersion(*, major: int, minor: int, patch: int, pre_stage: PreReleaseStage)
class fastsandpm.versioning.library_version.LibraryVersion(*, major: int, minor: int, patch: int, pre_stage: PreReleaseStage, pre: int)

Bases: object

Represents a semantic version with comparison support.

A semantic version consists of major, minor, and patch numbers, with an optional pre-release identifier. Versions can be compared using standard comparison operators.

The version format is: major.minor.patch[.pre] or major.minor.patch[-pre]

Examples: “1.0.0”, “2.3.1”, “1.0.0.alpha”, “2.0.0-rc1”

major

The major version number.

minor

The minor version number.

patch

The patch version number.

pre_stage

Optional pre-release stage (ALPHA, BETA, RELEASE_CANDIDATE).

pre

Optional pre-release number (e.g., 1 for rc1).

Example

>>> v1 = LibraryVersion("1.2.3")
>>> v2 = LibraryVersion(major=2, minor=0, patch=0)
>>> v1 < v2
True
static parse(version: str) tuple[int, int, int, PreReleaseStage | None, int | None][source]

Parse a version string into its components.

Parameters:

version – A version string in “major.minor.patch” or “major.minor.patch.pre” or “major.minor.patch-pre” or “major.minor.patchpre” format (e.g., “1.2.3b3”).

Returns:

A tuple of (major, minor, patch, pre_stage, pre) where pre_stage and pre are None if not specified.

Raises:

ValueError – If the version string doesn’t match expected format, or if major/minor/patch are not valid integers.

class fastsandpm.versioning.library_version.PreReleaseStage(*values)[source]

Bases: Enum

Enum representing pre-release stages in semantic versioning.

Pre-release stages indicate the maturity level of a version before its official release. They are ordered from least to most mature: ALPHA < BETA < RELEASE_CANDIDATE.

Example

>>> stage = PreReleaseStage.from_string("rc")
>>> stage
<PreReleaseStage.RELEASE_CANDIDATE: 'rc'>
classmethod from_string(value: str) PreReleaseStage | None[source]

Convert a string to a PreReleaseStage enum.

Parameters:

value – A string representing a pre-release stage. Supports full names (alpha, beta, release-candidate) and abbreviations (a, b, rc).

Returns:

The corresponding PreReleaseStage enum, or None if not recognized.

ALPHA = 'alpha'

Early development/testing phase.

BETA = 'beta'

Feature-complete but may contain bugs.

RELEASE_CANDIDATE = 'rc'

Ready for release.