You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by ma...@apache.org on 2022/08/10 15:17:07 UTC
[pulsar] 10/12: [fix][function] Fix python instance not process zip file correctly (#16697)
This is an automated email from the ASF dual-hosted git repository.
mattisonchao pushed a commit to branch branch-2.9
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 4f03d0056b4f4ff0e4c0e8048094117db1867fb0
Author: jiangpengcheng <sc...@gmail.com>
AuthorDate: Wed Aug 3 13:58:48 2022 +0800
[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 627013489ab..0672142e334 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),