@@ -519,40 +519,61 @@ def popen_webhost(*, stdout, stderr, script_root=FUNCS_PATH, port=None):
519519 testconfig = configparser .ConfigParser ()
520520 testconfig .read (WORKER_CONFIG )
521521
522- dll = os .environ .get ('PYAZURE_WEBHOST_DLL' )
523- if not dll and testconfig and testconfig .has_section ('webhost' ):
524- dll = testconfig ['webhost' ].get ('dll' )
522+ hostexe_args = []
525523
526- if dll :
527- # Paths from environment might contain trailing or leading whitespace.
528- dll = dll .strip ()
524+ # If we want to use core-tools
525+ coretools_exe = os .environ .get ('CORE_TOOLS_EXE_PATH' )
526+ if coretools_exe :
527+ coretools_exe = coretools_exe .strip ()
528+ if pathlib .Path (coretools_exe ).exists ():
529+ hostexe_args = [str (coretools_exe ), 'host' , 'start' ]
530+ if port is not None :
531+ hostexe_args .extend (['--port' , str (port )])
529532
530- if not dll :
531- dll = DEFAULT_WEBHOST_DLL_PATH
533+ # If we need to use Functions host directly
534+ if not hostexe_args :
535+ dll = os .environ .get ('PYAZURE_WEBHOST_DLL' )
536+ if not dll and testconfig and testconfig .has_section ('webhost' ):
537+ dll = testconfig ['webhost' ].get ('dll' )
532538
533- secrets = SECRETS_TEMPLATE
539+ if dll :
540+ # Paths from environment might contain trailing
541+ # or leading whitespace.
542+ dll = dll .strip ()
534543
535- os .makedirs (dll .parent / 'Secrets' , exist_ok = True )
536- with open (dll .parent / 'Secrets' / 'host.json' , 'w' ) as f :
537- f .write (secrets )
544+ if not dll :
545+ dll = DEFAULT_WEBHOST_DLL_PATH
538546
539- if not dll or not pathlib .Path (dll ).exists ():
547+ secrets = SECRETS_TEMPLATE
548+
549+ os .makedirs (dll .parent / 'Secrets' , exist_ok = True )
550+ with open (dll .parent / 'Secrets' / 'host.json' , 'w' ) as f :
551+ f .write (secrets )
552+
553+ if dll and pathlib .Path (dll ).exists ():
554+ hostexe_args = ['dotnet' , str (dll )]
555+
556+ if not hostexe_args :
540557 raise RuntimeError ('\n ' .join ([
541558 f'Unable to locate Azure Functions Host binary.' ,
542559 f'Please do one of the following:' ,
543- f' * run the following command from the root folder of the ' ,
544- f' project:' ,
560+ f' * run the following command from the root folder of' ,
561+ f' the project:' ,
545562 f'' ,
546563 f' $ { sys .executable } setup.py webhost' ,
547564 f'' ,
548- f' * or download or build the Azure Functions Host and then write' ,
549- f' the full path to WebHost.dll into the `PYAZURE_WEBHOST_DLL`' ,
550- f' environment variable. Alternatively, you can create the' ,
551- f' { WORKER_CONFIG .name } file in the root folder of the project' ,
552- f' with the following structure:' ,
565+ f' * or download or build the Azure Functions Host and'
566+ f' then write the full path to WebHost.dll'
567+ f' into the `PYAZURE_WEBHOST_DLL` environment variable.' ,
568+ f' Alternatively, you can create the' ,
569+ f' { WORKER_CONFIG .name } file in the root folder' ,
570+ f' of the project with the following structure:' ,
553571 f'' ,
554- f' [webhost]' ,
555- f' dll = /path/Microsoft.Azure.WebJobs.Script.WebHost.dll' ,
572+ f' [webhost]' ,
573+ f' dll = /path/Microsoft.Azure.WebJobs.Script.WebHost.dll' ,
574+ f' * or download Azure Functions Core Tools binaries and' ,
575+ f' then write the full path to func.exe into the ' ,
576+ f' `CORE_TOOLS_PATH` envrionment variable.'
556577 ]))
557578
558579 worker_path = os .environ .get ('PYAZURE_WORKER_DIR' )
@@ -595,7 +616,7 @@ def popen_webhost(*, stdout, stderr, script_root=FUNCS_PATH, port=None):
595616 extra_env ['ASPNETCORE_URLS' ] = f'http://*:{ port } '
596617
597618 return subprocess .Popen (
598- [ 'dotnet' , str ( dll )] ,
619+ hostexe_args ,
599620 cwd = script_root ,
600621 env = {
601622 ** os .environ ,
0 commit comments