Skip to content

Commit

Permalink
run linter, use Version.parse for schema
Browse files Browse the repository at this point in the history
  • Loading branch information
vzotova committed Aug 6, 2024
1 parent 9a4ca14 commit ee9ee47
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
16 changes: 6 additions & 10 deletions porter/fields/base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import json
from base64 import b64decode, b64encode
import re

import click
from marshmallow import fields
from packaging.version import Version, parse

from porter.fields.exceptions import InvalidInputData

Expand Down Expand Up @@ -114,15 +114,11 @@ def _deserialize(self, value, attr, data, **kwargs):
class VersionString(String):

def _serialize(self, value, attr, obj, **kwargs) -> str:
if (type(value) is not list or len(value) == 0 or len(value) > 3):
if type(value) is not Version:
raise InvalidInputData(
f"Unexpected object type, {type(value)}; expected list[3]")

return ".".join(value)
f"Unexpected object type, {type(value)}; expected Version"
)
return str(value)

def _deserialize(self, value, attr, data, **kwargs) -> list:
pattern = r'(\d+\.)?(\d+\.)?(\d+)'
match = re.findall(pattern, value)
if len(match) != 1:
raise InvalidInputData("Minimum version must have x.x.x format")
return match[0]
return parse(value)
2 changes: 1 addition & 1 deletion porter/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
Integer,
NonNegativeInteger,
PositiveInteger,
VersionString,
StringList,
VersionString,
)
from porter.fields.exceptions import InvalidArgumentCombo, InvalidInputData
from porter.fields.retrieve import CapsuleFrag, RetrievalKit
Expand Down

0 comments on commit ee9ee47

Please sign in to comment.