5
5
import logging
6
6
import os .path
7
7
import re
8
- import shutil
9
8
from collections .abc import Iterable
9
+ from tempfile import TemporaryDirectory
10
10
11
11
from pip ._vendor .packaging .utils import canonicalize_name , canonicalize_version
12
12
from pip ._vendor .packaging .version import InvalidVersion , Version
24
24
from pip ._internal .utils .misc import ensure_dir , hash_file
25
25
from pip ._internal .utils .setuptools_build import make_setuptools_clean_args
26
26
from pip ._internal .utils .subprocess import call_subprocess
27
- from pip ._internal .utils .temp_dir import TempDirectory
28
27
from pip ._internal .utils .urls import path_to_url
29
28
from pip ._internal .vcs import vcs
30
29
@@ -189,7 +188,7 @@ def _build_one_inside_env(
189
188
global_options : list [str ],
190
189
editable : bool ,
191
190
) -> str | None :
192
- with TempDirectory ( kind = "wheel" ) as temp_dir :
191
+ with TemporaryDirectory ( dir = output_dir ) as temp_dir :
193
192
assert req .name
194
193
if req .use_pep517 :
195
194
assert req .metadata_directory
@@ -207,14 +206,14 @@ def _build_one_inside_env(
207
206
name = req .name ,
208
207
backend = req .pep517_backend ,
209
208
metadata_directory = req .metadata_directory ,
210
- tempd = temp_dir . path ,
209
+ tempd = temp_dir ,
211
210
)
212
211
else :
213
212
wheel_path = build_wheel_pep517 (
214
213
name = req .name ,
215
214
backend = req .pep517_backend ,
216
215
metadata_directory = req .metadata_directory ,
217
- tempd = temp_dir . path ,
216
+ tempd = temp_dir ,
218
217
)
219
218
else :
220
219
wheel_path = build_wheel_legacy (
@@ -223,15 +222,17 @@ def _build_one_inside_env(
223
222
source_dir = req .unpacked_source_directory ,
224
223
global_options = global_options ,
225
224
build_options = build_options ,
226
- tempd = temp_dir . path ,
225
+ tempd = temp_dir ,
227
226
)
228
227
229
228
if wheel_path is not None :
230
229
wheel_name = os .path .basename (wheel_path )
231
230
dest_path = os .path .join (output_dir , wheel_name )
232
231
try :
233
232
wheel_hash , length = hash_file (wheel_path )
234
- shutil .move (wheel_path , dest_path )
233
+ # We can do a rename here because wheel_path is guaranteed to be
234
+ # in the same filesystem as output_dir.
235
+ os .rename (wheel_path , dest_path )
235
236
logger .info (
236
237
"Created wheel for %s: filename=%s size=%d sha256=%s" ,
237
238
req .name ,
0 commit comments