11"""
22Posit Connect API client and utility functions
33"""
4+ from __future__ import annotations
5+
46import binascii
57import os
68from os .path import abspath
3032from .bundle import _default_title , fake_module_file_from_directory
3133from .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
3440class 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