Skip to content

Commit

Permalink
ENH: Added python version to metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ganesh-k13 committed Jan 13, 2023
1 parent 17c3fd4 commit fde94d4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion vetiver/meta.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from dataclasses import dataclass, asdict, field
from typing import Mapping

Expand All @@ -10,6 +11,7 @@ class VetiverMeta:
version: "str | None" = None
url: "str | None" = None
required_pkgs: "list | None" = field(default_factory=list)
python_version: "str | None" = None

def to_dict(self) -> Mapping:
data = asdict(self)
Expand All @@ -25,9 +27,10 @@ def from_dict(cls, metadata, pip_name=None) -> "VetiverMeta":
version = metadata.get("version", None)
url = metadata.get("url", None)
required_pkgs = metadata.get("required_pkgs", [])
python_version = metadata.get("python_version", sys.version)

if pip_name:
if not list(filter(lambda x: pip_name in x, required_pkgs)):
required_pkgs = required_pkgs + [f"{pip_name}"]

return cls(user, version, url, required_pkgs)
return cls(user, version, url, required_pkgs, python_version)
1 change: 1 addition & 0 deletions vetiver/pin_read_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def vetiver_pin_write(board, model: VetiverModel, versioned: bool = True):
"vetiver_meta": {
"required_pkgs": model.metadata.required_pkgs,
"prototype": None if not model.prototype else model.prototype().json(),
"python_version": model.metadata.python_version,
},
},
versioned=versioned,
Expand Down
3 changes: 3 additions & 0 deletions vetiver/vetiver_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def from_pin(cls, board, name: str, version: str = None):
if "vetiver_meta" in meta.user:
get_prototype = meta.user.get("vetiver_meta").get("prototype", None)
required_pkgs = meta.user.get("vetiver_meta").get("required_pkgs", None)
python_version = meta.user.get("vetiver_meta").get("python_version", None)
meta.user.pop("vetiver_meta")
else:
# ptype = meta.user.get("ptype", None)
Expand All @@ -113,6 +114,7 @@ def from_pin(cls, board, name: str, version: str = None):
# get_prototype = None

required_pkgs = meta.user.get("required_pkgs")
python_version = meta.user.get("python_version")

return cls(
model=model,
Expand All @@ -123,6 +125,7 @@ def from_pin(cls, board, name: str, version: str = None):
"version": meta.version.version,
"url": meta.local.get("url"), # None all the time, besides Connect,
"required_pkgs": required_pkgs,
"python_version": python_version,
},
prototype_data=json.loads(get_prototype) if get_prototype else None,
versioned=True,
Expand Down

0 comments on commit fde94d4

Please sign in to comment.