Skip to content

Commit

Permalink
fix: clean code and complete docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanDavidBuitrago committed Jun 23, 2022
1 parent dd23f15 commit e74f39a
Show file tree
Hide file tree
Showing 18 changed files with 145 additions and 70 deletions.
5 changes: 2 additions & 3 deletions tvm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ def list_versions(limit: int):
click.echo(click.style(name, fg=color))



@click.command(name="list")
@click.option('-l', '--limit', default=10, help='number of `latest versions` to list')
def list_versions_backup(limit: int):
Expand Down Expand Up @@ -520,12 +519,12 @@ def install_plugin(options):
def uninstall_plugin(options):
"""Use the package installer pip in current tutor version."""
repository = VersionManagerGitRepository()
uninstaller =TutorPluginUninstaller(repository=repository)
uninstaller = TutorPluginUninstaller(repository=repository)
options = list(options)
options.insert(0, "uninstall")
options.append("-y")
uninstaller(options)


@click.group(
name="config",
Expand Down
1 change: 1 addition & 0 deletions tvm/version_manager/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Version manager init."""
1 change: 1 addition & 0 deletions tvm/version_manager/application/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Application init."""
5 changes: 5 additions & 0 deletions tvm/version_manager/application/tutor_plugin_installer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
"""Tutor plugin installer application."""
from tvm.version_manager.domain.version_manager_repository import VersionManagerRepository


class TutorPluginInstaller:
"""Tutor plugin installer for version manager."""

def __init__(self, repository: VersionManagerRepository) -> None:
"""init."""
self.repository = repository

def __call__(self, options) -> None:
"""call."""
self.repository.install_plugin(options)
6 changes: 5 additions & 1 deletion tvm/version_manager/application/tutor_plugin_uninstaller.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from tvm.version_manager.domain.tutor_version import TutorVersion
"""Tutor plugin uninstaller application."""
from tvm.version_manager.domain.version_manager_repository import VersionManagerRepository


class TutorPluginUninstaller:
"""Tutor plugin uninstaller for version manager."""

def __init__(self, repository: VersionManagerRepository) -> None:
"""init."""
self.repository = repository

def __call__(self, options) -> None:
"""call."""
self.repository.uninstall_plugin(options)
5 changes: 5 additions & 0 deletions tvm/version_manager/application/tutor_version_enabler.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
"""Tutor version enabler application."""
from tvm.version_manager.domain.tutor_version import TutorVersion
from tvm.version_manager.domain.version_manager_repository import VersionManagerRepository


class TutorVersionEnabler:
"""Tutor version enabler for version manager."""

def __init__(self, repository: VersionManagerRepository) -> None:
"""init."""
self.repository = repository

def __call__(self, version: str) -> None:
"""call."""
version = TutorVersion(version)
self.repository.use_version(version)
5 changes: 5 additions & 0 deletions tvm/version_manager/application/tutor_version_finder.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
"""Tutor version finder application."""
from tvm.version_manager.domain.tutor_version import TutorVersion
from tvm.version_manager.domain.version_manager_repository import VersionManagerRepository


class TutorVersionFinder:
"""Tutor version finder for version manager."""

def __init__(self, repository: VersionManagerRepository):
"""init."""
self.repository = repository

def __call__(self, version: str) -> TutorVersion:
"""call."""
version = TutorVersion(version)
return self.repository.find_version(version=version)
5 changes: 5 additions & 0 deletions tvm/version_manager/application/tutor_version_installer.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
"""Tutor version installer application."""
from tvm.version_manager.domain.tutor_version import TutorVersion
from tvm.version_manager.domain.version_manager_repository import VersionManagerRepository


class TutorVersionInstaller:
"""Tutor version installer for version manager."""

def __init__(self, repository: VersionManagerRepository) -> None:
"""init."""
self.repository = repository

def __call__(self, version: str) -> None:
"""call."""
version = TutorVersion(version)
self.repository.install_version(version=version)
5 changes: 5 additions & 0 deletions tvm/version_manager/application/tutor_version_uninstaller.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
"""Tutor version uninstaller application."""
from tvm.version_manager.domain.tutor_version import TutorVersion
from tvm.version_manager.domain.version_manager_repository import VersionManagerRepository


class TutorVersionUninstaller:
"""Tutor version uninstaller for version manager."""

def __init__(self, repository: VersionManagerRepository) -> None:
"""init."""
self.repository = repository

def __call__(self, version: str) -> None:
"""call."""
version = TutorVersion(version)
self.repository.uninstall_version(version)
10 changes: 7 additions & 3 deletions tvm/version_manager/application/tutor_vesion_lister.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
"""Tutor version application."""
from typing import List

from tvm.version_manager.domain.tutor_version import TutorVersion
from tvm.version_manager.domain.version_manager_repository import (
VersionManagerRepository,
)
from tvm.version_manager.domain.version_manager_repository import VersionManagerRepository


class TutorVersionLister:
"""Tutor version lister for version manage."""

def __init__(self, repository: VersionManagerRepository) -> None:
"""init."""
self.repository = repository

def __call__(self, limit: int) -> List[TutorVersion]:
"""call."""
return self.repository.list_versions(limit=limit)
1 change: 1 addition & 0 deletions tvm/version_manager/domain/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Domain init."""
12 changes: 7 additions & 5 deletions tvm/version_manager/domain/tutor_version.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
"""Tutor version domain."""
import re
from tvm.version_manager.domain.tutor_version_format_error import (
TutorVersionFormatError,
)

from tvm.version_manager.domain.tutor_version_format_error import TutorVersionFormatError


class TutorVersion(str):
def __init__(self, value: str, file_url: str = None):
"""Tutor version format."""

def __init__(self, value: str, file_url: str = None): # pylint: disable=super-init-not-called
"""Raise BadParameter if the value is not a tutor version."""
self._value = value
self._file_url = file_url

result = re.match(r'^v([0-9]+)\.([0-9]+)\.([0-9]+)$', value)
result = re.match(r"^v([0-9]+)\.([0-9]+)\.([0-9]+)$", value)
if not result:
raise TutorVersionFormatError("format must be 'vX.Y.Z'")
5 changes: 4 additions & 1 deletion tvm/version_manager/domain/tutor_version_format_error.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
"""Tutor version format error message."""


class TutorVersionFormatError(Exception):
pass
"""Tutor version format error exception."""
5 changes: 4 additions & 1 deletion tvm/version_manager/domain/tutor_version_is_not_installed.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
"""Tutor vesion is not installed."""


class TutorVersionIsNotInstalled(Exception):
pass
"""Tutor vesion is not installed domain."""
23 changes: 13 additions & 10 deletions tvm/version_manager/domain/version_manager_repository.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
"""Version manager repository methods."""
from abc import ABC, abstractmethod
from typing import List, Optional

from tvm.version_manager.domain.tutor_version import TutorVersion


class VersionManagerRepository(ABC):
"""Administrate version manager repository methods."""

@abstractmethod
def list_versions(self, limit: int) -> List[TutorVersion]:
pass
"""List versions of the version manager."""

@staticmethod
@abstractmethod
def local_versions(tvm_path: str) -> List[TutorVersion]:
pass
"""List local versions of the version manager."""

@staticmethod
@abstractmethod
def current_version(tvm_path: str) -> List[TutorVersion]:
pass
"""Present the current version of the version manager."""

@abstractmethod
def install_version(self, version: TutorVersion) -> None:
pass
"""Install the version manager for tutor version."""

@abstractmethod
def find_version(self, version: TutorVersion) -> Optional[TutorVersion]:
pass
"""Find the tutor version manager."""

@abstractmethod
def uninstall_version(self, version: TutorVersion) -> None:
pass
"""Uninstall the version manager for tutor version selected."""

@abstractmethod
def use_version(self, version: TutorVersion) -> None:
pass
"""Use selected version when is installed."""

@staticmethod
@abstractmethod
def version_is_installed(version: str) -> None:
pass
"""Version is installed method."""

@abstractmethod
def install_plugin(self, options: List) -> None:
pass
"""Install tutor plugin."""

@abstractmethod
def uninstall_plugin(self, options: List) -> None:
pass
"""Uninstall tutor plugin."""
1 change: 1 addition & 0 deletions tvm/version_manager/infrastructure/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Infrastructure init."""
Loading

0 comments on commit e74f39a

Please sign in to comment.