File tree Expand file tree Collapse file tree 6 files changed +13
-54
lines changed
src/functions_framework/aio Expand file tree Collapse file tree 6 files changed +13
-54
lines changed Original file line number Diff line number Diff line change 39
39
with :
40
40
python-version : ${{ matrix.python }}
41
41
42
- - name : Install the framework with async extras
43
- run : python -m pip install -e .[async]
42
+ - name : Install the framework
43
+ run : python -m pip install -e .
44
44
45
45
- name : Setup Go
46
46
uses : actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
Original file line number Diff line number Diff line change @@ -30,18 +30,14 @@ dependencies = [
30
30
" cloudevents>=1.2.0,<=1.11.0" , # Must support python 3.7
31
31
" Werkzeug>=0.14,<4.0.0" ,
32
32
" httpx>=0.24.1" ,
33
+ " starlette>=0.37.0,<1.0.0; python_version>='3.8'" ,
34
+ " uvicorn>=0.18.0,<1.0.0; python_version>='3.8'" ,
35
+ " uvicorn-worker>=0.2.0,<1.0.0; python_version>='3.8'" ,
33
36
]
34
37
35
38
[project .urls ]
36
39
Homepage = " https://github.com/googlecloudplatform/functions-framework-python"
37
40
38
- [project .optional-dependencies ]
39
- async = [
40
- " starlette>=0.37.0,<1.0.0; python_version>='3.8'" ,
41
- " uvicorn>=0.18.0,<1.0.0; python_version>='3.8'" ,
42
- " uvicorn-worker>=0.2.0,<1.0.0; python_version>='3.8'"
43
- ]
44
-
45
41
[project .scripts ]
46
42
ff = " functions_framework._cli:_cli"
47
43
functions-framework = " functions_framework._cli:_cli"
Original file line number Diff line number Diff line change 25
25
26
26
from cloudevents .http import from_http
27
27
from cloudevents .http .event import CloudEvent
28
+ from starlette .applications import Starlette
29
+ from starlette .exceptions import HTTPException
30
+ from starlette .middleware import Middleware
31
+ from starlette .requests import Request
32
+ from starlette .responses import JSONResponse , Response
33
+ from starlette .routing import Route
28
34
29
35
from functions_framework import (
30
36
_enable_execution_id_logging ,
36
42
MissingSourceException ,
37
43
)
38
44
39
- try :
40
- from starlette .applications import Starlette
41
- from starlette .exceptions import HTTPException
42
- from starlette .middleware import Middleware
43
- from starlette .requests import Request
44
- from starlette .responses import JSONResponse , Response
45
- from starlette .routing import Route
46
- except ImportError :
47
- raise FunctionsFrameworkException (
48
- "Starlette is not installed. Install the framework with the 'async' extra: "
49
- "pip install functions-framework[async]"
50
- )
51
-
52
45
HTTPResponse = Union [
53
46
Response , # Functions can return a full Starlette Response object
54
47
str , # Str returns are wrapped in Response(result)
Original file line number Diff line number Diff line change 35
35
TEST_FUNCTIONS_DIR = pathlib .Path (__file__ ).resolve ().parent / "test_functions"
36
36
37
37
38
- def test_import_error_without_starlette (monkeypatch ):
39
- import builtins
40
-
41
- original_import = builtins .__import__
42
-
43
- def mock_import (name , * args , ** kwargs ):
44
- if name .startswith ("starlette" ):
45
- raise ImportError (f"No module named '{ name } '" )
46
- return original_import (name , * args , ** kwargs )
47
-
48
- monkeypatch .setattr (builtins , "__import__" , mock_import )
49
-
50
- # Remove the module from sys.modules to force re-import
51
- if "functions_framework.aio" in sys .modules :
52
- del sys .modules ["functions_framework.aio" ]
53
-
54
- with pytest .raises (exceptions .FunctionsFrameworkException ) as excinfo :
55
- import functions_framework .aio
56
-
57
- assert "Starlette is not installed" in str (excinfo .value )
58
- assert "pip install functions-framework[async]" in str (excinfo .value )
59
-
60
-
61
38
def test_invalid_function_definition_missing_function_file ():
62
39
source = TEST_FUNCTIONS_DIR / "missing_function_file" / "main.py"
63
40
target = "function"
Original file line number Diff line number Diff line change 18
18
import pretend
19
19
import pytest
20
20
21
- import functions_framework . _http
21
+ from starlette . applications import Starlette
22
22
23
- try :
24
- from starlette .applications import Starlette
25
- except ImportError :
26
- pass
23
+ import functions_framework ._http
27
24
28
25
29
26
def test_httpserver_detects_asgi_app ():
Original file line number Diff line number Diff line change 29
29
pytest-cov
30
30
pytest-integration
31
31
pretend
32
- extras =
33
- async
34
32
setenv =
35
33
PYTESTARGS = --cov =functions_framework --cov-branch --cov-report term-missing --cov-fail-under =100
36
34
# Python 3.7: Use .coveragerc-py37 to exclude aio module from coverage since it requires Python 3.8+ (Starlette dependency)
48
46
isort
49
47
mypy
50
48
build
51
- extras =
52
- async
53
49
commands =
54
50
black --check src tests conftest.py --exclude tests/test_functions/background_load_error/main.py
55
51
isort -c src tests conftest.py
You can’t perform that action at this time.
0 commit comments