@@ -296,7 +296,9 @@ def validate_sha256(self, force_recompute: bool = False) -> None:
296296 )
297297
298298 def get_reader (
299- self , * , progressbar : Union [Progressbar , Callable [[], Progressbar ], bool ] = True
299+ self ,
300+ * ,
301+ progressbar : Union [Progressbar , Callable [[], Progressbar ], bool , None ] = None ,
300302 ):
301303 """open the file source (download if needed)"""
302304 return get_reader (self .source , progressbar = progressbar , sha256 = self .sha256 )
@@ -690,7 +692,7 @@ def get_reader(
690692def _open_url (
691693 source : HttpUrl ,
692694 / ,
693- progressbar : Union [Progressbar , Callable [[], Progressbar ], bool , None ] = None ,
695+ progressbar : Union [Progressbar , Callable [[], Progressbar ], bool , None ],
694696 ** kwargs : Unpack [HashKwargs ],
695697) -> BytesReader :
696698 cache = (
@@ -724,40 +726,39 @@ def _open_url(
724726def _fetch_url (
725727 source : RootHttpUrl ,
726728 * ,
727- progressbar : Union [Progressbar , Callable [[], Progressbar ], bool , None ] = None ,
729+ progressbar : Union [Progressbar , Callable [[], Progressbar ], bool , None ],
728730):
729731 if source .scheme not in ("http" , "https" ):
730732 raise NotImplementedError (source .scheme )
731733
734+ if progressbar is None :
735+ # chose progressbar option from validation context
736+ progressbar = get_validation_context ().progressbar
737+
738+ if progressbar is None :
739+ # default to no progressbar in CI environments
740+ progressbar = not settings .CI
741+
732742 if callable (progressbar ):
733743 progressbar = progressbar ()
734744
735- if settings .CI :
736- headers = {"User-Agent" : "ci" }
737- if progressbar is None :
738- progressbar = False
739- else :
740- headers = {}
741- if progressbar is None :
742- progressbar = True
743-
744- if isinstance (progressbar , bool ):
745- # setup progressbar
746- if progressbar :
747- use_ascii = bool (sys .platform == "win32" )
748- progressbar = tqdm (
749- ncols = 79 ,
750- ascii = use_ascii ,
751- unit = "B" ,
752- unit_scale = True ,
753- leave = True ,
754- )
745+ if isinstance (progressbar , bool ) and progressbar :
746+ progressbar = tqdm (
747+ ncols = 79 ,
748+ ascii = bool (sys .platform == "win32" ),
749+ unit = "B" ,
750+ unit_scale = True ,
751+ leave = True ,
752+ )
755753
756754 if progressbar is not False :
757755 progressbar .set_description (f"Downloading { extract_file_name (source )} " )
758756
757+ headers : Dict [str , str ] = {}
759758 if settings .user_agent is not None :
760759 headers ["User-Agent" ] = settings .user_agent
760+ elif settings .CI :
761+ headers ["User-Agent" ] = "ci"
761762
762763 r = httpx .get (str (source ), follow_redirects = True , headers = headers )
763764 _ = r .raise_for_status ()
0 commit comments