1
1
"""
2
2
Posit Connect API client and utility functions
3
3
"""
4
+ from __future__ import annotations
5
+
4
6
import binascii
5
7
import os
6
8
from os .path import abspath
30
32
from .bundle import _default_title , fake_module_file_from_directory
31
33
from .timeouts import get_task_timeout , get_task_timeout_help_message
32
34
35
+ if typing .TYPE_CHECKING :
36
+ from .bundle import ManifestBundle
37
+ from .bundle import Manifest
38
+
33
39
34
40
class AbstractRemoteServer :
35
41
def __init__ (self , url : str , remote_name : str ):
@@ -626,7 +632,7 @@ def validate_rstudio_server(
626
632
raise RSConnectException ("Failed to verify with {} ({})." .format (server .remote_name , exc ))
627
633
628
634
@cls_logged ("Making bundle ..." )
629
- def make_bundle (self , func : Callable , * args , ** kwargs ):
635
+ def make_bundle (self , func : Callable [..., ManifestBundle ] , * args , ** kwargs ):
630
636
path = (
631
637
self .get ("path" , ** kwargs )
632
638
or self .get ("file" , ** kwargs )
@@ -656,7 +662,8 @@ def make_bundle(self, func: Callable, *args, **kwargs):
656
662
)
657
663
raise RSConnectException (msg )
658
664
659
- d ["bundle" ] = bundle
665
+ d ["bundle" ] = bundle .bundle
666
+ d ["manifest" ] = bundle .manifest
660
667
661
668
return self
662
669
@@ -680,6 +687,7 @@ def deploy_bundle(
680
687
title : str = None ,
681
688
title_is_default : bool = False ,
682
689
bundle : IO = None ,
690
+ manifest : Manifest = None ,
683
691
env_vars = None ,
684
692
app_mode = None ,
685
693
visibility = None ,
@@ -689,6 +697,7 @@ def deploy_bundle(
689
697
title = title or self .get ("title" )
690
698
title_is_default = title_is_default or self .get ("title_is_default" )
691
699
bundle = bundle or self .get ("bundle" )
700
+ manifest = manifest or self .get ("manifest" )
692
701
env_vars = env_vars or self .get ("env_vars" )
693
702
app_mode = app_mode or self .get ("app_mode" )
694
703
visibility = visibility or self .get ("visibility" )
@@ -725,7 +734,7 @@ def deploy_bundle(
725
734
cloud_service = CloudService (self .client , self .remote_server , os .getenv ("LUCID_APPLICATION_ID" ))
726
735
app_store_version = self .get ("app_store_version" )
727
736
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
729
738
)
730
739
self .upload_rstudio_bundle (prepare_deploy_result , bundle_size , contents )
731
740
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):
1120
1129
self ._server .handle_bad_response (response )
1121
1130
return response
1122
1131
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
+ ):
1124
1141
data = {"name" : name , "space" : space_id , "project" : project_id , "application_type" : application_type }
1125
1142
if render_by :
1126
1143
data ["render_by" ] = render_by
1144
+ if content_category :
1145
+ data ["content_category" ] = content_category
1127
1146
response = self .post ("/v1/outputs/" , body = data )
1128
1147
self ._server .handle_bad_response (response )
1129
1148
return response
1130
1149
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 )
1133
1155
self ._server .handle_bad_response (response )
1134
1156
return response
1135
1157
@@ -1334,6 +1356,7 @@ def prepare_deploy(
1334
1356
bundle_size : int ,
1335
1357
bundle_hash : str ,
1336
1358
app_mode : AppMode ,
1359
+ manifest : Manifest ,
1337
1360
app_store_version : typing .Optional [int ],
1338
1361
) -> PrepareDeployOutputResult :
1339
1362
@@ -1345,6 +1368,8 @@ def prepare_deploy(
1345
1368
1346
1369
project_id = self ._get_current_project_id ()
1347
1370
1371
+ content_category = manifest .data ["metadata" ].get ("content_category" )
1372
+
1348
1373
if app_id is None :
1349
1374
# this is a deployment of a new output
1350
1375
if project_id is not None :
@@ -1361,6 +1386,7 @@ def prepare_deploy(
1361
1386
project_id = project_id ,
1362
1387
space_id = space_id ,
1363
1388
render_by = render_by ,
1389
+ content_category = content_category ,
1364
1390
)
1365
1391
app_id_int = output ["source_id" ]
1366
1392
else :
@@ -1379,7 +1405,7 @@ def prepare_deploy(
1379
1405
output = self ._rstudio_client .get_content (content_id )
1380
1406
1381
1407
if application_type == "static" :
1382
- revision = self ._rstudio_client .create_revision (content_id )
1408
+ revision = self ._rstudio_client .create_revision (content_id , content_category )
1383
1409
app_id_int = revision ["application_id" ]
1384
1410
1385
1411
# associate the output with the current Posit Cloud project (if any)
0 commit comments