Skip to content

Commit cb7eaa8

Browse files
committed
update to use executor
1 parent 40d164e commit cb7eaa8

File tree

2 files changed

+56
-72
lines changed

2 files changed

+56
-72
lines changed

rsconnect/api.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -233,19 +233,17 @@ def task_get(self, task_id, first_status=None):
233233
self._server.handle_bad_response(response)
234234
return response
235235

236-
237236
def deploy_git(self, app_name, repository, branch, subdirectory):
238237
app = self.app_create(app_name)
239238
self._server.handle_bad_response(app)
240239

241-
self.post(
240+
resp = self.post(
242241
"applications/%s/repo" % app["guid"],
243-
body={
244-
"repository": repository, "branch": branch , "subdirectory": subdirectory
245-
}
242+
body={"repository": repository, "branch": branch, "subdirectory": subdirectory},
246243
)
244+
self._server.handle_bad_response(resp)
247245

248-
task = self.post("applications/%s/deploy" % app["guid"], body=dict())
246+
task = self.app_deploy(app["guid"])
249247
self._server.handle_bad_response(task)
250248

251249
return {
@@ -323,7 +321,6 @@ def wait_for_task(
323321
poll_wait=0.5,
324322
raise_on_error=True,
325323
):
326-
327324
if log_callback is None:
328325
log_lines = []
329326
log_callback = log_lines.append
@@ -764,6 +761,18 @@ def deploy_bundle(
764761
}
765762
return self
766763

764+
@cls_logged("Deploying git repository ...")
765+
def deploy_git(self, app_name: str = None, repository: str = None, branch: str = None, subdirectory: str = None):
766+
app_name = app_name or self.get("app_name")
767+
repository = repository or self.get("repository")
768+
branch = branch or self.get("branch")
769+
subdirectory = subdirectory or self.get("subdirectory")
770+
771+
result = self.client.deploy_git(app_name, repository, branch, subdirectory)
772+
self.remote_server.handle_bad_response(result)
773+
self.state["deployed_info"] = result
774+
return self
775+
767776
def emit_task_log(
768777
self,
769778
app_id: int = None,
@@ -1144,14 +1153,9 @@ def create_application(self, account_id, application_name):
11441153
return response
11451154

11461155
def create_output(self, name: str, application_type: str, project_id=None, space_id=None, render_by=None):
1147-
data = {
1148-
"name": name,
1149-
"space": space_id,
1150-
"project": project_id,
1151-
"application_type": application_type
1152-
}
1156+
data = {"name": name, "space": space_id, "project": project_id, "application_type": application_type}
11531157
if render_by:
1154-
data['render_by'] = render_by
1158+
data["render_by"] = render_by
11551159
response = self.post("/v1/outputs/", body=data)
11561160
self._server.handle_bad_response(response)
11571161
return response
@@ -1364,10 +1368,7 @@ def prepare_deploy(
13641368
app_mode: AppMode,
13651369
app_store_version: typing.Optional[int],
13661370
) -> PrepareDeployOutputResult:
1367-
1368-
application_type = "static" if app_mode in [
1369-
AppModes.STATIC,
1370-
AppModes.STATIC_QUARTO] else "connect"
1371+
application_type = "static" if app_mode in [AppModes.STATIC, AppModes.STATIC_QUARTO] else "connect"
13711372
logger.debug(f"application_type: {application_type}")
13721373

13731374
render_by = "server" if app_mode == AppModes.STATIC_QUARTO else None
@@ -1385,11 +1386,13 @@ def prepare_deploy(
13851386
space_id = None
13861387

13871388
# create the new output and associate it with the current Posit Cloud project and space
1388-
output = self._rstudio_client.create_output(name=app_name,
1389-
application_type=application_type,
1390-
project_id=project_id,
1391-
space_id=space_id,
1392-
render_by=render_by)
1389+
output = self._rstudio_client.create_output(
1390+
name=app_name,
1391+
application_type=application_type,
1392+
project_id=project_id,
1393+
space_id=space_id,
1394+
render_by=render_by,
1395+
)
13931396
app_id_int = output["source_id"]
13941397
else:
13951398
# this is a redeployment of an existing output

rsconnect/main.py

Lines changed: 30 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def wrapper(*args, **kwargs):
243243

244244
return wrapper
245245

246+
246247
# This callback handles the "shorthand" --disable-env-management option.
247248
# If the shorthand flag is provided, then it takes precendence over the R and Python flags.
248249
# This callback also inverts the --disable-env-management-r and
@@ -252,7 +253,7 @@ def wrapper(*args, **kwargs):
252253
# which is more consistent when writing these values to the manifest.
253254
def env_management_callback(ctx, param, value) -> typing.Optional[bool]:
254255
# eval the shorthand flag if it was provided
255-
disable_env_management = ctx.params.get('disable_env_management')
256+
disable_env_management = ctx.params.get("disable_env_management")
256257
if disable_env_management is not None:
257258
value = disable_env_management
258259

@@ -486,7 +487,6 @@ def bootstrap(
486487
@cloud_shinyapps_args
487488
@click.pass_context
488489
def add(ctx, name, server, api_key, insecure, cacert, account, token, secret, verbose):
489-
490490
set_verbosity(verbose)
491491
if click.__version__ >= "8.0.0" and sys.version_info >= (3, 7):
492492
click.echo("Detected the following inputs:")
@@ -1081,11 +1081,11 @@ def deploy_manifest(
10811081
name="quarto",
10821082
short_help="Deploy Quarto content to Posit Connect [v2021.08.0+] or Posit Cloud.",
10831083
help=(
1084-
'Deploy a Quarto document or project to Posit Connect or Posit Cloud. Should the content use the Quarto '
1084+
"Deploy a Quarto document or project to Posit Connect or Posit Cloud. Should the content use the Quarto "
10851085
'Jupyter engine, an environment file ("requirements.txt") is created and included in the deployment if one '
1086-
'does not already exist. Requires Posit Connect 2021.08.0 or later.'
1087-
'\n\n'
1088-
'FILE_OR_DIRECTORY is the path to a single-file Quarto document or the directory containing a Quarto project.'
1086+
"does not already exist. Requires Posit Connect 2021.08.0 or later."
1087+
"\n\n"
1088+
"FILE_OR_DIRECTORY is the path to a single-file Quarto document or the directory containing a Quarto project."
10891089
),
10901090
no_args_is_help=True,
10911091
)
@@ -1439,51 +1439,31 @@ def deploy_help():
14391439
@deploy.command(
14401440
name="git",
14411441
short_help="Deploy git repository with exisiting manifest file",
1442-
help="Deploy git repository with exisiting manifest file"
1443-
)
1444-
@click.option("--name", "-n", help="The nickname of the RStudio Connect server to deploy to.")
1445-
@click.option(
1446-
"--server", "-s", envvar="CONNECT_SERVER", help="The URL for the RStudio Connect server to deploy to.",
1447-
)
1448-
@click.option(
1449-
"--api-key", "-k", envvar="CONNECT_API_KEY", help="The API key to use to authenticate with RStudio Connect.",
1450-
)
1451-
@click.option(
1452-
"--insecure", "-i", envvar="CONNECT_INSECURE", is_flag=True, help="Disable TLS certification/host validation.",
1442+
help="Deploy git repository with exisiting manifest file",
14531443
)
1454-
@click.option(
1455-
"--cacert",
1456-
"-c",
1457-
envvar="CONNECT_CA_CERTIFICATE",
1458-
type=click.File(),
1459-
help="The path to trusted TLS CA certificates.",
1460-
)
1461-
@click.option("--verbose", "-v", is_flag=True, help="Print detailed messages.")
1462-
@click.option('--app_name', '-a')
1463-
@click.option('--repository', "-r")
1464-
@click.option('--branch', "-b")
1465-
@click.option('--subdirectory', "-d")
1466-
def deploy_git(name, server, api_key, insecure, cacert, verbose, app_name, repository, branch, subdirectory):
1444+
@server_args
1445+
@click.option("--app_name", "-a")
1446+
@click.option("--repository", "-r", required=True)
1447+
@click.option("--branch", "-b", default="main")
1448+
@click.option("--subdirectory", "-d", default="/")
1449+
@cli_exception_handler
1450+
def deploy_git(
1451+
name: str,
1452+
server: str,
1453+
api_key: str,
1454+
insecure: bool,
1455+
cacert: typing.IO,
1456+
verbose,
1457+
app_name: str,
1458+
repository: str,
1459+
branch: str,
1460+
subdirectory: str,
1461+
):
1462+
subdirectory = subdirectory.strip("/")
1463+
kwargs = locals()
14671464
set_verbosity(verbose)
1468-
1469-
with cli_feedback("Checking arguments"):
1470-
connect_server = _validate_deploy_to_args(name, server, api_key, insecure, cacert)
1471-
1472-
connect_client = api.RSConnect(connect_server)
1473-
1474-
with cli_feedback("Deploying git repository"):
1475-
app = connect_client.deploy_git(app_name, repository, branch, subdirectory)
1476-
1477-
with cli_feedback(""):
1478-
click.secho("\nDeployment log:", fg="bright_white")
1479-
app_url, _ = spool_deployment_log(connect_server, app, click.echo)
1480-
click.secho("Deployment completed successfully.", fg="bright_white")
1481-
click.secho(" Dashboard content URL: %s" % app_url, fg="bright_white")
1482-
click.secho(" Direct content URL: %s" % app["app_url"], fg="bright_white")
1483-
1484-
1485-
click.secho("Git deployment completed successfully.", fg="bright_white")
1486-
click.secho("App available as %s" % app_name, fg="bright_white")
1465+
ce = RSConnectExecutor(**kwargs)
1466+
ce.validate_server().deploy_git().emit_task_log()
14871467

14881468

14891469
@cli.group(
@@ -1499,6 +1479,7 @@ def deploy_git(name, server, api_key, insecure, cacert, verbose, app_name, repos
14991479
def write_manifest():
15001480
pass
15011481

1482+
15021483
@write_manifest.command(
15031484
name="notebook",
15041485
short_help="Create a manifest.json file for a Jupyter notebook.",

0 commit comments

Comments
 (0)