From 37c174faecc19f344bade69ad062fe4479628394 Mon Sep 17 00:00:00 2001 From: Ankit Kumar Date: Fri, 18 Jan 2019 14:27:49 -0800 Subject: [PATCH] fix python version dependency on bundle script --- src/Azure.Functions.Cli/Common/Constants.cs | 2 +- .../StaticResources/python_bundle_script.py.template | 10 ++++++---- .../StaticResources/python_docker_build.sh.template | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Azure.Functions.Cli/Common/Constants.cs b/src/Azure.Functions.Cli/Common/Constants.cs index b570a20b2..16fa6aa94 100644 --- a/src/Azure.Functions.Cli/Common/Constants.cs +++ b/src/Azure.Functions.Cli/Common/Constants.cs @@ -58,7 +58,7 @@ public static class ArmConstants public static class DockerImages { - public const string LinuxPythonImageAmd64 = "mcr.microsoft.com/azure-functions/python:2.0"; + public const string LinuxPythonImageAmd64 = "mcr.microsoft.com/azure-functions/python:2.0.12275"; } public static class StaticResourcesNames diff --git a/src/Azure.Functions.Cli/StaticResources/python_bundle_script.py.template b/src/Azure.Functions.Cli/StaticResources/python_bundle_script.py.template index 9a29e7bcc..6c42bb908 100644 --- a/src/Azure.Functions.Cli/StaticResources/python_bundle_script.py.template +++ b/src/Azure.Functions.Cli/StaticResources/python_bundle_script.py.template @@ -1,7 +1,9 @@ -from PyInstaller.__main__ import run import os import sys +from PyInstaller.__main__ import run +from distutils.sysconfig import get_python_lib + # Gets the list of all the possible modules from a directory def get_possible_modules(location, parent = ''): @@ -39,10 +41,10 @@ def is_python_file(a_file): return a_file.endswith('.so') or a_file.endswith('.py') or a_file.endswith('.pyd') or a_file.endswith('.pyo') or a_file.endswith('.pyc') def __main__(): - if len(sys.argv) < 3: - print("Need more arguments: Usage: python_build_template.py [starter_script] [python_packages_path]") + if len(sys.argv) < 2: + print("Need more arguments: Usage: python_build_template.py [starter_script]") return - packages_location = sys.argv[2] + packages_location = get_python_lib() all_modules = get_possible_modules(packages_location) entry_file = sys.argv[1] # Creates a list of hidden imports arguments for pyinstaller in the format - "--hidden-import=" diff --git a/src/Azure.Functions.Cli/StaticResources/python_docker_build.sh.template b/src/Azure.Functions.Cli/StaticResources/python_docker_build.sh.template index 3f3fd5423..bc0d9dd0e 100644 --- a/src/Azure.Functions.Cli/StaticResources/python_docker_build.sh.template +++ b/src/Azure.Functions.Cli/StaticResources/python_docker_build.sh.template @@ -12,12 +12,12 @@ python -m venv --copies worker_venv worker_venv/bin/pip install -r requirements.txt # Bundle using pyinstaller -pip install pyinstaller==3.4 +worker_venv/bin/pip install pyinstaller==3.4 pyinstaller_success=false # If pyinstaller succeeds, we deactivate and remove the venv -if python /python_bundle_script.py /azure-functions-host/workers/python/worker.py ./worker_venv/lib/python3.6/site-packages; then +if worker_venv/bin/python /python_bundle_script.py /azure-functions-host/workers/python/worker.py; then pyinstaller_success=true else if [ -d ./worker-bundle ]; then