diff --git a/CHANGELOG.md b/CHANGELOG.md index db0f5cd9..23b81923 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,15 +5,22 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Fix handling of debug flag when gunicorn is not present ([#44]) ## [1.4.1] - 2020-05-07 +### Fixed - Fix Windows support ([#38]) ## [1.4.0] - 2020-05-06 +### Changed - Use gunicorn as a production HTTP server ## [1.3.0] - 2020-04-13 +### Added - Add support for running `python -m functions_framework` ([#31]) + +### Changed - Move `functions_framework.cli.cli` to `functions_framework._cli._cli` - Adjust path handling for robots.txt and favicon.ico ([#33]) @@ -56,6 +63,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [1.0.1]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v1.0.1 [1.0.0]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v1.0.0 +[#44]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/44 [#38]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/38 [#33]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/33 [#31]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/31 diff --git a/src/functions_framework/_http/__init__.py b/src/functions_framework/_http/__init__.py index 0e532780..ca9b0f5c 100644 --- a/src/functions_framework/_http/__init__.py +++ b/src/functions_framework/_http/__init__.py @@ -18,9 +18,10 @@ class HTTPServer: def __init__(self, app, debug, **options): self.app = app + self.debug = debug self.options = options - if debug: + if self.debug: self.server_class = FlaskApplication else: try: @@ -31,7 +32,9 @@ def __init__(self, app, debug, **options): self.server_class = FlaskApplication def run(self, host, port): - http_server = self.server_class(self.app, host, port, **self.options) + http_server = self.server_class( + self.app, host, port, self.debug, **self.options + ) http_server.run() diff --git a/src/functions_framework/_http/flask.py b/src/functions_framework/_http/flask.py index 270390e7..b2edf563 100644 --- a/src/functions_framework/_http/flask.py +++ b/src/functions_framework/_http/flask.py @@ -14,11 +14,12 @@ class FlaskApplication: - def __init__(self, app, host, port, **options): + def __init__(self, app, host, port, debug, **options): self.app = app self.host = host self.port = port + self.debug = debug self.options = options def run(self): - self.app.run(self.host, self.port, debug=True, **self.options) + self.app.run(self.host, self.port, debug=self.debug, **self.options) diff --git a/src/functions_framework/_http/gunicorn.py b/src/functions_framework/_http/gunicorn.py index fd0b0a3a..163b5317 100644 --- a/src/functions_framework/_http/gunicorn.py +++ b/src/functions_framework/_http/gunicorn.py @@ -16,7 +16,7 @@ class GunicornApplication(gunicorn.app.base.BaseApplication): - def __init__(self, app, host, port, **options): + def __init__(self, app, host, port, debug, **options): self.options = { "bind": "%s:%s" % (host, port), "workers": 1, diff --git a/tests/test_http.py b/tests/test_http.py index 37fbf2cf..e9929d94 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -75,12 +75,15 @@ def test_httpserver(monkeypatch, debug, gunicorn_missing, expected): wrapper.run(host, port) - assert wrapper.server_class.calls == [pretend.call(app, host, port, **options)] + assert wrapper.server_class.calls == [ + pretend.call(app, host, port, debug, **options) + ] assert http_server.run.calls == [pretend.call()] @pytest.mark.skipif("platform.system() == 'Windows'") -def test_gunicorn_application(): +@pytest.mark.parametrize("debug", [True, False]) +def test_gunicorn_application(debug): app = pretend.stub() host = "1.2.3.4" port = "1234" @@ -89,7 +92,7 @@ def test_gunicorn_application(): import functions_framework._http.gunicorn gunicorn_app = functions_framework._http.gunicorn.GunicornApplication( - app, host, port, **options + app, host, port, debug, **options ) assert gunicorn_app.app == app @@ -107,23 +110,25 @@ def test_gunicorn_application(): assert gunicorn_app.load() == app -def test_flask_application(): +@pytest.mark.parametrize("debug", [True, False]) +def test_flask_application(debug): app = pretend.stub(run=pretend.call_recorder(lambda *a, **kw: None)) host = pretend.stub() port = pretend.stub() options = {"a": pretend.stub(), "b": pretend.stub()} flask_app = functions_framework._http.flask.FlaskApplication( - app, host, port, **options + app, host, port, debug, **options ) assert flask_app.app == app assert flask_app.host == host assert flask_app.port == port + assert flask_app.debug == debug assert flask_app.options == options flask_app.run() assert app.run.calls == [ - pretend.call(host, port, debug=True, a=options["a"], b=options["b"]), + pretend.call(host, port, debug=debug, a=options["a"], b=options["b"]), ]