Skip to content

Commit 5a4ff5c

Browse files
author
Matthew Lynch
committed
use decorators consistently to allow for error propagation
1 parent 91a9e07 commit 5a4ff5c

File tree

1 file changed

+81
-76
lines changed

1 file changed

+81
-76
lines changed

rsconnect/main.py

Lines changed: 81 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -134,26 +134,37 @@ def wrapper(*args, **kwargs):
134134

135135

136136
def shinyapps_args(func):
137-
account_option = click.option(
137+
@click.option(
138138
"--account",
139139
"-A",
140140
envvar="SHINYAPPS_ACCOUNT",
141141
help="The shinyapps.io account name.",
142142
)
143-
token_option = click.option(
143+
@click.option(
144144
"--token",
145145
"-T",
146146
envvar="SHINYAPPS_TOKEN",
147147
help="The shinyapps.io token.",
148148
)
149-
secret_option = click.option(
149+
@click.option(
150150
"--secret",
151151
"-S",
152152
envvar="SHINYAPPS_SECRET",
153153
help="The shinyapps.io token secret.",
154154
)
155+
@functools.wraps(func)
156+
def wrapper(*args, **kwargs):
157+
return func(*args, **kwargs)
155158

156-
return secret_option(token_option(account_option(func)))
159+
return wrapper
160+
161+
162+
def _passthrough(func):
163+
@functools.wraps(func)
164+
def wrapper(*args, **kwargs):
165+
return func(*args, **kwargs)
166+
167+
return wrapper
157168

158169

159170
def validate_env_vars(ctx, param, all_values):
@@ -973,76 +984,75 @@ def deploy_html(
973984
)
974985

975986

976-
def generate_deploy_python(app_mode, alias, min_version, supported_by_shinyapps=None):
987+
def generate_deploy_python(app_mode, alias, min_version, supported_by_shinyapps=False):
988+
shinyapps = shinyapps_args if supported_by_shinyapps else _passthrough
989+
977990
# noinspection SpellCheckingInspection
978-
decorators = [
979-
deploy.command(
980-
name=alias,
981-
short_help="Deploy a {desc} to RStudio Connect [v{version}+].".format(
982-
desc=app_mode.desc(), version=min_version
983-
),
984-
help=(
985-
'Deploy a {desc} module to RStudio Connect. The "directory" argument must refer to an '
986-
"existing directory that contains the application code."
987-
).format(desc=app_mode.desc()),
988-
),
989-
server_args,
990-
shinyapps_args if supported_by_shinyapps else None,
991-
content_args,
992-
click.option(
993-
"--entrypoint",
994-
"-e",
995-
help=(
996-
"The module and executable object which serves as the entry point for the {desc} (defaults to app)"
997-
).format(desc=app_mode.desc()),
998-
),
999-
click.option(
1000-
"--exclude",
1001-
"-x",
1002-
multiple=True,
1003-
help=(
1004-
"Specify a glob pattern for ignoring files when building the bundle. Note that your shell may try "
1005-
"to expand this which will not do what you expect. Generally, it's safest to quote the pattern. "
1006-
"This option may be repeated."
1007-
),
1008-
),
1009-
click.option(
1010-
"--python",
1011-
"-p",
1012-
type=click.Path(exists=True),
1013-
help=(
1014-
"Path to Python interpreter whose environment should be used. "
1015-
"The Python environment must have the rsconnect package installed."
1016-
),
1017-
),
1018-
click.option(
1019-
"--conda",
1020-
"-C",
1021-
is_flag=True,
1022-
hidden=True,
1023-
help="Use Conda to deploy (requires Connect version 1.8.2 or later)",
1024-
),
1025-
click.option(
1026-
"--force-generate",
1027-
"-g",
1028-
is_flag=True,
1029-
help='Force generating "requirements.txt", even if it already exists.',
991+
@deploy.command(
992+
name=alias,
993+
short_help="Deploy a {desc} to RStudio Connect [v{version}+].".format(
994+
desc=app_mode.desc(), version=min_version
1030995
),
1031-
click.option(
1032-
"--image",
1033-
"-I",
1034-
help="Target image to be used during content execution (only applicable if the RStudio Connect "
1035-
"server is configured to use off-host execution)",
996+
help=(
997+
'Deploy a {desc} module to RStudio Connect. The "directory" argument must refer to an '
998+
"existing directory that contains the application code."
999+
).format(desc=app_mode.desc()),
1000+
)
1001+
@server_args
1002+
@content_args
1003+
@shinyapps
1004+
@click.option(
1005+
"--entrypoint",
1006+
"-e",
1007+
help=(
1008+
"The module and executable object which serves as the entry point for the {desc} (defaults to app)"
1009+
).format(desc=app_mode.desc()),
1010+
)
1011+
@click.option(
1012+
"--exclude",
1013+
"-x",
1014+
multiple=True,
1015+
help=(
1016+
"Specify a glob pattern for ignoring files when building the bundle. Note that your shell may try "
1017+
"to expand this which will not do what you expect. Generally, it's safest to quote the pattern. "
1018+
"This option may be repeated."
10361019
),
1037-
click.argument("directory", type=click.Path(exists=True, dir_okay=True, file_okay=False)),
1038-
click.argument(
1039-
"extra_files",
1040-
nargs=-1,
1041-
type=click.Path(exists=True, dir_okay=False, file_okay=True),
1020+
)
1021+
@click.option(
1022+
"--python",
1023+
"-p",
1024+
type=click.Path(exists=True),
1025+
help=(
1026+
"Path to Python interpreter whose environment should be used. "
1027+
"The Python environment must have the rsconnect package installed."
10421028
),
1043-
cli_exception_handler,
1044-
]
1045-
1029+
)
1030+
@click.option(
1031+
"--conda",
1032+
"-C",
1033+
is_flag=True,
1034+
hidden=True,
1035+
help="Use Conda to deploy (requires Connect version 1.8.2 or later)",
1036+
)
1037+
@click.option(
1038+
"--force-generate",
1039+
"-g",
1040+
is_flag=True,
1041+
help='Force generating "requirements.txt", even if it already exists.',
1042+
)
1043+
@click.option(
1044+
"--image",
1045+
"-I",
1046+
help="Target image to be used during content execution (only applicable if the RStudio Connect "
1047+
"server is configured to use off-host execution)",
1048+
)
1049+
@click.argument("directory", type=click.Path(exists=True, dir_okay=True, file_okay=False))
1050+
@click.argument(
1051+
"extra_files",
1052+
nargs=-1,
1053+
type=click.Path(exists=True, dir_okay=False, file_okay=True),
1054+
)
1055+
@cli_exception_handler
10461056
def deploy_app(
10471057
name: str,
10481058
server: str,
@@ -1096,12 +1106,7 @@ def deploy_app(
10961106
.emit_task_log()
10971107
)
10981108

1099-
func = deploy_app
1100-
for decorator in reversed(decorators):
1101-
if decorator is not None:
1102-
func = decorator(func)
1103-
1104-
return func
1109+
return deploy_app
11051110

11061111

11071112
deploy_api = generate_deploy_python(app_mode=AppModes.PYTHON_API, alias="api", min_version="1.8.2")

0 commit comments

Comments
 (0)