@@ -495,9 +495,7 @@ def print_user_message(
495
495
)
496
496
497
497
if is_documentation_mode () and is_notebook ():
498
-
499
498
if display_type .lower () == "tip" :
500
-
501
499
if "\n " in msg :
502
500
t = "<b>{}:</b>" .format (title .upper ().strip ()) if title else ""
503
501
@@ -567,7 +565,6 @@ def print_user_message(
567
565
)
568
566
569
567
elif display_type .startswith ("info" ):
570
-
571
568
user_message = msg .strip ().replace ("\n " , "<br>" )
572
569
573
570
if see_also_links :
@@ -640,7 +637,6 @@ def ellipsis_strings(raw, n=24):
640
637
641
638
result = []
642
639
for s in sequence :
643
-
644
640
if len (str (s )) <= n :
645
641
result .append (s )
646
642
else :
@@ -1136,36 +1132,44 @@ def is_data_too_wide(
1136
1132
return col_num > max_col_num
1137
1133
1138
1134
1139
- def get_files (directory : str ):
1135
+ def get_files (directory : str , auth : Optional [ Dict ] = None ):
1140
1136
"""List out all the file names under this directory.
1141
1137
1142
1138
Parameters
1143
1139
----------
1144
1140
directory: str
1145
1141
The directory to list out all the files from.
1142
+ auth: (Dict, optional). Defaults to None.
1143
+ The default authentication is set using `ads.set_auth` API. If you need to override the
1144
+ default, use the `ads.common.auth.api_keys` or `ads.common.auth.resource_principal` to create appropriate
1145
+ authentication signer and kwargs required to instantiate IdentityClient object.
1146
1146
1147
1147
Returns
1148
1148
-------
1149
1149
List
1150
1150
List of the files in the directory.
1151
1151
"""
1152
1152
directory = directory .rstrip ("/" )
1153
- if os .path .exists (os .path .join (directory , ".model-ignore" )):
1154
- ignore_patterns = (
1155
- Path (os .path .join (directory ), ".model-ignore" )
1156
- .read_text ()
1157
- .strip ()
1158
- .split ("\n " )
1159
- )
1153
+ path_scheme = urlparse (directory ).scheme or "file"
1154
+ storage_options = auth or authutil .default_signer ()
1155
+ model_ignore_path = os .path .join (directory , ".model-ignore" )
1156
+ if is_path_exists (model_ignore_path , auth = auth ):
1157
+ with fsspec .open (model_ignore_path , "r" , ** storage_options ) as f :
1158
+ ignore_patterns = f .read ().strip ().split ("\n " )
1160
1159
else :
1161
1160
ignore_patterns = []
1162
1161
file_names = []
1163
- for root , dirs , files in os .walk (directory ):
1162
+ fs = fsspec .filesystem (path_scheme , ** storage_options )
1163
+ for root , dirs , files in fs .walk (directory ):
1164
1164
for name in files :
1165
1165
file_names .append (os .path .join (root , name ))
1166
1166
for name in dirs :
1167
1167
file_names .append (os .path .join (root , name ))
1168
1168
1169
+ # return all files in remote directory.
1170
+ if directory .startswith ("oci://" ):
1171
+ directory = directory .lstrip ("oci://" )
1172
+
1169
1173
for ignore in ignore_patterns :
1170
1174
if not ignore .startswith ("#" ) and ignore .strip () != "" :
1171
1175
matches = []
@@ -1228,7 +1232,7 @@ def copy_from_uri(
1228
1232
force_overwrite: (bool, optional). Defaults to False.
1229
1233
Whether to overwrite existing files or not.
1230
1234
auth: (Dict, optional). Defaults to None.
1231
- The default authetication is set using `ads.set_auth` API. If you need to override the
1235
+ The default authentication is set using `ads.set_auth` API. If you need to override the
1232
1236
default, use the `ads.common.auth.api_keys` or `ads.common.auth.resource_principal` to create appropriate
1233
1237
authentication signer and kwargs required to instantiate IdentityClient object.
1234
1238
@@ -1294,7 +1298,7 @@ def copy_file(
1294
1298
force_overwrite: (bool, optional). Defaults to False.
1295
1299
Whether to overwrite existing files or not.
1296
1300
auth: (Dict, optional). Defaults to None.
1297
- The default authetication is set using `ads.set_auth` API. If you need to override the
1301
+ The default authentication is set using `ads.set_auth` API. If you need to override the
1298
1302
default, use the `ads.common.auth.api_keys` or `ads.common.auth.resource_principal` to create appropriate
1299
1303
authentication signer and kwargs required to instantiate IdentityClient object.
1300
1304
chunk_size: (int, optinal). Defaults to `DEFAULT_BUFFER_SIZE`
@@ -1357,7 +1361,7 @@ def remove_file(file_path: str, auth: Optional[Dict] = None) -> None:
1357
1361
file_path: str
1358
1362
The path of the source file, which can be local path or OCI object storage URI.
1359
1363
auth: (Dict, optional). Defaults to None.
1360
- The default authetication is set using `ads.set_auth` API. If you need to override the
1364
+ The default authentication is set using `ads.set_auth` API. If you need to override the
1361
1365
default, use the `ads.common.auth.api_keys` or `ads.common.auth.resource_principal` to create appropriate
1362
1366
authentication signer and kwargs required to instantiate IdentityClient object.
1363
1367
@@ -1570,3 +1574,26 @@ def extract_region(auth: Optional[Dict] = None) -> Union[str, None]:
1570
1574
pass
1571
1575
1572
1576
return None
1577
+
1578
+
1579
+ def is_path_exists (uri : str , auth : Optional [Dict ] = None ) -> bool :
1580
+ """Check if the given path which can be local path or OCI object storage URI exists.
1581
+
1582
+ Parameters
1583
+ ----------
1584
+ uri: str
1585
+ The URI of the target, which can be local path or OCI object storage URI.
1586
+ auth: (Dict, optional). Defaults to None.
1587
+ The default authentication is set using `ads.set_auth` API. If you need to override the
1588
+ default, use the `ads.common.auth.api_keys` or `ads.common.auth.resource_principal` to create appropriate
1589
+ authentication signer and kwargs required to instantiate IdentityClient object.
1590
+
1591
+ Returns
1592
+ -------
1593
+ bool: return True if the path exists.
1594
+ """
1595
+ path_scheme = urlparse (uri ).scheme or "file"
1596
+ storage_options = auth or authutil .default_signer ()
1597
+ if fsspec .filesystem (path_scheme , ** storage_options ).exists (uri ):
1598
+ return True
1599
+ return False
0 commit comments