File tree Expand file tree Collapse file tree 9 files changed +16
-65
lines changed
src/functions_framework/aio Expand file tree Collapse file tree 9 files changed +16
-65
lines changed Original file line number Diff line number Diff line change 14
14
permissions : read-all
15
15
16
16
jobs :
17
- python37 :
18
- uses : GoogleCloudPlatform/functions-framework-conformance/.github/workflows/buildpack-integration-test.yml@main
19
- with :
20
- http-builder-source : ' tests/conformance'
21
- http-builder-target : ' write_http_declarative'
22
- cloudevent-builder-source : ' tests/conformance'
23
- cloudevent-builder-target : ' write_cloud_event_declarative'
24
- prerun : ' tests/conformance/prerun.sh ${{ github.sha }}'
25
- builder-runtime : ' python37'
26
- builder-runtime-version : ' 3.7'
27
- start-delay : 5
28
17
python38 :
29
18
uses : GoogleCloudPlatform/functions-framework-conformance/.github/workflows/buildpack-integration-test.yml@main
30
19
with :
Original file line number Diff line number Diff line change 29
29
proxy.golang.org:443
30
30
pypi.org:443
31
31
storage.googleapis.com:443
32
+ release-assets.githubusercontent.com:443
32
33
33
34
- name : Checkout code
34
35
uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
38
39
with :
39
40
python-version : ${{ matrix.python }}
40
41
41
- - name : Install the framework with async extras
42
- run : python -m pip install -e .[async]
42
+ - name : Install the framework
43
+ run : python -m pip install -e .
43
44
44
45
- name : Setup Go
45
46
uses : actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
Original file line number Diff line number Diff line change 34
34
proxy.golang.org:443
35
35
pypi.org:443
36
36
storage.googleapis.com:443
37
+ release-assets.githubusercontent.com:443
37
38
38
39
- name : Checkout code
39
40
uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
Original file line number Diff line number Diff line change 54
54
production.cloudflare.docker.com:443
55
55
pypi.org:443
56
56
registry-1.docker.io:443
57
+ release-assets.githubusercontent.com:443
57
58
58
59
- name : Checkout
59
60
uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
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