Enable Python 3.8 in V3 worker (#603)
* Enable Python 3.8 in V3 worker * Also allow python version 3.8 in worker.py
This commit is contained in:
Родитель
0b68e473dc
Коммит
676a8e578c
|
@ -18,7 +18,7 @@
|
|||
<file src="..\3.7_WINDOWS_X86\**" target="tools\3.7\WINDOWS\X86" />
|
||||
<file src="..\3.7_LINUX_X64\**" target="tools\3.7\LINUX\X64" />
|
||||
<file src="..\3.7_OSX_X64\**" target="tools\3.7\OSX\X64" />
|
||||
<file src="..\python\prod\worker.config.json" target="tools" />
|
||||
<file src="Microsoft.Azure.Functions.V2.PythonWorker.targets" target="build" />
|
||||
<file src="..\python\prodV2\worker.config.json" target="tools" />
|
||||
<file src="Microsoft.Azure.Functions.PythonWorker.targets" target="build" />
|
||||
</files>
|
||||
</package>
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<file src="..\3.8_WINDOWS_X86\**" target="tools\3.8\WINDOWS\X86" />
|
||||
<file src="..\3.8_LINUX_X64\**" target="tools\3.8\LINUX\X64" />
|
||||
<file src="..\3.8_OSX_X64\**" target="tools\3.8\OSX\X64" />
|
||||
<file src="..\python\prod\worker.config.json" target="tools" />
|
||||
<file src="Microsoft.Azure.Functions.V3.PythonWorker.targets" target="build" />
|
||||
<file src="..\python\prodV3\worker.config.json" target="tools" />
|
||||
<file src="Microsoft.Azure.Functions.PythonWorker.targets" target="build" />
|
||||
</files>
|
||||
</package>
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
<Project>
|
||||
<Target Name="Initialize" AfterTargets="Publish;Build">
|
||||
<CreateItem Include="$(MSBuildThisFileDirectory)\..\">
|
||||
<Output ItemName="MSBuildThisFileDirectoryParentDirectory" TaskParameter="Include"/>
|
||||
</CreateItem>
|
||||
|
||||
<CreateProperty Value="%(MSBuildThisFileDirectoryParentDirectory.Fullpath)">
|
||||
<Output PropertyName="NugetRoot" TaskParameter="Value"/>
|
||||
</CreateProperty>
|
||||
|
||||
<ItemGroup>
|
||||
<SourceFiles Include="$(NugetRoot)tools\**\*.*"/>
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
<Target Name="CopyOnPublish" DependsOnTargets="Initialize" AfterTargets="Publish">
|
||||
<Copy SourceFiles="@(SourceFiles)"
|
||||
DestinationFiles="@(SourceFiles->'$(PublishDir)\workers\python\%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||
</Target>
|
||||
|
||||
<Target Name="CopyOnBuild" DependsOnTargets="Initialize" AfterTargets="Build">
|
||||
<Copy SourceFiles="@(SourceFiles)"
|
||||
DestinationFiles="@(SourceFiles->'$(OutDir)\workers\python\%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||
</Target>
|
||||
</Project>
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"description":{
|
||||
"language":"python",
|
||||
"defaultRuntimeVersion":"3.6",
|
||||
"supportedOperatingSystems":["LINUX", "OSX", "WINDOWS"],
|
||||
"supportedRuntimeVersions":["3.6", "3.7", "3.8"],
|
||||
"supportedArchitectures":["X64", "X86"],
|
||||
"extensions":[".py"],
|
||||
"defaultExecutablePath":"python",
|
||||
"defaultWorkerPath":"%FUNCTIONS_WORKER_RUNTIME_VERSION%/{os}/{architecture}/worker.py"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
# User packages
|
||||
PKGS_PATH = "site/wwwroot/.python_packages"
|
||||
VENV_PKGS_PATH = "site/wwwroot/worker_venv"
|
||||
|
||||
PKGS_36 = "lib/python3.6/site-packages"
|
||||
PKGS = "lib/site-packages"
|
||||
|
||||
# Azure environment variables
|
||||
AZURE_WEBSITE_INSTANCE_ID = "WEBSITE_INSTANCE_ID"
|
||||
AZURE_CONTAINER_NAME = "CONTAINER_NAME"
|
||||
|
||||
|
||||
def is_azure_environment():
|
||||
return (AZURE_CONTAINER_NAME in os.environ
|
||||
or AZURE_WEBSITE_INSTANCE_ID in os.environ)
|
||||
|
||||
|
||||
def determine_user_pkg_paths():
|
||||
minor_version = sys.version_info[1]
|
||||
|
||||
home = Path.home()
|
||||
pkgs_path = os.path.join(home, PKGS_PATH)
|
||||
venv_pkgs_path = os.path.join(home, VENV_PKGS_PATH)
|
||||
|
||||
user_pkg_paths = []
|
||||
if minor_version == 6:
|
||||
user_pkg_paths.append(os.path.join(venv_pkgs_path, PKGS_36))
|
||||
user_pkg_paths.append(os.path.join(pkgs_path, PKGS_36))
|
||||
user_pkg_paths.append(os.path.join(pkgs_path, PKGS))
|
||||
elif minor_version in (7, 8):
|
||||
user_pkg_paths.append(os.path.join(pkgs_path, PKGS))
|
||||
else:
|
||||
raise RuntimeError(f'Unsupported Python version: 3.{minor_version}')
|
||||
|
||||
return user_pkg_paths
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# worker.py lives in the same directory as azure_functions_worker
|
||||
func_worker_dir = str(Path(__file__).absolute().parent)
|
||||
env = os.environ
|
||||
|
||||
if is_azure_environment():
|
||||
user_pkg_paths = determine_user_pkg_paths()
|
||||
|
||||
joined_pkg_paths = os.pathsep.join(user_pkg_paths)
|
||||
env['PYTHONPATH'] = f'{joined_pkg_paths}:{func_worker_dir}'
|
||||
os.execve(sys.executable,
|
||||
[sys.executable, '-m', 'azure_functions_worker']
|
||||
+ sys.argv[1:],
|
||||
env)
|
||||
else:
|
||||
sys.path.insert(1, func_worker_dir)
|
||||
from azure_functions_worker import main
|
||||
|
||||
main.main()
|
Загрузка…
Ссылка в новой задаче