From 022e3f9c149789b01f3ea99f12cdccf3148b9f0a Mon Sep 17 00:00:00 2001 From: Mike Baynton Date: Mon, 18 Sep 2023 10:11:37 -0500 Subject: [PATCH 1/3] Edit inline help to correctly list Cloud and shinyapps.io support Fixes #481 --- rsconnect/main.py | 7 ++++--- rsconnect/models.py | 48 +++++++++++++++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/rsconnect/main.py b/rsconnect/main.py index 5af3128f..5c908be3 100644 --- a/rsconnect/main.py +++ b/rsconnect/main.py @@ -1285,14 +1285,15 @@ def generate_deploy_python(app_mode, alias, min_version): # noinspection SpellCheckingInspection @deploy.command( name=alias, - short_help="Deploy a {desc} to Posit Connect [v{version}+], Posit Cloud, or shinyapps.io.".format( + short_help="Deploy a {desc} to {deploy_targets}.".format( desc=app_mode.desc(), + deploy_targets=app_mode.deploy_targets(min_version), version=min_version, ), help=( - "Deploy a {desc} module to Posit Connect, Posit Cloud, or shinyapps.io (if supported by the platform). " + "Deploy a {desc} to {deploy_targets}. " 'The "directory" argument must refer to an existing directory that contains the application code.' - ).format(desc=app_mode.desc()), + ).format(desc=app_mode.desc(), deploy_targets=app_mode.deploy_targets(min_version)), no_args_is_help=True, ) @server_args diff --git a/rsconnect/models.py b/rsconnect/models.py index cac1ebdc..fa6d4166 100644 --- a/rsconnect/models.py +++ b/rsconnect/models.py @@ -31,11 +31,16 @@ class AppMode(object): Connect """ - def __init__(self, ordinal, name, text, ext=None): + DEPLOY_TARGET_CONNECT = 1 + DEPLOY_TARGET_CLOUD = 2 + DEPLOY_TARGET_SHINYAPPSIO = 4 + + def __init__(self, ordinal, name, text, ext=None, deploy_targets=DEPLOY_TARGET_CONNECT): self._ordinal = ordinal self._name = name self._text = text self._ext = ext + self._deploy_targets = deploy_targets def ordinal(self): return self._ordinal @@ -46,6 +51,23 @@ def name(self): def desc(self): return self._text + def deploy_targets(self, min_connect_version): + targets = [] + if self._deploy_targets & self.DEPLOY_TARGET_CONNECT: + targets.append(f"Posit Connect [v{min_connect_version}+]") + if self._deploy_targets & self.DEPLOY_TARGET_CLOUD: + targets.append("Posit Cloud") + if self._deploy_targets & self.DEPLOY_TARGET_SHINYAPPSIO: + targets.append("shinyapps.io") + + if len(targets) > 1: + targets[-1] = "or " + targets[-1] + + separator = " " + if len(targets) > 2: + separator = ", " + return separator.join(targets) + def extension(self): return self._ext @@ -63,21 +85,21 @@ class AppModes(object): """ UNKNOWN = AppMode(0, "unknown", "") - SHINY = AppMode(1, "shiny", "Shiny App", ".R") - RMD = AppMode(3, "rmd-static", "R Markdown", ".Rmd") - SHINY_RMD = AppMode(2, "rmd-shiny", "Shiny App (Rmd)") - STATIC = AppMode(4, "static", "Static HTML", ".html") - PLUMBER = AppMode(5, "api", "API") + SHINY = AppMode(1, "shiny", "Shiny App", ".R", AppMode.DEPLOY_TARGET_CLOUD | AppMode.DEPLOY_TARGET_SHINYAPPSIO | AppMode.DEPLOY_TARGET_CONNECT) + RMD = AppMode(3, "rmd-static", "R Markdown", ".Rmd", AppMode.DEPLOY_TARGET_CLOUD | AppMode.DEPLOY_TARGET_CONNECT) + SHINY_RMD = AppMode(2, "rmd-shiny", "Shiny App (Rmd)", AppMode.DEPLOY_TARGET_CLOUD | AppMode.DEPLOY_TARGET_SHINYAPPSIO | AppMode.DEPLOY_TARGET_CONNECT) + STATIC = AppMode(4, "static", "Static HTML", ".html", AppMode.DEPLOY_TARGET_CLOUD | AppMode.DEPLOY_TARGET_CONNECT) + PLUMBER = AppMode(5, "api", "API", ".R", AppMode.DEPLOY_TARGET_CLOUD | AppMode.DEPLOY_TARGET_CONNECT) TENSORFLOW = AppMode(6, "tensorflow-saved-model", "TensorFlow Model") JUPYTER_NOTEBOOK = AppMode(7, "jupyter-static", "Jupyter Notebook", ".ipynb") - PYTHON_API = AppMode(8, "python-api", "Python API") - DASH_APP = AppMode(9, "python-dash", "Dash Application") + PYTHON_API = AppMode(8, "python-api", "Python API", None, AppMode.DEPLOY_TARGET_CLOUD | AppMode.DEPLOY_TARGET_CONNECT) + DASH_APP = AppMode(9, "python-dash", "Dash Application", None, AppMode.DEPLOY_TARGET_CLOUD | AppMode.DEPLOY_TARGET_CONNECT) STREAMLIT_APP = AppMode(10, "python-streamlit", "Streamlit Application") - BOKEH_APP = AppMode(11, "python-bokeh", "Bokeh Application") - PYTHON_FASTAPI = AppMode(12, "python-fastapi", "Python FastAPI") - SHINY_QUARTO = AppMode(13, "quarto-shiny", "Shiny Quarto Document") - STATIC_QUARTO = AppMode(14, "quarto-static", "Quarto Document", ".qmd") - PYTHON_SHINY = AppMode(15, "python-shiny", "Python Shiny Application") + BOKEH_APP = AppMode(11, "python-bokeh", "Bokeh Application", None, AppMode.DEPLOY_TARGET_CLOUD | AppMode.DEPLOY_TARGET_CONNECT) + PYTHON_FASTAPI = AppMode(12, "python-fastapi", "Python FastAPI", None, AppMode.DEPLOY_TARGET_CLOUD | AppMode.DEPLOY_TARGET_CONNECT) + SHINY_QUARTO = AppMode(13, "quarto-shiny", "Shiny Quarto Document", None, AppMode.DEPLOY_TARGET_CLOUD | AppMode.DEPLOY_TARGET_CONNECT | AppMode.DEPLOY_TARGET_SHINYAPPSIO) + STATIC_QUARTO = AppMode(14, "quarto-static", "Quarto Document", ".qmd", AppMode.DEPLOY_TARGET_CLOUD | AppMode.DEPLOY_TARGET_CONNECT) + PYTHON_SHINY = AppMode(15, "python-shiny", "Python Shiny Application", None, AppMode.DEPLOY_TARGET_CLOUD | AppMode.DEPLOY_TARGET_CONNECT | AppMode.DEPLOY_TARGET_SHINYAPPSIO) JUPYTER_VOILA = AppMode(16, "jupyter-voila", "Jupyter Voila Application") _modes = [ From 4abff793d47a8184bb4edbebd6ac63226477d1c4 Mon Sep 17 00:00:00 2001 From: Mike Baynton Date: Mon, 18 Sep 2023 10:39:25 -0500 Subject: [PATCH 2/3] lint --- rsconnect/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/rsconnect/main.py b/rsconnect/main.py index 5c908be3..f3b4cc46 100644 --- a/rsconnect/main.py +++ b/rsconnect/main.py @@ -1288,7 +1288,6 @@ def generate_deploy_python(app_mode, alias, min_version): short_help="Deploy a {desc} to {deploy_targets}.".format( desc=app_mode.desc(), deploy_targets=app_mode.deploy_targets(min_version), - version=min_version, ), help=( "Deploy a {desc} to {deploy_targets}. " From 08e2eb61e4718deb7b9ec2a1680eef3c0457fc61 Mon Sep 17 00:00:00 2001 From: Mike Baynton Date: Mon, 18 Sep 2023 11:00:08 -0500 Subject: [PATCH 3/3] bugfix on rmd-shiny --- rsconnect/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rsconnect/models.py b/rsconnect/models.py index fa6d4166..699f1225 100644 --- a/rsconnect/models.py +++ b/rsconnect/models.py @@ -87,7 +87,7 @@ class AppModes(object): UNKNOWN = AppMode(0, "unknown", "") SHINY = AppMode(1, "shiny", "Shiny App", ".R", AppMode.DEPLOY_TARGET_CLOUD | AppMode.DEPLOY_TARGET_SHINYAPPSIO | AppMode.DEPLOY_TARGET_CONNECT) RMD = AppMode(3, "rmd-static", "R Markdown", ".Rmd", AppMode.DEPLOY_TARGET_CLOUD | AppMode.DEPLOY_TARGET_CONNECT) - SHINY_RMD = AppMode(2, "rmd-shiny", "Shiny App (Rmd)", AppMode.DEPLOY_TARGET_CLOUD | AppMode.DEPLOY_TARGET_SHINYAPPSIO | AppMode.DEPLOY_TARGET_CONNECT) + SHINY_RMD = AppMode(2, "rmd-shiny", "Shiny App (Rmd)", None, AppMode.DEPLOY_TARGET_CLOUD | AppMode.DEPLOY_TARGET_SHINYAPPSIO | AppMode.DEPLOY_TARGET_CONNECT) STATIC = AppMode(4, "static", "Static HTML", ".html", AppMode.DEPLOY_TARGET_CLOUD | AppMode.DEPLOY_TARGET_CONNECT) PLUMBER = AppMode(5, "api", "API", ".R", AppMode.DEPLOY_TARGET_CLOUD | AppMode.DEPLOY_TARGET_CONNECT) TENSORFLOW = AppMode(6, "tensorflow-saved-model", "TensorFlow Model")