Skip to content

Commit

Permalink
added serve cli command to start default flask server (#112)
Browse files Browse the repository at this point in the history
* added serve cli command to start default flask server

* pep8 fixes

* fixed debug param typo

* changed behavior of serve without arguments to run default services

* updated README.md with new serve command
  • Loading branch information
brendancol authored Feb 17, 2022
1 parent 8fa3d5f commit 3c0dd67
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pytest mapshader/tests -sv
#### Run Flask Server
```bash
conda activate mapshader
python mapshader/flask_app.py
mapshader serve

>>> * Serving Flask app "flask_app" (lazy loading)
>>> * Environment: production
Expand Down Expand Up @@ -96,7 +96,7 @@ This configuration file can then be passed to the flask server upon startup:

```bash
conda activate mapshader
python mapshader/flask_app.py -f my_services.yaml
mapshader serve my_services.yaml

>>> * Serving Flask app "flask_app" (lazy loading)
>>> * Environment: production
Expand Down
54 changes: 54 additions & 0 deletions mapshader/commands/serve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import click

from ..flask_app import create_app


@click.command(
context_settings=dict(help_option_names=['-h', '--help']),
short_help='Start default mapshader server using Flask',
help=(
'Start default mapshader server using Flask'
),
)
@click.argument(
'config_yaml',
type=str,
required=False,
)
@click.option(
'--host',
'host',
default='0.0.0.0',
type=str,
help='Host of Flask server',
)
@click.option(
'--port',
'port',
default=5000,
type=int,
help='Port number of Flask server',
)
@click.option(
'--glob',
'glob',
required=False,
type=str,
help='Filter services to start based on glob',
)
@click.option(
'--debug',
'debug',
is_flag=True,
default=False,
help='Run server in debug mode',
)
def serve(config_yaml=None, host='0.0.0.0', port=5000, glob=None, debug=False):

from os import path

if config_yaml:
config_yaml = path.abspath(path.expanduser(config_yaml))

create_app(config_yaml, contains=glob).run(
host=host, port=port, debug=debug)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
build_raster_overviews=mapshader.commands.build_raster_overviews:build_raster_overviews
examples=mapshader.commands.examples:examples
tif_to_netcdf=mapshader.commands.tif_to_netcdf:tif_to_netcdf
serve=mapshader.commands.serve:serve
''',
)

Expand Down

0 comments on commit 3c0dd67

Please sign in to comment.