@@ -99,12 +99,12 @@ def download_file(
9999 destination_path = Path (destination ) if destination is not None else None
100100
101101 # If destination is not a dir, create it
102- if destination_path is not None and not destination_path .is_dir ():
102+ if destination_path is not None and not destination_path .exists ():
103103 destination_path .mkdir (parents = True , exist_ok = True )
104104
105- # Check if it was able to create the dir
105+ # Check if it was able to create the dir, very rare case
106106 if destination_path is not None and not destination_path .is_dir ():
107- raise ValueError ("Destination directory provided does not exist" )
107+ raise ValueError ("Destination directory provided does not exist" ) # pragma: no cover
108108
109109 url = self ._get_filepath_on_default_server (filename , directory )
110110 local_path = self ._retrieve_data (url , filename , dest = destination , force = force )
@@ -125,7 +125,8 @@ def _add_file(self, file_path: str):
125125 file_path : str
126126 Local path of the downloaded example file.
127127 """
128- self ._downloads_list .append (file_path )
128+ if file_path not in self ._downloads_list :
129+ self ._downloads_list .append (file_path )
129130
130131 def _joinurl (self , base : str , directory : str ) -> str :
131132 """Join multiple paths to a base URL.
@@ -185,10 +186,11 @@ def _retrieve_data(self, url: str, filename: str, dest: str = None, force: bool
185186 str
186187 The local path where the file was saved.
187188 """
189+ local_path = ""
188190 if dest is None :
189191 dest = tempfile .gettempdir () # Use system temp directory if no destination is provided
190192 local_path = Path (dest ) / Path (filename ).name
191- if not force and Path .is_file (local_path ):
193+ if not force and Path .is_file (Path ( local_path ) ):
192194 return local_path
193195 try :
194196 local_path , _ = urllib .request .urlretrieve (url , filename = local_path )
0 commit comments