diff --git a/CHANGELOG.md b/CHANGELOG.md index f0e63698..cacc025f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ 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] +- Add support for running `python -m functions_framework` ([#31]) +- Move `functions_framework.cli.cli` to `functions_framework._cli._cli` ## [1.2.0] - 2020-02-20 ### Added @@ -41,6 +43,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 +[#31]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/31 [#20]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/20 [#14]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/14 [#12]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/12 diff --git a/setup.py b/setup.py index 062c9748..a51631a3 100644 --- a/setup.py +++ b/setup.py @@ -51,9 +51,9 @@ extras_require={"test": ["pytest", "tox"]}, entry_points={ "console_scripts": [ - "functions-framework=functions_framework.cli:cli", - "functions_framework=functions_framework.cli:cli", - "ff=functions_framework.cli:cli", + "functions-framework=functions_framework._cli:_cli", + "functions_framework=functions_framework._cli:_cli", + "ff=functions_framework._cli:_cli", ] }, ) diff --git a/src/functions_framework/__main__.py b/src/functions_framework/__main__.py new file mode 100644 index 00000000..0435041c --- /dev/null +++ b/src/functions_framework/__main__.py @@ -0,0 +1,3 @@ +from functions_framework._cli import _cli + +_cli(prog_name="python -m functions_framework") diff --git a/src/functions_framework/cli.py b/src/functions_framework/_cli.py similarity index 95% rename from src/functions_framework/cli.py rename to src/functions_framework/_cli.py index 9bab270c..20092228 100644 --- a/src/functions_framework/cli.py +++ b/src/functions_framework/_cli.py @@ -32,7 +32,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) -def cli(target, source, signature_type, host, port, debug, dry_run): +def _cli(target, source, signature_type, host, port, debug, dry_run): app = create_app(target, source, signature_type) if dry_run: click.echo("Function: {}".format(target)) diff --git a/tests/test_cli.py b/tests/test_cli.py index 0bc41a37..7d408d81 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -19,7 +19,7 @@ import functions_framework -from functions_framework.cli import cli +from functions_framework._cli import _cli @pytest.fixture @@ -30,13 +30,13 @@ def run(): @pytest.fixture def create_app(monkeypatch, run): create_app = pretend.call_recorder(lambda *a, **kw: pretend.stub(run=run)) - monkeypatch.setattr(functions_framework.cli, "create_app", create_app) + monkeypatch.setattr(functions_framework._cli, "create_app", create_app) return create_app def test_cli_no_arguments(): runner = CliRunner() - result = runner.invoke(cli) + result = runner.invoke(_cli) assert result.exit_code == 2 assert "Missing option '--target'" in result.output @@ -98,7 +98,7 @@ def test_cli_no_arguments(): ) def test_cli_arguments(create_app, run, args, env, create_app_calls, run_calls): runner = CliRunner(env=env) - result = runner.invoke(cli, args) + result = runner.invoke(_cli, args) assert result.exit_code == 0 assert create_app.calls == create_app_calls