Skip to content

Commit

Permalink
[Project] Add helper func to determine if url suffix is yaml/yml (mlr…
Browse files Browse the repository at this point in the history
  • Loading branch information
yaelgen authored Jan 16, 2023
1 parent 7b90bf9 commit f3438a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 12 additions & 5 deletions mlrun/projects/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@
from ..run import code_to_function, get_object, import_function, new_function
from ..runtimes.utils import add_code_metadata
from ..secrets import SecretsStore
from ..utils import is_ipython, is_legacy_artifact, is_relative_path, logger, update_in
from ..utils import (
is_ipython,
is_legacy_artifact,
is_relative_path,
is_yaml_path,
logger,
update_in,
)
from ..utils.clones import clone_git, clone_tgz, clone_zip, get_repo_url
from ..utils.model_monitoring import set_project_model_monitoring_credentials
from ..utils.notifications import CustomNotificationPusher, NotificationTypes
Expand Down Expand Up @@ -248,7 +255,7 @@ def load_project(
from_db = False
if url:
url = str(url) # to support path objects
if url.endswith(".yaml"):
if is_yaml_path(url):
project = _load_project_file(url, name, secrets)
project.spec.context = context
elif url.startswith("git://"):
Expand Down Expand Up @@ -1504,7 +1511,7 @@ def get_artifact(spec):
item_path, _ = self.get_item_absolute_path(item_path)
dataitem = mlrun.get_dataitem(item_path)

if item_path.endswith(".yaml") or item_path.endswith(".yml"):
if is_yaml_path(item_path):
artifact_dict = yaml.load(dataitem.get(), Loader=yaml.FullLoader)
artifact = get_artifact(artifact_dict)
elif item_path.endswith(".json"):
Expand Down Expand Up @@ -2846,7 +2853,7 @@ def _init_function_from_dict(f, project, name=None):
name, image=image, kind=kind or "job", handler=handler, tag=tag
)

elif url.endswith(".yaml") or url.startswith("db://") or url.startswith("hub://"):
elif is_yaml_path(url) or url.startswith("db://") or url.startswith("hub://"):
if tag:
raise ValueError(
"function with db:// or hub:// url or .yaml file, does not support tag value "
Expand Down Expand Up @@ -2935,7 +2942,7 @@ def _init_function_from_dict_legacy(f, project):

if "spec" in f:
func = new_function(name, runtime=f["spec"])
elif url.endswith(".yaml") or url.startswith("db://") or url.startswith("hub://"):
elif is_yaml_path(url) or url.startswith("db://") or url.startswith("hub://"):
func = import_function(url)
if image:
func.spec.image = image
Expand Down
4 changes: 4 additions & 0 deletions mlrun/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ def tag_name_regex_as_string() -> str:
return get_regex_list_as_string(mlrun.utils.regex.tag_name)


def is_yaml_path(url):
return url.endswith(".yaml") or url.endswith(".yml")


# Verifying that a field input is of the expected type. If not the method raises a detailed MLRunInvalidArgumentError
def verify_field_of_type(field_name: str, field_value, expected_type: type):
if not isinstance(field_value, expected_type):
Expand Down

0 comments on commit f3438a3

Please sign in to comment.