From b7a8194c82db6fe1c0789a08cac0abf1a0162465 Mon Sep 17 00:00:00 2001 From: anovis Date: Mon, 10 Jan 2022 10:40:59 -0400 Subject: [PATCH 1/4] Add ability to pass options to create_server --- README.md | 1 + src/functions_framework/_cli.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 192a9b55..66e0228c 100644 --- a/README.md +++ b/README.md @@ -323,6 +323,7 @@ You can configure the Functions Framework using command-line flags or environmen | `--source` | `FUNCTION_SOURCE` | The path to the file containing your function. Default: `main.py` (in the current working directory) | | `--debug` | `DEBUG` | A flag that allows to run functions-framework to run in debug mode, including live reloading. Default: `False` | | `--dry-run` | `DRY_RUN` | A flag that allows for testing the function build from the configuration without creating a server. Default: `False` | +| `--options` | `OPTIONS` | Pass in options to be used to override defaults in the HTTP Server. Options should be in the format `"KEY:VALUE"`. For example `--options="workers:3" --options="thread:9"` will set the default workers to 3 and threads to 9. If using the Environment variable, then make sure multiple options are seprated by a whitespace. Default: `{}` | ## Enable Google Cloud Function Events diff --git a/src/functions_framework/_cli.py b/src/functions_framework/_cli.py index 663ea50f..fa88ea2a 100644 --- a/src/functions_framework/_cli.py +++ b/src/functions_framework/_cli.py @@ -33,11 +33,15 @@ @click.option("--port", envvar="PORT", type=click.INT, default=8080) @click.option("--debug", envvar="DEBUG", is_flag=True) @click.option("--dry-run", envvar="DRY_RUN", is_flag=True) -def _cli(target, source, signature_type, host, port, debug, dry_run): +@click.option("--options", "-o", envvar="OPTIONS", multiple=True) +def _cli(target, source, signature_type, host, port, debug, dry_run, options): app = create_app(target, source, signature_type) if dry_run: click.echo("Function: {}".format(target)) click.echo("URL: http://{}:{}/".format(host, port)) click.echo("Dry run successful, shutting down.") else: - create_server(app, debug).run(host, port) + server_options = { + option.split(":")[0]: option.split(":")[1] for option in options + } + create_server(app, debug, **server_options).run(host, port) \ No newline at end of file From c35e6e46b2e09736b55cd036b3694f02e60bb4a3 Mon Sep 17 00:00:00 2001 From: anovis Date: Mon, 10 Jan 2022 10:40:59 -0400 Subject: [PATCH 2/4] feat: Add ability to pass options to create_server --- README.md | 1 + src/functions_framework/_cli.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 192a9b55..66e0228c 100644 --- a/README.md +++ b/README.md @@ -323,6 +323,7 @@ You can configure the Functions Framework using command-line flags or environmen | `--source` | `FUNCTION_SOURCE` | The path to the file containing your function. Default: `main.py` (in the current working directory) | | `--debug` | `DEBUG` | A flag that allows to run functions-framework to run in debug mode, including live reloading. Default: `False` | | `--dry-run` | `DRY_RUN` | A flag that allows for testing the function build from the configuration without creating a server. Default: `False` | +| `--options` | `OPTIONS` | Pass in options to be used to override defaults in the HTTP Server. Options should be in the format `"KEY:VALUE"`. For example `--options="workers:3" --options="thread:9"` will set the default workers to 3 and threads to 9. If using the Environment variable, then make sure multiple options are seprated by a whitespace. Default: `{}` | ## Enable Google Cloud Function Events diff --git a/src/functions_framework/_cli.py b/src/functions_framework/_cli.py index 663ea50f..fa88ea2a 100644 --- a/src/functions_framework/_cli.py +++ b/src/functions_framework/_cli.py @@ -33,11 +33,15 @@ @click.option("--port", envvar="PORT", type=click.INT, default=8080) @click.option("--debug", envvar="DEBUG", is_flag=True) @click.option("--dry-run", envvar="DRY_RUN", is_flag=True) -def _cli(target, source, signature_type, host, port, debug, dry_run): +@click.option("--options", "-o", envvar="OPTIONS", multiple=True) +def _cli(target, source, signature_type, host, port, debug, dry_run, options): app = create_app(target, source, signature_type) if dry_run: click.echo("Function: {}".format(target)) click.echo("URL: http://{}:{}/".format(host, port)) click.echo("Dry run successful, shutting down.") else: - create_server(app, debug).run(host, port) + server_options = { + option.split(":")[0]: option.split(":")[1] for option in options + } + create_server(app, debug, **server_options).run(host, port) \ No newline at end of file From a288a011115cf5375413e3b2b6067fff59ee9883 Mon Sep 17 00:00:00 2001 From: anovis Date: Mon, 10 Jan 2022 11:24:04 -0400 Subject: [PATCH 3/4] feat: Add test --- src/functions_framework/_cli.py | 2 +- tests/test_cli.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/functions_framework/_cli.py b/src/functions_framework/_cli.py index fa88ea2a..fb581857 100644 --- a/src/functions_framework/_cli.py +++ b/src/functions_framework/_cli.py @@ -33,7 +33,7 @@ @click.option("--port", envvar="PORT", type=click.INT, default=8080) @click.option("--debug", envvar="DEBUG", is_flag=True) @click.option("--dry-run", envvar="DRY_RUN", is_flag=True) -@click.option("--options", "-o", envvar="OPTIONS", multiple=True) +@click.option("--options", "-o", envvar="OPTIONS", multiple=True, default=[]) def _cli(target, source, signature_type, host, port, debug, dry_run, options): app = create_app(target, source, signature_type) if dry_run: diff --git a/tests/test_cli.py b/tests/test_cli.py index aa4a901e..8404cf70 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -99,6 +99,12 @@ def test_cli_no_arguments(): [pretend.call("foo", None, "http")], [pretend.call("0.0.0.0", 8080)], ), + ( + ["--target", "foo", "--option", "workers:2", "--option", "threads:2"], + {}, + [pretend.call("foo", None, "http")], + [pretend.call("0.0.0.0", 8080, {"workers": 2, "threads": 2})], + ), ], ) def test_cli(monkeypatch, args, env, create_app_calls, run_calls): From aa7513d0262862172d45207f08b4031c4ec5d023 Mon Sep 17 00:00:00 2001 From: Fer Date: Wed, 13 Sep 2023 08:56:55 -0600 Subject: [PATCH 4/4] Create .github/CODEOWNERS --- .github/CODEOWNERS | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..99bf45c4 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @premisedata/infosec infosec@premise.com