@@ -218,27 +218,29 @@ def should_parallelize_transfer(
218218 if size is not None and isinstance (open_options , dict ):
219219 open_options [kw .DATA_SIZE_KW ] = size
220220
221- def _download (self , obj , local_path , num_threads , updatables = (), ** options ):
221+ def _download (self , obj_path , local_path , num_threads , updatables = (), ** options ):
222222 """Transfer the contents of a data object to a local file.
223223
224224 Called from get() when a local path is named.
225225 """
226- if os .path .isdir (local_path ):
227- local_file = os .path .join (local_path , irods_basename (obj ))
228- else :
229- local_file = local_path
226+
227+ local_file = (
228+ os .path .join (local_path , irods_basename (obj_path )) # noqa: PTH118
229+ if os .path .isdir (local_path ) # noqa: PTH112
230+ else local_path
231+ )
230232
231233 # Check for force flag if local_file exists
232234 if os .path .exists (local_file ) and kw .FORCE_FLAG_KW not in options :
233235 raise ex .OVERWRITE_WITHOUT_FORCE_FLAG
234236
235237 data_open_returned_values_ = {}
236- with self .open (obj , "r" , returned_values = data_open_returned_values_ , ** options ) as o :
238+ with self .open (obj_path , "r" , returned_values = data_open_returned_values_ , ** options ) as o :
237239 if self .should_parallelize_transfer (num_threads , o , open_options = options .items ()):
238240 error = RuntimeError ("parallel get failed" )
239241 try :
240242 if not self .parallel_get (
241- (obj , o ),
243+ (obj_path , o ),
242244 local_file ,
243245 num_threads = num_threads ,
244246 target_resource_name = options .get (kw .RESC_NAME_KW , "" ),
@@ -265,6 +267,8 @@ def get(self, path, local_path=None, num_threads=DEFAULT_NUMBER_OF_THREADS, upda
265267 """
266268 parent = self .sess .collections .get (irods_dirname (path ))
267269
270+ replica_sort_function = options .pop ('replica_sort_function' , None )
271+
268272 # TODO: optimize
269273 if local_path :
270274 self ._download (path , local_path , num_threads = num_threads , updatables = updatables , ** options )
@@ -284,7 +288,7 @@ def get(self, path, local_path=None, num_threads=DEFAULT_NUMBER_OF_THREADS, upda
284288 results = query .all () # get up to max_rows replicas
285289 if len (results ) <= 0 :
286290 raise ex .DataObjectDoesNotExist ()
287- return iRODSDataObject (self , parent , results )
291+ return iRODSDataObject (self , parent , results , replica_sort_function = replica_sort_function )
288292
289293 @staticmethod
290294 def _resolve_force_put_option (options , default_setting = None , true_value = "" ):
@@ -317,23 +321,25 @@ def put(
317321 self ._resolve_force_put_option (options , default_setting = client_config .data_objects .force_put_by_default )
318322
319323 if self .sess .collections .exists (irods_path ):
320- obj = iRODSCollection .normalize_path (irods_path , os .path .basename (local_path ))
324+ obj_path = iRODSCollection .normalize_path (irods_path , os .path .basename (local_path )) # noqa: PTH119
321325 else :
322- obj = irods_path
323- if kw .FORCE_FLAG_KW not in options and self .exists (obj ):
326+ obj_path = irods_path
327+ if kw .FORCE_FLAG_KW not in options and self .exists (obj_path ):
324328 raise ex .OVERWRITE_WITHOUT_FORCE_FLAG
325329 options .pop (kw .FORCE_FLAG_KW , None )
326330
331+ replica_sort_function = options .pop ('replica_sort_function' , None )
332+
327333 with open (local_path , "rb" ) as f :
328334 sizelist = []
329335 if self .should_parallelize_transfer (num_threads , f , measured_obj_size = sizelist , open_options = options ):
330- o = deferred_call (self .open , (obj , "w" ), options )
336+ o = deferred_call (self .open , (obj_path , "w" ), options )
331337 f .close ()
332338 error = RuntimeError ("parallel put failed" )
333339 try :
334340 if not self .parallel_put (
335341 local_path ,
336- (obj , o ),
342+ (obj_path , o ),
337343 total_bytes = sizelist [0 ],
338344 num_threads = num_threads ,
339345 target_resource_name = options .get (kw .RESC_NAME_KW , "" ) or options .get (kw .DEST_RESC_NAME_KW , "" ),
@@ -346,7 +352,7 @@ def put(
346352 except BaseException as e :
347353 raise error from e
348354 else :
349- with self .open (obj , "w" , ** options ) as o :
355+ with self .open (obj_path , "w" , ** options ) as o :
350356 # Set operation type to trigger acPostProcForPut
351357 if kw .OPR_TYPE_KW not in options :
352358 options [kw .OPR_TYPE_KW ] = 1 # PUT_OPR
@@ -360,10 +366,11 @@ def put(
360366 # Requested to register checksum without verifying, but source replica has a checksum. This can result
361367 # in multiple replicas being marked good with different checksums, which is an inconsistency.
362368 del repl_options [kw .REG_CHKSUM_KW ]
363- self .replicate (obj , ** repl_options )
369+ self .replicate (obj_path , ** repl_options )
364370
365371 if return_data_object :
366- return self .get (obj )
372+ return self .get (obj_path , replica_sort_function = replica_sort_function )
373+ return None
367374
368375 def chksum (self , path , ** options ):
369376 """
@@ -480,6 +487,7 @@ def create(
480487 raise ex .DataObjectExistsAtLogicalPath
481488
482489 options = {** options , kw .DATA_TYPE_KW : "generic" }
490+ replica_sort_function = options .pop ('replica_sort_function' , None )
483491
484492 if resource :
485493 options [kw .DEST_RESC_NAME_KW ] = resource
@@ -508,7 +516,7 @@ def create(
508516 desc = response .int_info
509517 conn .close_file (desc )
510518
511- return self .get (path )
519+ return self .get (path , replica_sort_function = replica_sort_function )
512520
513521 def open_with_FileRaw (self , * arg , ** kw_options ):
514522 holder = []
0 commit comments