From 44696df64e56be96b13b3793688026183687481e Mon Sep 17 00:00:00 2001 From: jiangpengcheng Date: Wed, 3 Aug 2022 13:58:48 +0800 Subject: [PATCH] [fix][function] Fix python instance not process zip file correctly (#16697) (cherry picked from commit 68e454544d45734129e67ab3032eae3e40ff664c) --- .../instance/src/main/python/python_instance_main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pulsar-functions/instance/src/main/python/python_instance_main.py b/pulsar-functions/instance/src/main/python/python_instance_main.py index 8c5bf8a1d4167..2f0654ada3432 100644 --- a/pulsar-functions/instance/src/main/python/python_instance_main.py +++ b/pulsar-functions/instance/src/main/python/python_instance_main.py @@ -99,7 +99,7 @@ def main(): if os.path.splitext(str(args.py))[1] == '.whl': if args.install_usercode_dependencies: - cmd = "pip install -t %s" % os.path.dirname(str(args.py)) + cmd = "pip install -t %s" % os.path.dirname(os.path.abspath(str(args.py))) if args.dependency_repository: cmd = cmd + " -i %s" % str(args.dependency_repository) if args.extra_dependency_repository: @@ -112,7 +112,7 @@ def main(): else: zpfile = zipfile.ZipFile(str(args.py), 'r') zpfile.extractall(os.path.dirname(str(args.py))) - sys.path.insert(0, os.path.dirname(str(args.py))) + sys.path.insert(0, os.path.dirname(os.path.abspath(str(args.py)))) elif os.path.splitext(str(args.py))[1] == '.zip': # Assumig zip file with format func.zip # extract to folder function @@ -123,21 +123,21 @@ def main(): # run pip install to target folder deps folder zpfile = zipfile.ZipFile(str(args.py), 'r') zpfile.extractall(os.path.dirname(str(args.py))) - basename = os.path.splitext(str(args.py))[0] + basename = os.path.basename(os.path.splitext(str(args.py))[0]) deps_dir = os.path.join(os.path.dirname(str(args.py)), basename, "deps") if os.path.isdir(deps_dir) and os.listdir(deps_dir): # get all wheel files from deps directory wheel_file_list = [os.path.join(deps_dir, f) for f in os.listdir(deps_dir) if os.path.isfile(os.path.join(deps_dir, f)) and os.path.splitext(f)[1] =='.whl'] - cmd = "pip install -t %s --no-index --find-links %s %s" % (os.path.dirname(str(args.py)), deps_dir, " ".join(wheel_file_list)) + cmd = "pip install -t %s --no-index --find-links %s %s" % (os.path.dirname(os.path.abspath(str(args.py))), deps_dir, " ".join(wheel_file_list)) Log.debug("Install python dependencies via cmd: %s" % cmd) retval = os.system(cmd) if retval != 0: print("Could not install user depedencies specified by the zip file") sys.exit(1) # add python user src directory to path - sys.path.insert(0, os.path.join(os.path.dirname(str(args.py)), basename, "src")) + sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(str(args.py))), basename, "src")) log_file = os.path.join(args.logging_directory, util.getFullyQualifiedFunctionName(function_details.tenant, function_details.namespace, function_details.name),