-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Append /home/site/wwwroot to sys.path (#726)
* Add sys.path reload in Linux Consumption and add /home/site/wwwroot in Linux Dedicated/Premium
- Loading branch information
Showing
17 changed files
with
239 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,19 @@ | ||
import sys | ||
import os | ||
from azure_functions_worker import main | ||
|
||
|
||
# Azure environment variables | ||
AZURE_WEBJOBS_SCRIPT_ROOT = "AzureWebJobsScriptRoot" | ||
|
||
|
||
def add_script_root_to_sys_path(): | ||
'''Append function project root to module finding sys.path''' | ||
functions_script_root = os.getenv(AZURE_WEBJOBS_SCRIPT_ROOT) | ||
if functions_script_root is not None: | ||
sys.path.append(functions_script_root) | ||
|
||
|
||
if __name__ == '__main__': | ||
add_script_root_to_sys_path() | ||
main.main() |
16 changes: 16 additions & 0 deletions
16
tests/unittests/load_functions/absolute_thirdparty/function.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"scriptFile": "main.py", | ||
"entryPoint": "main", | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req" | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$return" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
# Import a module from thirdparty package azure-eventhub | ||
import azure.eventhub as eh | ||
|
||
|
||
def main(req) -> str: | ||
return f'eh = {eh.__name__}' |
16 changes: 0 additions & 16 deletions
16
tests/unittests/load_functions/brokenimplicit/function.json
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
tests/unittests/load_functions/implicit_import/function.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"scriptFile": "main.py", | ||
"entryPoint": "implicitinmport", | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req" | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$return" | ||
} | ||
] | ||
} |
6 changes: 4 additions & 2 deletions
6
...sts/load_functions/brokenimplicit/main.py → ...ts/load_functions/implicit_import/main.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
# Import simple module with implicit directory import statement should fail | ||
|
||
# Import simple module with implicit statement should now be acceptable | ||
# since sys.path is now appended with function script root | ||
from simple.main import main as s_main | ||
|
||
|
||
def brokenimplicit(req) -> str: | ||
def implicitinmport(req) -> str: | ||
return f's_main = {s_main(req)}' |
16 changes: 16 additions & 0 deletions
16
tests/unittests/load_functions/module_not_found/function.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"scriptFile": "main.py", | ||
"entryPoint": "modulenotfound", | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req" | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$return" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
# Import simple module with implicit statement should now be acceptable | ||
import notfound | ||
|
||
|
||
def modulenotfound(req) -> str: | ||
return f'notfound = {notfound.__name__}' |
16 changes: 16 additions & 0 deletions
16
tests/unittests/load_functions/name_collision/function.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"scriptFile": "main.py", | ||
"entryPoint": "main", | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req" | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$return" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
# Both customer code and third-party package has the same name pytest. | ||
# Worker should pick the pytest from the third-party package | ||
import pytest as pt | ||
|
||
|
||
def main(req) -> str: | ||
return f'pt.__version__ = {pt.__version__}' |
16 changes: 16 additions & 0 deletions
16
tests/unittests/load_functions/name_collision_app_import/function.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"scriptFile": "main.py", | ||
"entryPoint": "main", | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req" | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$return" | ||
} | ||
] | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/unittests/load_functions/name_collision_app_import/main.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
# Both customer code and third-party package has the same name pytest. | ||
# When using absolute import, should pick customer's package. | ||
import __app__.pytest as pt | ||
|
||
|
||
def main(req) -> str: | ||
return f'pt.__version__ = {pt.__version__}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
|
||
'''This module pytest is provided inside customer's code, | ||
used for checking module name collision''' | ||
__version__ = 'from.customer.code' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters