@@ -245,18 +245,29 @@ def pin_write(
245245 A date to store in the Meta.created field. This field may be used as
246246 part of the pin version name.
247247 """
248+
249+ pin_name = self .path_to_pin (name )
250+
248251 # TODO(docs): describe options for type argument
249252 # TODO(docs): elaborate on default behavior for versioned parameter
250253 # TODO(compat): python pins added a created parameter above
251254 with tempfile .TemporaryDirectory () as tmp_dir :
252255 # create all pin data (e.g. data.txt, save object)
253256 meta = self .prepare_pin_version (
254- tmp_dir , x , name , type , title , description , metadata , versioned , created
257+ tmp_dir ,
258+ x ,
259+ pin_name ,
260+ type ,
261+ title ,
262+ description ,
263+ metadata ,
264+ versioned ,
265+ created ,
255266 )
256267
257268 # move pin to destination ----
258269 # create pin version folder
259- dst_pin_path = self .construct_path ([self . path_to_pin ( name ) ])
270+ dst_pin_path = self .construct_path ([pin_name ])
260271 dst_version_path = self .path_to_deploy_version (name , meta .version .version )
261272
262273 try :
@@ -490,7 +501,7 @@ def keep_final_path_component(self, path):
490501
491502 def sort_pin_versions (self , versions ):
492503 # assume filesystem returned them with most recent last
493- return versions
504+ return sorted ( versions , key = lambda v : v . version )
494505
495506 def prepare_pin_version (
496507 self ,
@@ -523,10 +534,11 @@ def prepare_pin_version(
523534 p_obj = Path (pin_dir_path ) / name
524535
525536 # file is saved locally in order to hash, calc size
526- save_data (x , str (p_obj ), type )
537+ file_names = save_data (x , str (p_obj ), type )
527538
528539 meta = self .meta_factory .create (
529- str (p_obj ),
540+ pin_dir_path ,
541+ file_names ,
530542 type ,
531543 title = title ,
532544 description = description ,
@@ -556,8 +568,8 @@ class BoardManual(BaseBoard):
556568 Examples
557569 --------
558570 >>> import fsspec
571+ >>> import os
559572 >>> fs = fsspec.filesystem("github", org = "machow", repo = "pins-python")
560-
561573 >>> pin_paths = {"df_csv": "df_csv/20220214T163720Z-9bfad"}
562574 >>> board = BoardManual("pins/tests/pins-compat", fs, pin_paths=pin_paths)
563575
@@ -650,6 +662,31 @@ def pin_list(self):
650662 names = [f"{ cont ['owner_username' ]} /{ cont ['name' ]} " for cont in results ]
651663 return names
652664
665+ def pin_write (self , * args , ** kwargs ):
666+
667+ # run parent function ---
668+
669+ f_super = super ().pin_write
670+ meta = f_super (* args , ** kwargs )
671+
672+ # update content title to reflect what's in metadata ----
673+
674+ # TODO(question): R pins updates this info before writing the pin..?
675+ # bind the original signature to get pin name
676+ sig = inspect .signature (f_super )
677+ bind = sig .bind (* args , ** kwargs )
678+
679+ pin_name = self .path_to_pin (bind .arguments ["name" ])
680+ content = self .fs .info (pin_name )
681+ self .fs .api .patch_content_item (
682+ content ["guid" ],
683+ title = meta .title ,
684+ description = meta .description or "" ,
685+ # access_type = content.access_type
686+ )
687+
688+ return meta
689+
653690 def pin_search (self , search = None , as_df = True ):
654691 from pins .rsconnect .api import RsConnectApiRequestError
655692
@@ -742,10 +779,12 @@ def prepare_pin_version(self, pin_dir_path, x, name: "str | None", *args, **kwar
742779 # RSC pin names can have form <user_name>/<name>, but this will try to
743780 # create the object in a directory named <user_name>. So we grab just
744781 # the <name> part.
745- if "/" in name :
746- name = name .split ("/" )[- 1 ]
782+ short_name = name .split ("/" )[- 1 ]
747783
748- meta = super ().prepare_pin_version (pin_dir_path , x , name , * args , ** kwargs )
784+ # TODO(compat): py pins always uses the short name, R pins uses w/e the
785+ # user passed, but guessing people want the long name?
786+ meta = super ().prepare_pin_version (pin_dir_path , x , short_name , * args , ** kwargs )
787+ meta .name = name
749788
750789 # copy in files needed by index.html ----------------------------------
751790 crnt_files = set ([meta .file ] if isinstance (meta .file , str ) else meta .file )
@@ -765,7 +804,8 @@ def prepare_pin_version(self, pin_dir_path, x, name: "str | None", *args, **kwar
765804 pin_files = ", " .join (f"""<a href="{ x } ">{ x } </a>""" for x in all_files )
766805
767806 context = {
768- "pin_name" : "TODO" ,
807+ "date" : meta .version .created .replace (microsecond = 0 ),
808+ "pin_name" : self .path_to_pin (name ),
769809 "pin_files" : pin_files ,
770810 "pin_metadata" : meta ,
771811 }
0 commit comments