From 9dfff7375826414b5ef7836c6e947c151f125757 Mon Sep 17 00:00:00 2001 From: Khor Shu Heng <32997938+khorshuheng@users.noreply.github.com> Date: Wed, 24 Jan 2024 14:53:42 +0800 Subject: [PATCH] fix: move git initialization to function body (#521) # Description Import git module will fail when the execution environment does not contain git executable. As Merlin SDK does not strictly rely on git, we should move the import to the function body where it is needed instead. # Modifications # Tests # Checklist - [ ] Added PR label - [ ] Added unit test, integration, and/or e2e tests - [ ] Tested locally - [ ] Updated documentation - [ ] Update Swagger spec if the PR introduce API changes - [ ] Regenerated Golang and Python client if the PR introduces API changes # Release Notes ```release-note Fix a bug in which pyfunc related functions will fail when the execution environment does not have git executable. ``` --- python/sdk/merlin/pyfunc.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/sdk/merlin/pyfunc.py b/python/sdk/merlin/pyfunc.py index 24e8467f3..823616bb1 100644 --- a/python/sdk/merlin/pyfunc.py +++ b/python/sdk/merlin/pyfunc.py @@ -10,7 +10,6 @@ import pandas from caraml.upi.v1 import upi_pb2 from docker import APIClient -from git import Repo from merlin.docker.docker import copy_pyfunc_dockerfile, wait_build_complete from merlin.protocol import Protocol from merlin.version import VERSION @@ -516,6 +515,10 @@ def run_pyfunc_local_server( def _clone_merlin_repo(context_path: str): + # Can't be imported at module level because the initialization will fail when the git executable + # does not exists. + from git import Repo + repo_url = "https://github.com/caraml-dev/merlin.git" repo_path = f"{context_path}/merlin" if not os.path.isdir(repo_path):