Skip to content

Commit f476183

Browse files
committed
send content_category to cloud through API
1 parent fde088d commit f476183

File tree

5 files changed

+283
-237
lines changed

5 files changed

+283
-237
lines changed

rsconnect/actions.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ def write_quarto_manifest_json(
546546
"""
547547
warn("This method has been moved and will be deprecated.", DeprecationWarning, stacklevel=2)
548548

549-
manifest, _ = make_quarto_manifest(
549+
quarto_manifest_info = make_quarto_manifest(
550550
file_or_directory,
551551
inspect,
552552
app_mode,
@@ -562,7 +562,7 @@ def write_quarto_manifest_json(
562562
if not isdir(file_or_directory):
563563
base_dir = dirname(file_or_directory)
564564
manifest_path = join(base_dir, "manifest.json")
565-
write_manifest_json(manifest_path, manifest)
565+
write_manifest_json(manifest_path, quarto_manifest_info.manifest.data)
566566

567567

568568
def write_manifest_json(manifest_path, manifest):
@@ -1236,7 +1236,7 @@ def create_notebook_deployment_bundle(
12361236
image=image,
12371237
env_management_py=env_management_py,
12381238
env_management_r=env_management_r,
1239-
)
1239+
).bundle
12401240
except subprocess.CalledProcessError as exc:
12411241
# Jupyter rendering failures are often due to
12421242
# user code failing, vs. an internal failure of rsconnect-python.
@@ -1251,7 +1251,7 @@ def create_notebook_deployment_bundle(
12511251
image=image,
12521252
env_management_py=env_management_py,
12531253
env_management_r=env_management_r,
1254-
)
1254+
).bundle
12551255

12561256

12571257
def create_api_deployment_bundle(
@@ -1296,7 +1296,7 @@ def create_api_deployment_bundle(
12961296

12971297
return make_api_bundle(
12981298
directory, entry_point, app_mode, environment, extra_files, excludes, image, env_management_py, env_management_r
1299-
)
1299+
).bundle
13001300

13011301

13021302
def create_quarto_deployment_bundle(
@@ -1343,7 +1343,7 @@ def create_quarto_deployment_bundle(
13431343
image,
13441344
env_management_py,
13451345
env_management_r,
1346-
)
1346+
).bundle
13471347

13481348

13491349
def deploy_bundle(
@@ -1621,7 +1621,7 @@ def write_api_manifest_json(
16211621
)
16221622
manifest_path = join(directory, "manifest.json")
16231623

1624-
write_manifest_json(manifest_path, manifest)
1624+
write_manifest_json(manifest_path, manifest.data)
16251625

16261626
return exists(join(directory, environment.filename))
16271627

rsconnect/api.py

+33-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
22
Posit Connect API client and utility functions
33
"""
4+
from __future__ import annotations
5+
46
import binascii
57
import os
68
from os.path import abspath
@@ -30,6 +32,10 @@
3032
from .bundle import _default_title, fake_module_file_from_directory
3133
from .timeouts import get_task_timeout, get_task_timeout_help_message
3234

35+
if typing.TYPE_CHECKING:
36+
from .bundle import ManifestBundle
37+
from .bundle import Manifest
38+
3339

3440
class AbstractRemoteServer:
3541
def __init__(self, url: str, remote_name: str):
@@ -626,7 +632,7 @@ def validate_rstudio_server(
626632
raise RSConnectException("Failed to verify with {} ({}).".format(server.remote_name, exc))
627633

628634
@cls_logged("Making bundle ...")
629-
def make_bundle(self, func: Callable, *args, **kwargs):
635+
def make_bundle(self, func: Callable[..., ManifestBundle], *args, **kwargs):
630636
path = (
631637
self.get("path", **kwargs)
632638
or self.get("file", **kwargs)
@@ -656,7 +662,8 @@ def make_bundle(self, func: Callable, *args, **kwargs):
656662
)
657663
raise RSConnectException(msg)
658664

659-
d["bundle"] = bundle
665+
d["bundle"] = bundle.bundle
666+
d["manifest"] = bundle.manifest
660667

661668
return self
662669

@@ -680,6 +687,7 @@ def deploy_bundle(
680687
title: str = None,
681688
title_is_default: bool = False,
682689
bundle: IO = None,
690+
manifest: Manifest = None,
683691
env_vars=None,
684692
app_mode=None,
685693
visibility=None,
@@ -689,6 +697,7 @@ def deploy_bundle(
689697
title = title or self.get("title")
690698
title_is_default = title_is_default or self.get("title_is_default")
691699
bundle = bundle or self.get("bundle")
700+
manifest = manifest or self.get("manifest")
692701
env_vars = env_vars or self.get("env_vars")
693702
app_mode = app_mode or self.get("app_mode")
694703
visibility = visibility or self.get("visibility")
@@ -725,7 +734,7 @@ def deploy_bundle(
725734
cloud_service = CloudService(self.client, self.remote_server, os.getenv("LUCID_APPLICATION_ID"))
726735
app_store_version = self.get("app_store_version")
727736
prepare_deploy_result = cloud_service.prepare_deploy(
728-
app_id, deployment_name, bundle_size, bundle_hash, app_mode, app_store_version
737+
app_id, deployment_name, bundle_size, bundle_hash, app_mode, manifest, app_store_version
729738
)
730739
self.upload_rstudio_bundle(prepare_deploy_result, bundle_size, contents)
731740
cloud_service.do_deploy(prepare_deploy_result.bundle_id, prepare_deploy_result.application_id)
@@ -1120,16 +1129,29 @@ def create_application(self, account_id, application_name):
11201129
self._server.handle_bad_response(response)
11211130
return response
11221131

1123-
def create_output(self, name: str, application_type: str, project_id=None, space_id=None, render_by=None):
1132+
def create_output(
1133+
self,
1134+
name: str,
1135+
application_type: str,
1136+
project_id: typing.Optional[int],
1137+
space_id: typing.Optional[int],
1138+
render_by: typing.Optional[str],
1139+
content_category: typing.Optional[str],
1140+
):
11241141
data = {"name": name, "space": space_id, "project": project_id, "application_type": application_type}
11251142
if render_by:
11261143
data["render_by"] = render_by
1144+
if content_category:
1145+
data["content_category"] = content_category
11271146
response = self.post("/v1/outputs/", body=data)
11281147
self._server.handle_bad_response(response)
11291148
return response
11301149

1131-
def create_revision(self, content_id):
1132-
response = self.post("/v1/outputs/{}/revisions".format(content_id), body={})
1150+
def create_revision(self, content_id: int, content_category: typing.Optional[str]):
1151+
body = {}
1152+
if content_category:
1153+
body["content_category"] = content_category
1154+
response = self.post("/v1/outputs/{}/revisions".format(content_id), body=body)
11331155
self._server.handle_bad_response(response)
11341156
return response
11351157

@@ -1334,6 +1356,7 @@ def prepare_deploy(
13341356
bundle_size: int,
13351357
bundle_hash: str,
13361358
app_mode: AppMode,
1359+
manifest: Manifest,
13371360
app_store_version: typing.Optional[int],
13381361
) -> PrepareDeployOutputResult:
13391362

@@ -1345,6 +1368,8 @@ def prepare_deploy(
13451368

13461369
project_id = self._get_current_project_id()
13471370

1371+
content_category = manifest.data["metadata"].get("content_category")
1372+
13481373
if app_id is None:
13491374
# this is a deployment of a new output
13501375
if project_id is not None:
@@ -1361,6 +1386,7 @@ def prepare_deploy(
13611386
project_id=project_id,
13621387
space_id=space_id,
13631388
render_by=render_by,
1389+
content_category=content_category,
13641390
)
13651391
app_id_int = output["source_id"]
13661392
else:
@@ -1379,7 +1405,7 @@ def prepare_deploy(
13791405
output = self._rstudio_client.get_content(content_id)
13801406

13811407
if application_type == "static":
1382-
revision = self._rstudio_client.create_revision(content_id)
1408+
revision = self._rstudio_client.create_revision(content_id, content_category)
13831409
app_id_int = revision["application_id"]
13841410

13851411
# associate the output with the current Posit Cloud project (if any)

0 commit comments

Comments
 (0)