From a3e21a6b416628637c2592166eb775d36c7ce776 Mon Sep 17 00:00:00 2001 From: tdstein Date: Wed, 18 Oct 2023 12:13:23 -0400 Subject: [PATCH 1/3] Adds 'flask' command --- CHANGELOG.md | 3 +++ README.md | 17 ++++++++-------- rsconnect/main.py | 51 ++++++++++++++++++++++++++++------------------- 3 files changed, 42 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ce5225c4..2b787b186 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. 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 ### Fixed @@ -20,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 and `*_app.py` are now considered. However, if the directory contains more than one file matching these new patterns, you must provide rsconnect-python with an explicit `--entrypoint` argument. +- Added the `deploy flask` command. +- Added the `write-manifest flask` command. ## [1.20.0] - 2023-09-11 diff --git a/README.md b/README.md index cf4da9df4..22e5e076b 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ you will need to include the `--cacert` option that points to your certificate authority (CA) trusted certificates file. Both of these options can be saved along with the URL and API Key for a server. -> **Note** +> **Note** > When certificate information is saved for the server, the specified file > is read and its _contents_ are saved under the server's nickname. If the CA file's > contents are ever changed, you will need to add the server information again. @@ -135,7 +135,7 @@ rsconnect add \ --name myserver ``` -> **Note** +> **Note** > The `rsconnect` CLI will verify that the serve URL and API key > are valid. If either is found not to be, no information will be saved. @@ -270,8 +270,9 @@ rsconnect write-manifest notebook my-notebook.ipynb You can deploy a variety of APIs and applications using sub-commands of the `rsconnect deploy` command. -* `api`: WSGI-compliant APIs such as Flask and packages based on Flask -* `fastapi`: ASGI-compliant APIs (FastAPI, Quart, Sanic, and Falcon) +* `api`: WSGI-compliant APIs (e.g., `gunicorn`, `werkzeug`, `uwsgi`, `pyramid`, and `bottle`) +* `flask`: Flask APIs +* `fastapi`: ASGI-compliant APIs (e.g, `fastapi`, `quart`, `sanic`, and `falcon`) * `dash`: Python Dash apps * `streamlit`: Streamlit apps * `bokeh`: Bokeh server apps @@ -430,7 +431,7 @@ filename referenced in the manifest. ### Environment variables You can set environment variables during deployment. Their names and values will be -passed to Posit Connect during deployment so you can use them in your code. Note that +passed to Posit Connect during deployment so you can use them in your code. Note that if you are using `rsconnect` to deploy to shinyapps.io, environment variable management is not supported on that platform. @@ -985,9 +986,9 @@ xargs printf -- '-g %s\n' < guids.txt | xargs rsconnect content build add ``` ## Programmatic Provisioning -Posit Connect supports the programmatic bootstrapping of an administrator API key +Posit Connect supports the programmatic bootstrapping of an administrator API key for scripted provisioning tasks. This process is supported by the `rsconnect bootstrap` command, -which uses a JSON Web Token to request an initial API key from a fresh Connect instance. +which uses a JSON Web Token to request an initial API key from a fresh Connect instance. > **Warning** > This feature **requires Python version 3.6 or higher**. @@ -998,7 +999,7 @@ rsconnect bootstrap \ --jwt-keypath /path/to/secret.key ``` -A full description on how to use `rsconnect bootstrap` in a provisioning workflow is provided in the Connect administrator guide's +A full description on how to use `rsconnect bootstrap` in a provisioning workflow is provided in the Connect administrator guide's [programmatic provisioning](https://docs.posit.co/connect/admin/programmatic-provisioning) documentation. ## Server Administration Tasks diff --git a/rsconnect/main.py b/rsconnect/main.py index 5af3128f9..cc579aef9 100644 --- a/rsconnect/main.py +++ b/rsconnect/main.py @@ -8,6 +8,7 @@ import click from os.path import abspath, dirname, exists, isdir, join from functools import wraps +from typing import Optional from rsconnect.certificates import read_certificate_file @@ -65,6 +66,7 @@ from .log import logger, LogOutputFormat from .metadata import ServerStore, AppStore from .models import ( + AppMode, AppModes, BuildStatus, ContentGuidWithBundleParamType, @@ -1281,18 +1283,22 @@ def deploy_html( ) -def generate_deploy_python(app_mode, alias, min_version): +def generate_deploy_python(app_mode: AppMode, alias: str, min_version: str, desc: Optional[str] = None): + + if desc is None: + desc = app_mode.desc() + # noinspection SpellCheckingInspection @deploy.command( name=alias, short_help="Deploy a {desc} to Posit Connect [v{version}+], Posit Cloud, or shinyapps.io.".format( - desc=app_mode.desc(), + desc=desc, version=min_version, ), help=( "Deploy a {desc} module to Posit Connect, Posit Cloud, or shinyapps.io (if supported by the platform). " 'The "directory" argument must refer to an existing directory that contains the application code.' - ).format(desc=app_mode.desc()), + ).format(desc=desc), no_args_is_help=True, ) @server_args @@ -1407,14 +1413,13 @@ def deploy_app( return deploy_app -deploy_api = generate_deploy_python(app_mode=AppModes.PYTHON_API, alias="api", min_version="1.8.2") -# TODO: set fastapi min_version correctly -# deploy_fastapi = generate_deploy_python(app_mode=AppModes.PYTHON_FASTAPI, alias="fastapi", min_version="2021.08.0") -deploy_fastapi = generate_deploy_python(app_mode=AppModes.PYTHON_FASTAPI, alias="fastapi", min_version="2021.08.0") -deploy_dash_app = generate_deploy_python(app_mode=AppModes.DASH_APP, alias="dash", min_version="1.8.2") -deploy_streamlit_app = generate_deploy_python(app_mode=AppModes.STREAMLIT_APP, alias="streamlit", min_version="1.8.4") -deploy_bokeh_app = generate_deploy_python(app_mode=AppModes.BOKEH_APP, alias="bokeh", min_version="1.8.4") -deploy_shiny = generate_deploy_python(app_mode=AppModes.PYTHON_SHINY, alias="shiny", min_version="2022.07.0") +generate_deploy_python(app_mode=AppModes.PYTHON_API, alias="api", min_version="1.8.2") +generate_deploy_python(app_mode=AppModes.PYTHON_API, alias="flask", min_version="1.8.2", desc="Flask API") +generate_deploy_python(app_mode=AppModes.PYTHON_FASTAPI, alias="fastapi", min_version="2021.08.0") +generate_deploy_python(app_mode=AppModes.DASH_APP, alias="dash", min_version="1.8.2") +generate_deploy_python(app_mode=AppModes.STREAMLIT_APP, alias="streamlit", min_version="1.8.4") +generate_deploy_python(app_mode=AppModes.BOKEH_APP, alias="bokeh", min_version="1.8.4") +generate_deploy_python(app_mode=AppModes.PYTHON_SHINY, alias="shiny", min_version="2022.07.0") @deploy.command( @@ -1759,16 +1764,19 @@ def write_manifest_quarto( ) -def generate_write_manifest_python(app_mode, alias): +def generate_write_manifest_python(app_mode, alias, desc: Optional[str] = None): + if desc is None: + desc = app_mode.desc() + # noinspection SpellCheckingInspection @write_manifest.command( name=alias, - short_help="Create a manifest.json file for a {desc}.".format(desc=app_mode.desc()), + short_help="Create a manifest.json file for a {desc}.".format(desc=desc), help=( "Create a manifest.json file for a {desc} for later deployment. This will create an " 'environment file ("requirements.txt") if one does not exist. All files ' "are created in the same directory as the API code." - ).format(desc=app_mode.desc()), + ).format(desc=desc), ) @click.option("--overwrite", "-o", is_flag=True, help="Overwrite manifest.json, if it exists.") @click.option( @@ -1776,7 +1784,7 @@ def generate_write_manifest_python(app_mode, alias): "-e", help=( "The module and executable object which serves as the entry point for the {desc} (defaults to app)" - ).format(desc=app_mode.desc()), + ).format(desc=desc), ) @click.option( "--exclude", @@ -1850,12 +1858,13 @@ def manifest_writer( return manifest_writer -write_manifest_api = generate_write_manifest_python(AppModes.PYTHON_API, alias="api") -write_manifest_fastapi = generate_write_manifest_python(AppModes.PYTHON_FASTAPI, alias="fastapi") -write_manifest_dash = generate_write_manifest_python(AppModes.DASH_APP, alias="dash") -write_manifest_streamlit = generate_write_manifest_python(AppModes.STREAMLIT_APP, alias="streamlit") -write_manifest_bokeh = generate_write_manifest_python(AppModes.BOKEH_APP, alias="bokeh") -write_manifest_shiny = generate_write_manifest_python(AppModes.PYTHON_SHINY, alias="shiny") +generate_write_manifest_python(AppModes.BOKEH_APP, alias="bokeh") +generate_write_manifest_python(AppModes.DASH_APP, alias="dash") +generate_write_manifest_python(AppModes.PYTHON_API, alias="api") +generate_write_manifest_python(AppModes.PYTHON_API, alias="flask", desc="Flask API") +generate_write_manifest_python(AppModes.PYTHON_FASTAPI, alias="fastapi") +generate_write_manifest_python(AppModes.PYTHON_SHINY, alias="shiny") +generate_write_manifest_python(AppModes.STREAMLIT_APP, alias="streamlit") # noinspection SpellCheckingInspection From ecabfe207d3fff07fae029fa5ffa6de97f730cae Mon Sep 17 00:00:00 2001 From: tdstein Date: Wed, 18 Oct 2023 12:23:14 -0400 Subject: [PATCH 2/3] Fixes desc reference --- rsconnect/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rsconnect/main.py b/rsconnect/main.py index 585311633..5051b21db 100644 --- a/rsconnect/main.py +++ b/rsconnect/main.py @@ -1312,7 +1312,7 @@ def generate_deploy_python(app_mode: AppMode, alias: str, min_version: str, desc "-e", help=( "The module and executable object which serves as the entry point for the {desc} (defaults to app)" - ).format(desc=app_mode.desc()), + ).format(desc=desc), ) @click.option( "--exclude", From 382f1a497c3b6ece83b510c586b423640d539c15 Mon Sep 17 00:00:00 2001 From: tdstein Date: Wed, 18 Oct 2023 16:31:27 -0400 Subject: [PATCH 3/3] Updates API deployment options. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 22e5e076b..d910f084a 100644 --- a/README.md +++ b/README.md @@ -270,9 +270,9 @@ rsconnect write-manifest notebook my-notebook.ipynb You can deploy a variety of APIs and applications using sub-commands of the `rsconnect deploy` command. -* `api`: WSGI-compliant APIs (e.g., `gunicorn`, `werkzeug`, `uwsgi`, `pyramid`, and `bottle`) -* `flask`: Flask APIs -* `fastapi`: ASGI-compliant APIs (e.g, `fastapi`, `quart`, `sanic`, and `falcon`) +* `api`: WSGI-compliant APIs (e.g., `bottle`, `falcon`, `flask`, `flask-restx`, `flasgger`, `pycnic`). +* `flask`: Flask APIs (_Note: `flask` is an alias of `api`._). +* `fastapi`: ASGI-compliant APIs (e.g, `fastapi`, `quart`, `sanic`, `starlette`) * `dash`: Python Dash apps * `streamlit`: Streamlit apps * `bokeh`: Bokeh server apps