Skip to content

Commit

Permalink
fix: tvm list command error (#68)
Browse files Browse the repository at this point in the history
* fix: improve tutor versions sorter

* chore: add packaging dep to manage version comparison

* chore: upgrade dependencies

---------

Co-authored-by: Brayan Ceron <[email protected]>
  • Loading branch information
luisfelipec95 and bra-i-am authored May 15, 2024
1 parent ad92fa8 commit 53e9427
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 19 deletions.
1 change: 1 addition & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ jinja2
pyyaml
GitPython
virtualenv
packaging
10 changes: 6 additions & 4 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ click==8.1.7
# via -r requirements/base.in
distlib==0.3.8
# via virtualenv
filelock==3.13.3
filelock==3.14.0
# via virtualenv
gitdb==4.0.11
# via gitpython
gitpython==3.1.43
# via -r requirements/base.in
idna==3.6
idna==3.7
# via requests
jinja2==3.1.3
# via -r requirements/base.in
markupsafe==2.1.5
# via jinja2
platformdirs==4.2.0
packaging==24.0
# via -r requirements/base.in
platformdirs==4.2.1
# via virtualenv
pyyaml==6.0.1
# via -r requirements/base.in
Expand All @@ -34,5 +36,5 @@ smmap==5.0.1
# via gitdb
urllib3==2.2.1
# via requests
virtualenv==20.25.1
virtualenv==20.26.1
# via -r requirements/base.in
19 changes: 10 additions & 9 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ charset-normalizer==3.3.2
# requests
click==8.1.7
# via -r requirements/base.txt
coverage==7.4.4
coverage==7.5.0
# via -r requirements/dev.in
dill==0.3.8
# via pylint
distlib==0.3.8
# via
# -r requirements/base.txt
# virtualenv
exceptiongroup==1.2.0
exceptiongroup==1.2.1
# via pytest
filelock==3.13.3
filelock==3.14.0
# via
# -r requirements/base.txt
# virtualenv
Expand All @@ -36,7 +36,7 @@ gitdb==4.0.11
# gitpython
gitpython==3.1.43
# via -r requirements/base.txt
idna==3.6
idna==3.7
# via
# -r requirements/base.txt
# requests
Expand All @@ -58,16 +58,17 @@ mccabe==0.7.0
# via pylint
packaging==24.0
# via
# -r requirements/base.txt
# pudb
# pytest
parso==0.8.4
# via jedi
platformdirs==4.2.0
platformdirs==4.2.1
# via
# -r requirements/base.txt
# pylint
# virtualenv
pluggy==1.4.0
pluggy==1.5.0
# via pytest
pudb==2024.1
# via -r requirements/dev.in
Expand All @@ -81,7 +82,7 @@ pylint==2.14.5
# via
# -c requirements/constraints.txt
# -r requirements/dev.in
pytest==8.1.1
pytest==8.2.0
# via -r requirements/dev.in
pyyaml==6.0.1
# via -r requirements/base.txt
Expand All @@ -107,13 +108,13 @@ urllib3==2.2.1
# via
# -r requirements/base.txt
# requests
urwid==2.6.10
urwid==2.6.11
# via
# pudb
# urwid-readline
urwid-readline==0.14
# via pudb
virtualenv==20.25.1
virtualenv==20.26.1
# via -r requirements/base.txt
wcwidth==0.2.13
# via urwid
Expand Down
2 changes: 1 addition & 1 deletion requirements/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ docutils==0.17.1
# recommonmark
# sphinx
# sphinx-panels
idna==3.6
idna==3.7
# via requests
imagesize==1.4.1
# via sphinx
Expand Down
3 changes: 1 addition & 2 deletions requirements/pip-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ packaging==24.0
# via build
pip-tools==7.4.1
# via -r requirements/pip-tools.in
pyproject-hooks==1.0.0
pyproject-hooks==1.1.0
# via
# build
# pip-tools
tomli==2.0.1
# via
# build
# pip-tools
# pyproject-hooks
wheel==0.43.0
# via pip-tools

Expand Down
2 changes: 1 addition & 1 deletion requirements/pip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ wheel==0.43.0
# The following packages are considered to be unsafe in a requirements file:
pip==24.0
# via -r requirements/pip.in
setuptools==69.2.0
setuptools==69.5.1
# via -r requirements/pip.in
3 changes: 1 addition & 2 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,7 +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 = 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 @@ -9,6 +9,7 @@
from typing import List, Optional

import requests
from packaging.version import parse

from tvm.share.domain.client_logger_repository import ClientLoggerRepository
from tvm.version_manager.domain.tutor_version import TutorVersion
Expand Down Expand Up @@ -224,6 +225,20 @@ def use_version(self, version: TutorVersion) -> None:
self.set_current_info(data=data)
self.set_switcher()

def __valid_version_comparer(self, version_name: str):
"""
Turn version name to a valid version object.
Uses '+' 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]):
"""Sort tutor versions in ascending order."""
return sorted(versions, reverse=False, key=self.__valid_version_comparer)

@staticmethod
def version_is_installed(version: str) -> bool:
"""Validate if tutor version is installed."""
Expand Down

0 comments on commit 53e9427

Please sign in to comment.