88import time
99from collections import defaultdict
1010from os import makedirs , path
11- from re import compile , match , sub
11+ from re import match , sub
1212from typing import Dict , Iterable , List , Optional , Set , TypeVar
1313
1414import boto3 # type: ignore[import]
@@ -630,12 +630,15 @@ def grant_public_read(cls, key: str) -> None:
630630 CLIENT .put_object_acl (Bucket = BUCKET .name , Key = key , ACL = "public-read" )
631631
632632 @classmethod
633- def fetch_object_names (cls , prefix : str , pattern : str ) -> List [str ]:
633+ def fetch_object_names (cls , prefix : str ) -> List [str ]:
634634 obj_names = []
635635 for obj in BUCKET .objects .filter (Prefix = prefix ):
636636 is_acceptable = any (
637637 [path .dirname (obj .key ) == prefix ]
638- + [match (compile (f"{ prefix } /{ pattern } " ), path .dirname (obj .key ))]
638+ + [
639+ match (f"{ prefix } /{ pattern } " , path .dirname (obj .key ))
640+ for pattern in ACCEPTED_SUBDIR_PATTERNS
641+ ]
639642 ) and obj .key .endswith (ACCEPTED_FILE_EXTENSIONS )
640643 if not is_acceptable :
641644 continue
@@ -703,11 +706,9 @@ def _fetch_metadata(key: str) -> str:
703706 self .objects [idx ].pep658 = response
704707
705708 @classmethod
706- def from_S3 (
707- cls , prefix : str , pattern : str , with_metadata : bool = True
708- ) -> "S3Index" :
709+ def from_S3 (cls , prefix : str , with_metadata : bool = True ) -> "S3Index" :
709710 prefix = prefix .rstrip ("/" )
710- obj_names = cls .fetch_object_names (prefix , pattern )
711+ obj_names = cls .fetch_object_names (prefix )
711712
712713 def sanitize_key (key : str ) -> str :
713714 return key .replace ("+" , "%2B" )
@@ -748,12 +749,6 @@ def undelete_prefix(cls, prefix: str) -> None:
748749def create_parser () -> argparse .ArgumentParser :
749750 parser = argparse .ArgumentParser ("Manage S3 HTML indices for PyTorch" )
750751 parser .add_argument ("prefix" , type = str , choices = PREFIXES + ["all" ])
751- parser .add_argument (
752- "--subdir-pattern" ,
753- type = str ,
754- choices = ACCEPTED_SUBDIR_PATTERNS + ["all" ],
755- default = "all" ,
756- )
757752 parser .add_argument ("--do-not-upload" , action = "store_true" )
758753 parser .add_argument ("--compute-sha256" , action = "store_true" )
759754 return parser
@@ -766,22 +761,14 @@ def main() -> None:
766761 if args .compute_sha256 :
767762 action = "Computing checksums"
768763
769- patterns = (
770- ACCEPTED_SUBDIR_PATTERNS
771- if args .subdir_pattern == "all"
772- else [args .subdir_pattern ]
773- )
774764 prefixes = PREFIXES if args .prefix == "all" else [args .prefix ]
775765 for prefix in prefixes :
776766 generate_pep503 = prefix .startswith ("whl" )
777767 print (f"INFO: { action } for '{ prefix } '" )
778768 stime = time .time ()
779- for pattern in patterns :
780- idx = S3Index .from_S3 (
781- prefix = prefix ,
782- pattern = pattern ,
783- with_metadata = generate_pep503 or args .compute_sha256 ,
784- )
769+ idx = S3Index .from_S3 (
770+ prefix = prefix , with_metadata = generate_pep503 or args .compute_sha256
771+ )
785772 etime = time .time ()
786773 print (
787774 f"DEBUG: Fetched { len (idx .objects )} objects for '{ prefix } ' in { etime - stime :.2f} seconds"
0 commit comments