Skip to content

version_utils

appimage_updater.utils.version_utils

Version handling utilities for the AppImage Updater.

This module provides centralized version normalization, formatting, and comparison utilities to ensure consistent version handling across the application.

create_nightly_version(asset)

Create version string for nightly builds using asset creation date.

Parameters:

Name Type Description Default
asset Asset

Asset with creation date information

required

Returns:

Type Description
str

Date-based version string for nightly builds

Source code in src/appimage_updater/utils/version_utils.py
def create_nightly_version(asset: Asset) -> str:
    """Create version string for nightly builds using asset creation date.

    Args:
        asset: Asset with creation date information

    Returns:
        Date-based version string for nightly builds
    """
    date_str = asset.created_at.strftime("%Y-%m-%d")
    return date_str

extract_version_from_filename(filename, app_name)

Extract version from filename as fallback.

Parameters:

Name Type Description Default
filename str

Filename to extract version from

required
app_name str

Application name to remove from filename

required

Returns:

Type Description
str | None

Extracted version string or None if not found

Source code in src/appimage_updater/utils/version_utils.py
def extract_version_from_filename(filename: str, app_name: str) -> str | None:
    """Extract version from filename as fallback.

    Args:
        filename: Filename to extract version from
        app_name: Application name to remove from filename

    Returns:
        Extracted version string or None if not found
    """
    # Remove app name and common suffixes
    clean_name = filename.replace(app_name, "").replace(".AppImage", "").replace(".current", "")

    # Look for version patterns
    version_patterns = [
        r"[vV]?(\d+\.\d+\.\d+(?:-\w+)?)",  # v1.2.3 or v1.2.3-beta
        r"[vV]?(\d+\.\d+(?:-\w+)?)",  # v1.2 or v1.2-beta
        r"(\d{4}-\d{2}-\d{2})",  # Date format
    ]

    for pattern in version_patterns:
        match = re.search(pattern, clean_name)
        if match:
            # Normalize the extracted version
            return normalize_version_string(match.group(1))

    return None

format_version_display(version)

Format version for display, showing dates in a user-friendly format.

Parameters:

Name Type Description Default
version str | None

Version string to format for display

required

Returns:

Type Description
str

Formatted version string suitable for UI display

Examples:

>>> format_version_display("20250918")
"2025-09-18"
>>> format_version_display("2025-09-18")
"2025-09-18"
>>> format_version_display("2.3.1-beta")
"2.3.1-beta"
Source code in src/appimage_updater/utils/version_utils.py
def format_version_display(version: str | None) -> str:
    """Format version for display, showing dates in a user-friendly format.

    Args:
        version: Version string to format for display

    Returns:
        Formatted version string suitable for UI display

    Examples:
        >>> format_version_display("20250918")
        "2025-09-18"
        >>> format_version_display("2025-09-18")
        "2025-09-18"
        >>> format_version_display("2.3.1-beta")
        "2.3.1-beta"
    """
    if not version:
        return ""

    # Check if version is in date format (YYYY-MM-DD or YYYYMMDD)
    if re.match(r"^\d{4}-\d{2}-\d{2}$", version):
        # Already in YYYY-MM-DD format, return as-is
        return version
    elif re.match(r"^\d{8}$", version):
        # Convert YYYYMMDD to YYYY-MM-DD format
        return f"{version[:4]}-{version[4:6]}-{version[6:8]}"
    else:
        # Regular semantic version or other format
        return version

normalize_version_string(version)

Normalize version string to the current scheme.

This is the authoritative version normalization function used throughout the application. It handles various version formats and ensures consistency.

Parameters:

Name Type Description Default
version str

Raw version string from various sources

required

Returns:

Type Description
str

Normalized version string with consistent format

Examples:

>>> normalize_version_string("v2.3.1-beta")
"2.3.1-beta"
>>> normalize_version_string("2.11.3-x86")
"2.11.3"
>>> normalize_version_string("OrcaSlicer 2.3.1 beta Release")
"2.3.1-beta"
Source code in src/appimage_updater/utils/version_utils.py
def normalize_version_string(version: str) -> str:
    """Normalize version string to the current scheme.

    This is the authoritative version normalization function used throughout
    the application. It handles various version formats and ensures consistency.

    Args:
        version: Raw version string from various sources

    Returns:
        Normalized version string with consistent format

    Examples:
        >>> normalize_version_string("v2.3.1-beta")
        "2.3.1-beta"
        >>> normalize_version_string("2.11.3-x86")
        "2.11.3"
        >>> normalize_version_string("OrcaSlicer 2.3.1 beta Release")
        "2.3.1-beta"
    """
    version = _remove_version_prefix(version)

    # Try different normalization strategies in order of specificity
    result = _normalize_dash_separated_version(version)
    if result:
        return result

    result = _normalize_space_separated_version(version)
    if result:
        return result

    result = _normalize_simple_version(version)
    if result:
        return result

    return version