Skip to content

Commit

Permalink
fix: improve tutor versions sorter
Browse files Browse the repository at this point in the history
  • Loading branch information
bra-i-am committed May 3, 2024
1 parent 7d256bb commit f3208cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 1 addition & 3 deletions tvm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import stat
import subprocess
import sys
from distutils.version import LooseVersion # pylint: disable=W0402
from typing import Optional

import click
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import subprocess
import zipfile
from typing import List, Optional
from packaging.version import parse

import requests

Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit f3208cb

Please sign in to comment.