@@ -222,6 +222,11 @@ def get_runs(
222
222
either the JSON response from the runs request or the results in the
223
223
form of a Pandas DataFrame
224
224
225
+ Yields
226
+ ------
227
+ tuple[str, Run]
228
+ identifier and Run object
229
+
225
230
Raises
226
231
------
227
232
ValueError
@@ -434,13 +439,19 @@ def delete_alert(self, alert_id: str) -> None:
434
439
435
440
@prettify_pydantic
436
441
@pydantic .validate_call
437
- def list_artifacts (self , run_id : str ) -> typing .Generator [Artifact , None , None ]:
442
+ def list_artifacts (
443
+ self , run_id : str , sort_by_columns : list [tuple [str , bool ]] | None = None
444
+ ) -> typing .Generator [Artifact , None , None ]:
438
445
"""Retrieve artifacts for a given run
439
446
440
447
Parameters
441
448
----------
442
449
run_id : str
443
450
unique identifier for the run
451
+ sort_by_columns : list[tuple[str, bool]], optional
452
+ sort by columns in the order given,
453
+ list of tuples in the form (column_name: str, sort_descending: bool),
454
+ default is None.
444
455
445
456
Yields
446
457
------
@@ -452,7 +463,12 @@ def list_artifacts(self, run_id: str) -> typing.Generator[Artifact, None, None]:
452
463
RuntimeError
453
464
if retrieval of artifacts failed when communicating with the server
454
465
"""
455
- return Artifact .get (runs = json .dumps ([run_id ])) # type: ignore
466
+ return Artifact .get (
467
+ runs = json .dumps ([run_id ]),
468
+ sorting = [dict (zip (("column" , "descending" ), a )) for a in sort_by_columns ]
469
+ if sort_by_columns
470
+ else None ,
471
+ ) # type: ignore
456
472
457
473
def _retrieve_artifacts_from_server (
458
474
self , run_id : str , name : str , count : int | None = None
@@ -582,7 +598,7 @@ def get_artifacts_as_files(
582
598
* input - this file is an input file.
583
599
* output - this file is created by the run.
584
600
* code - this file represents an executed script
585
- output_dir : str | None, optional
601
+ output_dir : str | None, optTODOional
586
602
location to download files to, the default of None will download
587
603
them to the current working directory
588
604
@@ -649,6 +665,7 @@ def get_folders(
649
665
filters : list [str ] | None = None ,
650
666
count : pydantic .PositiveInt = 100 ,
651
667
start_index : pydantic .NonNegativeInt = 0 ,
668
+ sort_by_columns : list [tuple [str , bool ]] | None = None ,
652
669
) -> typing .Generator [tuple [str , Folder ], None , None ]:
653
670
"""Retrieve folders from the server
654
671
@@ -660,6 +677,10 @@ def get_folders(
660
677
maximum number of entries to return. Default is 100.
661
678
start_index : int, optional
662
679
the index from which to count entries. Default is 0.
680
+ sort_by_columns : list[tuple[str, bool]], optional
681
+ sort by columns in the order given,
682
+ list of tuples in the form (column_name: str, sort_descending: bool),
683
+ default is None.
663
684
664
685
Returns
665
686
-------
@@ -672,7 +693,12 @@ def get_folders(
672
693
if there was a failure retrieving data from the server
673
694
"""
674
695
return Folder .get (
675
- filters = json .dumps (filters or []), count = count , offset = start_index
696
+ filters = json .dumps (filters or []),
697
+ count = count ,
698
+ offset = start_index ,
699
+ sorting = [dict (zip (("column" , "descending" ), a )) for a in sort_by_columns ]
700
+ if sort_by_columns
701
+ else None ,
676
702
) # type: ignore
677
703
678
704
@prettify_pydantic
@@ -981,6 +1007,7 @@ def get_alerts(
981
1007
names_only : bool = True ,
982
1008
start_index : pydantic .NonNegativeInt | None = None ,
983
1009
count_limit : pydantic .PositiveInt | None = None ,
1010
+ sort_by_columns : list [tuple [str , bool ]] | None = None ,
984
1011
) -> list [AlertBase ] | list [str | None ]:
985
1012
"""Retrieve alerts for a given run
986
1013
@@ -996,6 +1023,10 @@ def get_alerts(
996
1023
slice results returning only those above this index, by default None
997
1024
count_limit : typing.int, optional
998
1025
limit number of returned results, by default None
1026
+ sort_by_columns : list[tuple[str, bool]], optional
1027
+ sort by columns in the order given,
1028
+ list of tuples in the form (column_name: str, sort_descending: bool),
1029
+ default is None.
999
1030
1000
1031
Returns
1001
1032
-------
@@ -1012,7 +1043,22 @@ def get_alerts(
1012
1043
raise RuntimeError (
1013
1044
"critical_only is ambiguous when returning alerts with no run ID specified."
1014
1045
)
1015
- return [alert .name if names_only else alert for _ , alert in Alert .get ()] # type: ignore
1046
+ return [
1047
+ alert .name if names_only else alert
1048
+ for _ , alert in Alert .get (
1049
+ sorting = [
1050
+ dict (zip (("column" , "descending" ), a )) for a in sort_by_columns
1051
+ ]
1052
+ if sort_by_columns
1053
+ else None ,
1054
+ )
1055
+ ] # type: ignore
1056
+
1057
+ if sort_by_columns :
1058
+ logger .warning (
1059
+ "Run identifier specified for alert retrieval,"
1060
+ " argument 'sort_by_columns' will be ignored"
1061
+ )
1016
1062
1017
1063
_alerts = [
1018
1064
Alert (identifier = alert .get ("id" ), ** alert )
@@ -1032,6 +1078,7 @@ def get_tags(
1032
1078
* ,
1033
1079
start_index : pydantic .NonNegativeInt | None = None ,
1034
1080
count_limit : pydantic .PositiveInt | None = None ,
1081
+ sort_by_columns : list [tuple [str , bool ]] | None = None ,
1035
1082
) -> typing .Generator [Tag , None , None ]:
1036
1083
"""Retrieve tags
1037
1084
@@ -1041,18 +1088,29 @@ def get_tags(
1041
1088
slice results returning only those above this index, by default None
1042
1089
count_limit : typing.int, optional
1043
1090
limit number of returned results, by default None
1091
+ sort_by_columns : list[tuple[str, bool]], optional
1092
+ sort by columns in the order given,
1093
+ list of tuples in the form (column_name: str, sort_descending: bool),
1094
+ default is None.
1044
1095
1045
1096
Returns
1046
1097
-------
1047
- list[Tag]
1048
- a list of all tags for this run
1098
+ yields
1099
+ tag identifier
1100
+ tag object
1049
1101
1050
1102
Raises
1051
1103
------
1052
1104
RuntimeError
1053
1105
if there was a failure retrieving data from the server
1054
1106
"""
1055
- return Tag .get (count = count_limit , offset = start_index )
1107
+ return Tag .get (
1108
+ count = count_limit ,
1109
+ offset = start_index ,
1110
+ sorting = [dict (zip (("column" , "descending" ), a )) for a in sort_by_columns ]
1111
+ if sort_by_columns
1112
+ else None ,
1113
+ )
1056
1114
1057
1115
@prettify_pydantic
1058
1116
@pydantic .validate_call
0 commit comments