Skip to content

Commit

Permalink
Add main file (#31)
Browse files Browse the repository at this point in the history
* Add __main__ file

* Rename cli to indicate it is internal

* Add prog_name to cli invocation in __main__.py

* Update changelog
  • Loading branch information
di authored Apr 8, 2020
1 parent 99206d1 commit 9fd5585
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
},
)
3 changes: 3 additions & 0 deletions src/functions_framework/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from functions_framework._cli import _cli

_cli(prog_name="python -m functions_framework")
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 4 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import functions_framework

from functions_framework.cli import cli
from functions_framework._cli import _cli


@pytest.fixture
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9fd5585

Please sign in to comment.