Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
m-alisafaee committed Feb 18, 2022
1 parent aec8695 commit 49aa01f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
23 changes: 8 additions & 15 deletions renku/core/management/template/template.py
Expand Up @@ -21,8 +21,7 @@
import re
import shutil
import tempfile
from enum import Enum
from functools import total_ordering
from enum import Enum, IntEnum, auto
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple

Expand Down Expand Up @@ -56,13 +55,12 @@
class TemplateAction(Enum):
"""Types of template rendering."""

INITIALIZE = 1
SET = 2
UPDATE = 3
INITIALIZE = auto()
SET = auto()
UPDATE = auto()


@total_ordering
class FileAction(Enum):
class FileAction(IntEnum):
"""Types of operation when copying a template to a project."""

APPEND = 1
Expand All @@ -74,11 +72,6 @@ class FileAction(Enum):
OVERWRITE = 7
RECREATE = 8

def __lt__(self, other):
if self.__class__ is other.__class__:
return self.value < other.value
return NotImplemented


def fetch_templates_source(source: Optional[str], reference: Optional[str]) -> TemplatesSource:
"""Fetch a template."""
Expand Down Expand Up @@ -347,7 +340,7 @@ def read_valid_value(var: TemplateParameter, default_value=None):
raise errors.TemplateUpdateError(f"Can't update template, it now requires variable(s): {missing_values_str}")

# NOTE: Ignore internal variables, i.e. __\w__
internal_keys = re.compile(r"__\w+__$")
internal_keys = re.compile(r"^__\w+__$")
metadata_variables = {v for v in template_metadata.metadata if not internal_keys.match(v)} | set(
input_parameters.keys()
)
Expand Down Expand Up @@ -392,7 +385,7 @@ def get_all_versions(self, id) -> List[str]:
return [self.version] if template_exists else []

def get_latest_version(self, id: str, reference: Optional[str], version: Optional[str]) -> Optional[str]:
"""Return True if a newer version of template available."""
"""Return latest version number of a template."""
if version is None:
return

Expand Down Expand Up @@ -462,7 +455,7 @@ def get_all_versions(self, id) -> List[str]:
return [str(v) for v in sorted(versions)]

def get_latest_version(self, id: str, reference: Optional[str], version: Optional[str]) -> Optional[str]:
"""Return True if a newer version of template available."""
"""Return latest version number of a template."""
if version is None:
return

Expand Down
4 changes: 2 additions & 2 deletions renku/core/models/template.py
Expand Up @@ -227,7 +227,7 @@ def get_all_versions(self) -> List[str]:
def validate(self, skip_files):
"""Validate a template."""
for attribute in self.REQUIRED_ATTRIBUTES:
if not getattr(self, attribute):
if not getattr(self, attribute, None):
raise errors.InvalidTemplateError(f"Template '{self.id}' does not have a '{attribute}' attribute")

for parameter in self.parameters:
Expand Down Expand Up @@ -320,7 +320,7 @@ def __init__(
self.name: str = name
self.description: str = description or ""
self.type: Optional[str] = type
self.possible_values: List[str] = possible_values or []
self.possible_values: List[Union[int, float, str, bool]] = possible_values or []
self.default = default

@classmethod
Expand Down

0 comments on commit 49aa01f

Please sign in to comment.