8000 Add main file (#31) · sesi/functions-framework-python@9fd5585 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9fd5585

Browse files
authored
Add main file (GoogleCloudPlatform#31)
* Add __main__ file * Rename cli to indicate it is internal * Add prog_name to cli invocation in __main__.py * Update changelog
1 parent 99206d1 commit 9fd5585

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
- Add support for running `python -m functions_framework` ([#31])
9+
- Move `functions_framework.cli.cli` to `functions_framework._cli._cli`
810

911
## [1.2.0] - 2020-02-20
1012
### Added
@@ -41,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4143
[1.0.1]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v1.0.1
4244
[1.0.0]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v1.0.0
4345

46+
[#31]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/31
4447
[#20]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/20
4548
[#14]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/14
4649
[#12]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/12

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@
5151
extras_require={"test": ["pytest", "tox"]},
5252
entry_points={
5353
"console_scripts": [
54-
"functions-framework=functions_framework.cli:cli",
55-
"functions_framework=functions_framework.cli:cli",
56-
"ff=functions_framework.cli:cli",
54+
"functions-framework=functions_framework._cli:_cli",
55+
"functions_framework=functions_framework._cli:_cli",
56+
"ff=functions_framework._cli:_cli",
5757
]
5858
},
5959
)

src/functions_framework/__main__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from functions_framework._cli import _cli
2+
3+
_cli(prog_name="python -m functions_framework")

src/functions_framework/cli.py renamed to src/functions_framework/_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
@click.option("--port", envvar="PORT", type=click.INT, default=8080)
3333
@click.option("--debug", envvar="DEBUG", is_flag=True)
3434
@click.option("--dry-run", envvar="DRY_RUN", is_flag=True)
35-
def cli(target, source, signature_type, host, port, debug, dry_run):
35+
def _cli(target, source, signature_type, host, port, debug, dry_run):
3636
app = create_app(target, source, signature_type)
3737
if dry_run:
3838
click.echo("Function: {}".format(target))

tests/test_cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import functions_framework
2121

22-
from functions_framework.cli import cli
22+
from functions_framework._cli import _cli
2323

2424

2525
@pytest.fixture
@@ -30,13 +30,13 @@ def run():
3030
@pytest.fixture
3131
def create_app(monkeypatch, run):
3232
create_app = pretend.call_recorder(lambda *a, **kw: pretend.stub(run=run))
33-
monkeypatch.setattr(functions_framework.cli, "create_app", create_app)
33+
monkeypatch.setattr(functions_framework._cli, "create_app", create_app)
3434
return create_app
3535

3636

3737
def test_cli_no_arguments():
3838
runner = CliRunner()
39-
result = runner.invoke(cli)
39+
result = runner.invoke(_cli)
4040

4141
assert result.exit_code == 2
4242
assert "Missing option '--target'" in result.output
@@ -98,7 +98,7 @@ def test_cli_no_arguments():
9898
)
9999
def test_cli_arguments(create_app, run, args, env, create_app_calls, run_calls):
100100
runner = CliRunner(env=env)
101-
result = runner.invoke(cli, args)
101< 4988 /code>+
result = runner.invoke(_cli, args)
102102

103103
assert result.exit_code == 0
104104
assert create_app.calls == create_app_calls

0 commit comments

Comments
 (0)
0