@@ -175,8 +175,8 @@ impl ParsedHFUrl {
175
175
/// Parse a http style HuggingFace URL into a ParsedHFUrl struct.
176
176
/// The URL should be in the format `https://huggingface.co/<repo_type>/<repository>/resolve/<revision>/<path>`
177
177
/// where `repo_type` is either `datasets` or `spaces`.
178
- ///
179
- /// url: The HuggingFace URL to parse.
178
+ ///
179
+ /// url: The HuggingFace URL to parse.
180
180
fn parse_http_style ( url : String ) -> Result < Self > {
181
181
let mut parsed_url = Self :: default ( ) ;
182
182
let mut last_delim = 0 ;
@@ -212,22 +212,24 @@ impl ParsedHFUrl {
212
212
return config_err ! ( "Invalid HuggingFace URL: {}, please format as 'https://huggingface.co/<repo_type>/<repository>/resolve/<revision>/<path>'" , url) ;
213
213
}
214
214
215
- parsed_url. repository = Some ( url[ start_delim..last_delim + next_slash. unwrap ( ) ] . to_string ( ) ) ;
215
+ parsed_url. repository =
216
+ Some ( url[ start_delim..last_delim + next_slash. unwrap ( ) ] . to_string ( ) ) ;
216
217
last_delim += next_slash. unwrap ( ) ;
217
-
218
+
218
219
let next_resolve = url[ last_delim..] . find ( "resolve" ) ;
219
220
if next_resolve. is_none ( ) {
220
221
return config_err ! ( "Invalid HuggingFace URL: {}, please format as 'https://huggingface.co/<repo_type>/<repository>/resolve/<revision>/<path>'" , url) ;
221
222
}
222
-
223
+
223
224
last_delim += next_resolve. unwrap ( ) + "resolve" . len ( ) ;
224
225
225
226
let next_slash = url[ last_delim + 1 ..] . find ( '/' ) ;
226
227
if next_slash. is_none ( ) {
227
228
return config_err ! ( "Invalid HuggingFace URL: {}, please format as 'https://huggingface.co/<repo_type>/<repository>/resolve/<revision>/<path>'" , url) ;
228
229
}
229
230
230
- parsed_url. revision = Some ( url[ last_delim + 1 ..last_delim + 1 + next_slash. unwrap ( ) ] . to_string ( ) ) ;
231
+ parsed_url. revision =
232
+ Some ( url[ last_delim + 1 ..last_delim + 1 + next_slash. unwrap ( ) ] . to_string ( ) ) ;
231
233
last_delim += 1 + next_slash. unwrap ( ) ;
232
234
233
235
// parse path.
@@ -572,15 +574,13 @@ impl ObjectStore for HFStore {
572
574
& self ,
573
575
_prefix : Option < & Path > ,
574
576
) -> ObjectStoreResult < ListResult > {
575
-
576
577
Err ( ObjectStoreError :: NotImplemented )
577
578
}
578
579
579
580
fn list (
580
581
& self ,
581
582
prefix : Option < & Path > ,
582
583
) -> BoxStream < ' _ , ObjectStoreResult < ObjectMeta > > {
583
-
584
584
let Some ( prefix) = prefix else {
585
585
return futures:: stream:: once ( async {
586
586
Err ( ObjectStoreError :: Generic {
@@ -615,7 +615,6 @@ impl ObjectStore for HFStore {
615
615
} ) ;
616
616
} ;
617
617
618
-
619
618
let Ok ( tree_result) =
620
619
serde_json:: from_slice :: < Vec < HFTreeEntry > > ( bytes. to_byte_slice ( ) )
621
620
else {
@@ -638,7 +637,9 @@ impl ObjectStore for HFStore {
638
637
. into_iter ( )
639
638
. map ( |result| {
640
639
result. and_then ( |mut meta| {
641
- let Ok ( location) = ParsedHFUrl :: parse_http_style ( meta. location . to_string ( ) ) else {
640
+ let Ok ( location) =
641
+ ParsedHFUrl :: parse_http_style ( meta. location . to_string ( ) )
642
+ else {
642
643
return Err ( ObjectStoreError :: Generic {
643
644
store : STORE ,
644
645
source : format ! ( "Unable to parse location {}" , meta. location)
@@ -714,28 +715,29 @@ mod tests {
714
715
fn test_parse_hf_url_errors ( ) {
715
716
test_error (
716
717
"datasets/datasets-examples/doc-formats-csv-1" ,
717
- "Invalid HuggingFace URL: hf:// datasets/datasets-examples/doc-formats-csv-1, please format as 'hf://<repo_type>/<repository>[@revision]/<path>'" ,
718
+ "Invalid HuggingFace URL: datasets/datasets-examples/doc-formats-csv-1, please format as 'hf://<repo_type>/<repository>[@revision]/<path>'" ,
718
719
) ;
719
720
720
721
test_error (
721
722
"datadicts/datasets-examples/doc-formats-csv-1/data.csv" ,
722
- "Invalid HuggingFace URL: hf:// datadicts/datasets-examples/doc-formats-csv-1/data.csv, currently only 'datasets' or 'spaces' are supported" ,
723
+ "Invalid HuggingFace URL: datadicts/datasets-examples/doc-formats-csv-1/data.csv, currently only 'datasets' or 'spaces' are supported" ,
723
724
) ;
724
725
725
726
test_error (
726
727
"datasets/datasets-examples/doc-formats-csv-1@~csv" ,
727
- "Invalid HuggingFace URL: hf:// datasets/datasets-examples/doc-formats-csv-1@~csv, please format as 'hf://<repo_type>/<repository>[@revision]/<path>'" ,
728
+ "Invalid HuggingFace URL: datasets/datasets-examples/doc-formats-csv-1@~csv, please format as 'hf://<repo_type>/<repository>[@revision]/<path>'" ,
728
729
) ;
729
730
730
731
test_error (
731
732
"datasets/datasets-examples/doc-formats-csv-1@~csv/" ,
732
- "Invalid HuggingFace URL: hf:// datasets/datasets-examples/doc-formats-csv-1@~csv/, please specify a path" ,
733
+ "Invalid HuggingFace URL: datasets/datasets-examples/doc-formats-csv-1@~csv/, please specify a path" ,
733
734
) ;
734
735
}
735
736
736
737
#[ test]
737
738
fn test_parse_http_url ( ) {
738
- let url = "datasets/datasets-examples/doc-formats-csv-1/resolve/main/data.csv" . to_string ( ) ;
739
+ let url = "datasets/datasets-examples/doc-formats-csv-1/resolve/main/data.csv"
740
+ . to_string ( ) ;
739
741
740
742
let parsed_url = ParsedHFUrl :: parse_http_style ( url) . unwrap ( ) ;
741
743
@@ -748,7 +750,6 @@ mod tests {
748
750
assert_eq ! ( parsed_url. path, Some ( "data.csv" . to_string( ) ) ) ;
749
751
}
750
752
751
-
752
753
#[ test]
753
754
fn test_file_path ( ) {
754
755
let url = "datasets/datasets-examples/doc-formats-csv-1/data.csv" . to_string ( ) ;
0 commit comments