Skip to content

Commit 81bc6cc

Browse files
authored
For Express, emit message if need to upgrade rsconnect-python (#1233)
1 parent ebdb97b commit 81bc6cc

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ install_requires =
4848
linkify-it-py>=1.0
4949
appdirs>=1.4.4
5050
asgiref>=3.5.2
51+
packaging>=20.9
5152
watchfiles>=0.18.0;platform_system!="Emscripten"
5253
questionary>=2.0.0;platform_system!="Emscripten"
5354
# This is needed to address a DoS issue. In the future, when we are able to upgrade

shiny/_main.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ def run_app(
288288
# is "shiny.express.app:_2f_path_2f_to_2f_app_2e_py".
289289
app = "shiny.express.app:" + escape_to_var_name(str(app_path))
290290
app_dir = str(app_path.parent)
291+
292+
# Express apps need min version of rsconnect-python to deploy correctly.
293+
_verify_rsconnect_version()
291294
else:
292295
app, app_dir = resolve_app(app, app_dir)
293296

@@ -626,3 +629,28 @@ class ReloadArgs(TypedDict):
626629
reload_includes: NotRequired[list[str]]
627630
reload_excludes: NotRequired[list[str]]
628631
reload_dirs: NotRequired[list[str]]
632+
633+
634+
# Check that the version of rsconnect supports Shiny Express; can be removed in the
635+
# future once this version of rsconnect is widely used. The dependency on "packaging"
636+
# can also be removed then, because it is only used here. (Added 2024-03)
637+
def _verify_rsconnect_version() -> None:
638+
PACKAGE_NAME = "rsconnect-python"
639+
MIN_VERSION = "1.22.0"
640+
641+
from importlib.metadata import PackageNotFoundError, version
642+
643+
from packaging.version import parse
644+
645+
try:
646+
installed_version = parse(version(PACKAGE_NAME))
647+
required_version = parse(MIN_VERSION)
648+
if installed_version < required_version:
649+
print(
650+
f"Warning: rsconnect-python {installed_version} is installed, but it does not support deploying Shiny Express applications. "
651+
f"Please upgrade to at least version {MIN_VERSION}. "
652+
"If you are using pip, you can run `pip install --upgrade rsconnect-python`",
653+
file=sys.stderr,
654+
)
655+
except PackageNotFoundError:
656+
pass

0 commit comments

Comments
 (0)