Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions azure_functions_worker/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
import pathlib
import sys
import typing
from os import PathLike, fspath

from .constants import MODULE_NOT_FOUND_TS_URL
from .utils.wrappers import attach_message_to_exception
from os import PathLike, fspath


_AZURE_NAMESPACE = '__app__'
_DEFAULT_SCRIPT_FILENAME = '__init__.py'
_DEFAULT_ENTRY_POINT = 'main'

_submodule_dirs = []

Expand Down Expand Up @@ -50,9 +51,10 @@ def uninstall() -> None:
def load_function(name: str, directory: str, script_file: str,
entry_point: typing.Optional[str]):
dir_path = pathlib.Path(directory)
script_path = pathlib.Path(script_file)
script_path = pathlib.Path(script_file) if script_file else pathlib.Path(
_DEFAULT_SCRIPT_FILENAME)
if not entry_point:
entry_point = 'main'
entry_point = _DEFAULT_ENTRY_POINT

register_function_dir(dir_path.parent)

Expand Down
14 changes: 14 additions & 0 deletions tests/unittests/load_functions/no_script_file/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"bindings": [
{
"type": "httpTrigger",
"direction": "in",
"name": "req"
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}
6 changes: 6 additions & 0 deletions tests/unittests/load_functions/no_script_file/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.


def main(req) -> str:
return __name__
5 changes: 5 additions & 0 deletions tests/unittests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ def test_loader_custom_entrypoint(self):
self.assertEqual(r.status_code, 200)
self.assertEqual(r.text, '__app__.entrypoint.main')

def test_loader_no_script_file(self):
r = self.webhost.request('GET', 'no_script_file')
self.assertEqual(r.status_code, 200)
self.assertEqual(r.text, '__app__.no_script_file.main')

def test_loader_subdir(self):
r = self.webhost.request('GET', 'subdir')
self.assertEqual(r.status_code, 200)
Expand Down