52
52
if typing .TYPE_CHECKING :
53
53
from .factory .proxy import SimvueBaseClass
54
54
from .factory .dispatch import DispatcherBaseClass
55
- from .types import DeserializedContent
56
55
57
56
UPLOAD_TIMEOUT : int = 30
58
57
HEARTBEAT_INTERVAL : int = 60
@@ -990,7 +989,24 @@ def save_object(
990
989
name : typing .Optional [str ] = None ,
991
990
allow_pickle : bool = False ,
992
991
) -> bool :
993
- obj : DeserializedContent
992
+ """Save an object to the Simvue server
993
+
994
+ Parameters
995
+ ----------
996
+ obj : typing.Any
997
+ object to serialize and send to the server
998
+ category : Literal['input', 'output', 'code']
999
+ category of file with respect to this run
1000
+ name : str, optional
1001
+ name to associate with this object, by default None
1002
+ allow_pickle : bool, optional
1003
+ whether to allow pickling if all other serialization types fail, by default False
1004
+
1005
+ Returns
1006
+ -------
1007
+ bool
1008
+ whether object upload was successful
1009
+ """
994
1010
serialized = serialize_object (obj , allow_pickle )
995
1011
996
1012
if not serialized or not (pickled := serialized [0 ]):
@@ -1022,7 +1038,7 @@ def save_object(
1022
1038
@pydantic .validate_call
1023
1039
def save_file (
1024
1040
self ,
1025
- filename : pydantic .FilePath ,
1041
+ file_path : pydantic .FilePath ,
1026
1042
category : typing .Literal ["input" , "output" , "code" ],
1027
1043
filetype : typing .Optional [str ] = None ,
1028
1044
preserve_path : bool = False ,
@@ -1032,7 +1048,7 @@ def save_file(
1032
1048
1033
1049
Parameters
1034
1050
----------
1035
- filename : pydantic.FilePath
1051
+ file_path : pydantic.FilePath
1036
1052
path to the file to upload
1037
1053
category : Literal['input', 'output', 'code']
1038
1054
category of file with respect to this run
@@ -1067,28 +1083,28 @@ def save_file(
1067
1083
self ._error (f"Invalid MIME type '{ filetype } ' specified" )
1068
1084
return False
1069
1085
1070
- stored_file_name : str = f"{ filename } "
1086
+ stored_file_name : str = f"{ file_path } "
1071
1087
1072
1088
if preserve_path and stored_file_name .startswith ("./" ):
1073
1089
stored_file_name = stored_file_name [2 :]
1074
1090
elif not preserve_path :
1075
- stored_file_name = os .path .basename (filename )
1091
+ stored_file_name = os .path .basename (file_path )
1076
1092
1077
1093
# Determine mimetype
1078
1094
if not (mimetype := filetype ):
1079
- mimetype = mimetypes .guess_type (filename )[0 ] or "application/octet-stream"
1095
+ mimetype = mimetypes .guess_type (file_path )[0 ] or "application/octet-stream"
1080
1096
1081
1097
data : dict [str , typing .Any ] = {
1082
1098
"name" : name or stored_file_name ,
1083
1099
"run" : self ._name ,
1084
1100
"type" : mimetype ,
1085
1101
"storage" : self ._storage_id ,
1086
1102
"category" : category ,
1087
- "size" : (file_size := os .path .getsize (filename )),
1103
+ "size" : (file_size := os .path .getsize (file_path )),
1088
1104
"originalPath" : os .path .abspath (
1089
- os .path .expanduser (os .path .expandvars (filename ))
1105
+ os .path .expanduser (os .path .expandvars (file_path ))
1090
1106
),
1091
- "checksum" : calculate_sha256 (f"{ filename } " , True ),
1107
+ "checksum" : calculate_sha256 (f"{ file_path } " , True ),
1092
1108
}
1093
1109
1094
1110
if not file_size :
0 commit comments