Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for calendar versioning #244

Open
nlathia opened this issue Jun 26, 2023 · 1 comment
Open

Add support for calendar versioning #244

nlathia opened this issue Jun 26, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@nlathia
Copy link
Contributor

nlathia commented Jun 26, 2023

We decided to adopt a different versioning approach over UUID - CalVer with a short UUID for ensuring uniqueness:

https://mlops-community.slack.com/archives/C0227QJCDS8/p1687777453332889?thread_ts=1687777412.934619&cid=C0227QJCDS8

@nlathia nlathia added the enhancement New feature or request label Jun 27, 2023
@nlathia
Copy link
Contributor Author

nlathia commented Jul 6, 2023

Example from slack:

import uuid
from datetime import datetime, timezone
from typing import List

from packaging.version import parse, Version


class CalVerUUID:
    """
    A class to generate, parse and sort version strings based on Calendar Versioning (CalVer)
    with an appended UUID for ensuring uniqueness.
    """

    sorting_key = parse

    @staticmethod
    def generate_version() -> str:
        """
        Generates a new version string with the current UTC timestamp down to the second and a unique UUID.

        The returned string has the format: 'YYYY.MM.DD.HH.MM.SS+UUID'

        Returns:
        --------
        str
            A version string.

        Example:
        --------
        >>> print(CalVerUUID.generate_version())
        '2023.06.25.15.30.45+1a2b3c4d'
        """
        now = datetime.now(tz=timezone.utc)
        timestamp_str = now.strftime("%Y.%m.%d.%H.%M.%S")
        # Generate a short unique identifier
        uuid_str = str(uuid.uuid4())[:8]
        return f"{timestamp_str}+{uuid_str}"

    @staticmethod
    def parse_version(version_str: str) -> Version:
        return parse(version_str)

    @staticmethod
    def sort_versions(version_list: List[str]) -> List[str]:
        """
        Sorts a list of version strings based on their timestamp and returns the sorted list.
        """
        return sorted(version_list, key=CalVerUUID.sorting_key, reverse=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant