@@ -138,12 +138,11 @@ class SchemeDictionaryDestination(WheelDestination):
138138 overwrite_existing : bool = False
139139 """Silently overwrite existing files."""
140140
141- def _path_with_destdir (self , scheme : Scheme , path : str ) -> str :
142- file = os . path . join (self .scheme_dict [scheme ], path )
141+ def _path_with_destdir (self , scheme : Scheme , path : str ) -> Path :
142+ file = Path (self .scheme_dict [scheme ]) / path
143143 if self .destdir is not None :
144- file_path = Path (file )
145- rel_path = file_path .relative_to (file_path .anchor )
146- return os .path .join (self .destdir , rel_path )
144+ rel_path = file .relative_to (file .anchor )
145+ return Path (self .destdir ) / rel_path
147146 return file
148147
149148 def write_to_fs (
@@ -164,15 +163,15 @@ def write_to_fs(
164163 - Hashes the written content, to determine the entry in the ``RECORD`` file.
165164 """
166165 target_path = self ._path_with_destdir (scheme , path )
167- if not self .overwrite_existing and os . path . exists (target_path ):
168- message = f"File already exists: { target_path } "
166+ if not self .overwrite_existing and target_path . exists ():
167+ message = f"File already exists: { target_path !s } "
169168 raise FileExistsError (message )
170169
171- parent_folder = os . path . dirname ( target_path )
172- if not os . path . exists (parent_folder ):
173- os . makedirs ( parent_folder )
170+ parent_folder = target_path . parent
171+ if not parent_folder . exists ():
172+ parent_folder . mkdir ( parents = True )
174173
175- with open (target_path , "wb" ) as f :
174+ with target_path . open ("wb" ) as f :
176175 hash_ , size = copyfileobj_with_hashing (stream , f , self .hash_algorithm )
177176
178177 if is_executable :
@@ -234,9 +233,9 @@ def write_script(
234233 )
235234
236235 path = self ._path_with_destdir (Scheme ("scripts" ), script_name )
237- mode = os .stat (path ).st_mode
236+ mode = path .stat ().st_mode
238237 mode |= (mode & 0o444 ) >> 2
239- os .chmod (path , mode )
238+ path .chmod (mode )
240239
241240 return entry
242241
@@ -248,9 +247,8 @@ def _compile_bytecode(self, scheme: Scheme, record: RecordEntry) -> None:
248247 import compileall
249248
250249 target_path = self ._path_with_destdir (scheme , record .path )
251- dir_path_to_embed = os .path .dirname ( # Without destdir
252- os .path .join (self .scheme_dict [scheme ], record .path )
253- )
250+ dir_path_to_embed = (Path (self .scheme_dict [scheme ]) / record .path ).parent
251+
254252 for level in self .bytecode_optimization_levels :
255253 compileall .compile_file (
256254 target_path , optimize = level , quiet = 1 , ddir = dir_path_to_embed
0 commit comments