2525# The GitHub repository of the Azure Functions Host
2626WEBHOST_GITHUB_API = "https://api.github.com/repos/Azure/azure-functions-host"
2727WEBHOST_TAG_PREFIX = "v4."
28+ WEBHOST_GIT_REPO = "https://github.com/Azure/azure-functions-host/archive"
2829
2930# Extensions necessary for non-core bindings.
3031AZURE_EXTENSIONS = """\
5657</Project>
5758"""
5859
59-
6060NUGET_CONFIG = """\
6161 <?xml version="1.0" encoding="UTF-8"?>
6262<configuration>
7575</configuration>
7676"""
7777
78-
7978CLASSIFIERS = [
8079 "Development Status :: 5 - Production/Stable" ,
8180 'Programming Language :: Python' ,
9190 "Intended Audience :: Developers" ,
9291]
9392
94-
9593PACKAGES = [
9694 "azure_functions_worker" ,
9795 "azure_functions_worker.protos" ,
103101 "azure_functions_worker._thirdparty"
104102]
105103
106-
107104INSTALL_REQUIRES = [
108105 "grpcio~=1.43.0" ,
109106 "grpcio-tools~=1.43.0" ,
110107 "protobuf~=3.19.3" ,
111108 "azure-functions==1.9.0"
112109]
113110
114-
115111EXTRA_REQUIRES = {
116112 "dev" : [
117113 "azure-eventhub~=5.7.0" , # Used for EventHub E2E tests
135131
136132class BuildGRPC :
137133 """Generate gRPC bindings."""
134+
138135 def _gen_grpc (self ):
139136 root = pathlib .Path (os .path .abspath (os .path .dirname (__file__ )))
140137
@@ -275,16 +272,20 @@ def run(self):
275272class Webhost (distutils .cmd .Command ):
276273 description = 'Download and setup Azure Functions Web Host.'
277274 user_options = [
278- ('webhost-version' , None ,
279- 'A Functions Host version to be downloaded (e.g. 3.0.15278).' ),
280- ('webhost-dir' , None ,
281- 'A path to the directory where Azure Web Host will be installed.' ),
275+ ('webhost-version=' , None ,
276+ 'A Functions Host version to be downloaded (e.g. 3.0.15278).' ),
277+ ('webhost-dir=' , None ,
278+ 'A path to the directory where Azure Web Host will be installed.' ),
279+ ('branch-name=' , None ,
280+ 'A branch from where azure-functions-host will be installed '
281+ '(e.g. branch-name=dev, branch-name= abc/branchname)' )
282282 ]
283283
284284 def __init__ (self , dist : Distribution ):
285285 super ().__init__ (dist )
286286 self .webhost_dir = None
287287 self .webhost_version = None
288+ self .branch_name = None
288289
289290 def initialize_options (self ):
290291 pass
@@ -313,14 +314,20 @@ def _get_webhost_version() -> str:
313314 return latest [0 ]['name' ].replace ('v' , '' )
314315
315316 @staticmethod
316- def _download_webhost_zip (version : str ) -> str :
317+ def _download_webhost_zip (version : str , branch : str ) -> str :
317318 # Return the path of the downloaded host
318319 temporary_file = tempfile .NamedTemporaryFile ()
319- zip_url = (
320- 'https://github.com/Azure/azure-functions-host/archive/'
321- f'v{ version } .zip'
322- )
323- print (f'Downloading Functions Host ({ version } ) from { zip_url } ' )
320+
321+ if branch is not None :
322+ zip_url = (
323+ f'{ WEBHOST_GIT_REPO } /refs/heads/{ branch } .zip'
324+ )
325+ else :
326+ zip_url = (
327+ f'{ WEBHOST_GIT_REPO } /v{ version } .zip'
328+ )
329+
330+ print (f'Downloading Functions Host from { zip_url } ' )
324331
325332 with temporary_file as zipf :
326333 zipf .close ()
@@ -410,9 +417,11 @@ def _compile_webhost(webhost_dir: pathlib.Path):
410417
411418 def run (self ):
412419 # Prepare webhost
413- zip_path = self ._download_webhost_zip (self .webhost_version )
420+ zip_path = self ._download_webhost_zip (self .webhost_version ,
421+ self .branch_name )
414422 self ._create_webhost_folder (self .webhost_dir )
415- self ._extract_webhost_zip (version = self .webhost_version ,
423+ version = self .branch_name or self .webhost_version
424+ self ._extract_webhost_zip (version = version .replace ('/' , '-' ),
416425 src_zip = zip_path ,
417426 dest = self .webhost_dir )
418427 self ._chmod_protobuf_generation_script (self .webhost_dir )
@@ -439,18 +448,23 @@ def run(self) -> None:
439448 for dir_to_delete in self .dir_list_to_delete :
440449 dir_delete = pathlib .Path (dir_to_delete )
441450 if dir_delete .exists ():
442- dir_util .remove_tree (str (dir_delete ))
451+ try :
452+ print (f"Deleting directory: { dir_to_delete } " )
453+ shutil .rmtree (dir_delete )
454+ except OSError as ex :
455+ print (f"Error deleting directory: { dir_to_delete } . "
456+ f"Exception: { ex } " )
443457
444458
445459COMMAND_CLASS = {
446460 'develop' : Development ,
447461 'build' : BuildProtos ,
448462 'webhost' : Webhost ,
463+ 'webhost --branch-name={branch-name}' : Webhost ,
449464 'extension' : Extension ,
450465 'clean' : Clean
451466}
452467
453-
454468setup (
455469 name = "azure-functions-worker" ,
456470 version = VERSION ,
0 commit comments