From 5a58a7ec56cf8a74e8db60a817232c3e93336864 Mon Sep 17 00:00:00 2001 From: brendancol Date: Wed, 16 Feb 2022 16:49:29 -0500 Subject: [PATCH 1/5] added serve cli command to start default flask server --- mapshader/commands/serve.py | 56 +++++++++++++++++++++++++++++++++++++ setup.py | 1 + 2 files changed, 57 insertions(+) create mode 100644 mapshader/commands/serve.py diff --git a/mapshader/commands/serve.py b/mapshader/commands/serve.py new file mode 100644 index 0000000..f76ab1a --- /dev/null +++ b/mapshader/commands/serve.py @@ -0,0 +1,56 @@ +import click +import yaml + +from ..flask_app import create_app + + +@click.command( + no_args_is_help=True, + 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)) + + app = create_app(config_yaml, contains=glob).run( + host=host, port=port, debug=False) diff --git a/setup.py b/setup.py index 840f70f..e9dacd0 100644 --- a/setup.py +++ b/setup.py @@ -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 ''', ) From 39eb58aca604ba3b2cafd2f61fe38449a0fb691e Mon Sep 17 00:00:00 2001 From: brendancol Date: Wed, 16 Feb 2022 17:03:11 -0500 Subject: [PATCH 2/5] pep8 fixes --- mapshader/commands/serve.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mapshader/commands/serve.py b/mapshader/commands/serve.py index f76ab1a..cccc581 100644 --- a/mapshader/commands/serve.py +++ b/mapshader/commands/serve.py @@ -1,5 +1,4 @@ import click -import yaml from ..flask_app import create_app @@ -52,5 +51,5 @@ def serve(config_yaml=None, host='0.0.0.0', port=5000, glob=None, debug=False): if config_yaml: config_yaml = path.abspath(path.expanduser(config_yaml)) - app = create_app(config_yaml, contains=glob).run( + create_app(config_yaml, contains=glob).run( host=host, port=port, debug=False) From e5616254df5555b1a5fa8225553b3d4a7e33bd33 Mon Sep 17 00:00:00 2001 From: brendancol Date: Wed, 16 Feb 2022 21:20:12 -0500 Subject: [PATCH 3/5] fixed debug param typo --- mapshader/commands/serve.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mapshader/commands/serve.py b/mapshader/commands/serve.py index cccc581..72943b7 100644 --- a/mapshader/commands/serve.py +++ b/mapshader/commands/serve.py @@ -52,4 +52,4 @@ def serve(config_yaml=None, host='0.0.0.0', port=5000, glob=None, debug=False): config_yaml = path.abspath(path.expanduser(config_yaml)) create_app(config_yaml, contains=glob).run( - host=host, port=port, debug=False) + host=host, port=port, debug=debug) From 2604f62b69e38659bbf31ba512df9dd7840e3721 Mon Sep 17 00:00:00 2001 From: brendancol Date: Wed, 16 Feb 2022 22:25:47 -0500 Subject: [PATCH 4/5] changed behavior of serve without arguments to run default services --- mapshader/commands/serve.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mapshader/commands/serve.py b/mapshader/commands/serve.py index 72943b7..2e3c451 100644 --- a/mapshader/commands/serve.py +++ b/mapshader/commands/serve.py @@ -4,7 +4,6 @@ @click.command( - no_args_is_help=True, context_settings=dict(help_option_names=['-h', '--help']), short_help='Start default mapshader server using Flask', help=( From 4ee4ceaeb04ccb74e7e7bc5cd22620d207ff89c3 Mon Sep 17 00:00:00 2001 From: brendancol Date: Wed, 16 Feb 2022 22:26:53 -0500 Subject: [PATCH 5/5] updated README.md with new serve command --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9d773c5..aaaff6a 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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