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 3939 with :
4040 python-version : ${{ matrix.python }}
4141
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 .
4444
4545 - name : Setup Go
4646 uses : actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
Original file line number Diff line number Diff line change @@ -30,18 +30,14 @@ dependencies = [
3030 " cloudevents>=1.2.0,<=1.11.0" , # Must support python 3.7
3131 " Werkzeug>=0.14,<4.0.0" ,
3232 " 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'" ,
3336]
3437
3538[project .urls ]
3639Homepage = " https://github.com/googlecloudplatform/functions-framework-python"
3740
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-
4541[project .scripts ]
4642ff = " functions_framework._cli:_cli"
4743functions-framework = " functions_framework._cli:_cli"
Original file line number Diff line number Diff line change 2525
2626from cloudevents .http import from_http
2727from 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
2834
2935from functions_framework import (
3036 _enable_execution_id_logging ,
3642 MissingSourceException ,
3743)
3844
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-
5245HTTPResponse = Union [
5346 Response , # Functions can return a full Starlette Response object
5447 str , # Str returns are wrapped in Response(result)
Original file line number Diff line number Diff line change 3535TEST_FUNCTIONS_DIR = pathlib .Path (__file__ ).resolve ().parent / "test_functions"
3636
3737
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-
6138def test_invalid_function_definition_missing_function_file ():
6239 source = TEST_FUNCTIONS_DIR / "missing_function_file" / "main.py"
6340 target = "function"
Original file line number Diff line number Diff line change 1818import pretend
1919import pytest
2020
21- import functions_framework . _http
21+ from starlette . applications import Starlette
2222
23- try :
24- from starlette .applications import Starlette
25- except ImportError :
26- pass
23+ import functions_framework ._http
2724
2825
2926def test_httpserver_detects_asgi_app ():
Original file line number Diff line number Diff line change 2929 pytest-cov
3030 pytest-integration
3131 pretend
32- extras =
33- async
3432setenv =
3533 PYTESTARGS = --cov =functions_framework --cov-branch --cov-report term-missing --cov-fail-under =100
3634 # Python 3.7: Use .coveragerc-py37 to exclude aio module from coverage since it requires Python 3.8+ (Starlette dependency)
4846 isort
4947 mypy
5048 build
51- extras =
52- async
5349commands =
5450 black --check src tests conftest.py --exclude tests/test_functions/background_load_error/main.py
5551 isort -c src tests conftest.py
You can’t perform that action at this time.
0 commit comments