Skip to content

Commit

Permalink
Introduce method for converting model to object
Browse files Browse the repository at this point in the history
  • Loading branch information
fridex committed Oct 1, 2018
1 parent fd56fe0 commit 99d50b0
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions thoth/adviser/python/package_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from thoth.adviser.exceptions import UnsupportedConfiguration
from thoth.adviser.exceptions import PipfileParseError
from thoth.adviser.exceptions import InternalError
from thoth.storages.graph import PythonPackageVersion as PackageVersionModel

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -61,6 +62,18 @@ def __gt__(self, other):

return self.semantic_version > other.semantic_version

@classmethod
def from_model(model: PackageVersionModel, *, develop: bool = False):
"""Convert database model representation to object representation."""
# TODO: add markers to the graph database
# TODO: add hashes to the graph database
return cls(
name=model.package_name,
version=model.package_version,
develop=develop,
index=model.index
)

def is_locked(self):
"""Check if the given package is locked to a specific version."""
return self.version.startswith('==')
Expand Down

0 comments on commit 99d50b0

Please sign in to comment.