diff --git a/tvm/cli.py b/tvm/cli.py index f9ca4a6..4be0525 100644 --- a/tvm/cli.py +++ b/tvm/cli.py @@ -6,7 +6,6 @@ import stat import subprocess import sys -from distutils.version import LooseVersion # pylint: disable=W0402 from typing import Optional import click @@ -142,8 +141,7 @@ def list_versions(limit: int): version_names = lister(limit=limit) local_versions = version_manager.local_versions(f"{TVM_PATH}") version_names = list(set(version_names + local_versions)) - version_names = [str(version_name) for version_name in version_names] - version_names = sorted(version_names, reverse=False, key=LooseVersion) + version_names = version_manager.sort_tutor_versions(version_names) global_active = version_manager.current_version(f"{TVM_PATH}") project_version = None diff --git a/tvm/version_manager/infrastructure/version_manager_git_repository.py b/tvm/version_manager/infrastructure/version_manager_git_repository.py index 5dc90be..38887ff 100644 --- a/tvm/version_manager/infrastructure/version_manager_git_repository.py +++ b/tvm/version_manager/infrastructure/version_manager_git_repository.py @@ -7,6 +7,7 @@ import subprocess import zipfile from typing import List, Optional +from packaging.version import parse import requests @@ -224,6 +225,15 @@ def use_version(self, version: TutorVersion) -> None: self.set_current_info(data=data) self.set_switcher() + def tutor_versions_sorter(self, version_name: str): + # Use '+' symbol to define local version labels instead "@" + # https://peps.python.org/pep-0440/#local-version-identifiers + valid_version_name = version_name.replace("@", "+") + return parse(valid_version_name) + + def sort_tutor_versions(self, versions: List[TutorVersion]): + return sorted(versions, reverse=False, key=self.tutor_versions_sorter) + @staticmethod def version_is_installed(version: str) -> bool: """Validate if tutor version is installed."""