8
8
import subprocess
9
9
import sys
10
10
import sysconfig
11
- from distutils import log
12
- from distutils .errors import (
11
+ import logging
12
+ from setuptools .errors import (
13
13
CompileError ,
14
- DistutilsExecError ,
15
- DistutilsFileError ,
16
- DistutilsPlatformError ,
14
+ ExecError ,
15
+ FileError ,
16
+ PlatformError ,
17
17
)
18
- from distutils . sysconfig import get_config_var
18
+ from sysconfig import get_config_var
19
19
from pathlib import Path
20
20
from typing import Dict , Iterable , List , NamedTuple , Optional , Set , Tuple , cast
21
21
36
36
get_rustc_cfgs ,
37
37
)
38
38
39
+ logger = logging .getLogger (__name__ )
39
40
40
41
def _check_cargo_supports_crate_type_option () -> bool :
41
42
version = get_rust_version ()
@@ -153,7 +154,7 @@ def build_extension(
153
154
env = _prepare_build_environment ()
154
155
155
156
if not os .path .exists (ext .path ):
156
- raise DistutilsFileError (
157
+ raise FileError (
157
158
f"can't find Rust extension project file: { ext .path } "
158
159
)
159
160
@@ -260,7 +261,7 @@ def build_extension(
260
261
raise CompileError (format_called_process_error (e , include_stdout = False ))
261
262
262
263
except OSError :
263
- raise DistutilsExecError (
264
+ raise ExecError (
264
265
"Unable to execute 'cargo' - this package "
265
266
"requires Rust to be installed and cargo to be on the PATH"
266
267
)
@@ -289,7 +290,7 @@ def build_extension(
289
290
if Path (artifact ).with_suffix ("" ).name == name
290
291
)
291
292
except StopIteration :
292
- raise DistutilsExecError (
293
+ raise ExecError (
293
294
f"Rust build failed; unable to locate executable '{ name } '"
294
295
)
295
296
@@ -307,11 +308,11 @@ def build_extension(
307
308
kinds = {"cdylib" , "dylib" },
308
309
)
309
310
if len (artifacts ) == 0 :
310
- raise DistutilsExecError (
311
+ raise ExecError (
311
312
"Rust build failed; unable to find any cdylib or dylib build artifacts"
312
313
)
313
314
elif len (artifacts ) > 1 :
314
- raise DistutilsExecError (
315
+ raise ExecError (
315
316
f"Rust build failed; expected only one cdylib or dylib build artifact but found { artifacts } "
316
317
)
317
318
@@ -371,7 +372,7 @@ def install_extension(
371
372
ext_path = self .get_dylib_ext_path (ext , module_name )
372
373
os .makedirs (os .path .dirname (ext_path ), exist_ok = True )
373
374
374
- log .info ("Copying rust artifact from %s to %s" , dylib_path , ext_path )
375
+ logger .info ("Copying rust artifact from %s to %s" , dylib_path , ext_path )
375
376
376
377
# We want to atomically replace any existing library file. We can't
377
378
# just copy the new library directly on top of the old one as that
@@ -546,7 +547,7 @@ def create_universal2_binary(output_path: str, input_paths: List[str]) -> None:
546
547
try :
547
548
from fat_macho import FatWriter
548
549
except ImportError :
549
- raise DistutilsExecError (
550
+ raise ExecError (
550
551
"failed to locate `lipo` or import `fat_macho.FatWriter`. "
551
552
"Try installing with `pip install fat-macho` "
552
553
)
@@ -648,7 +649,7 @@ def _binding_features(
648
649
elif ext .binding is Binding .RustCPython :
649
650
return {"cpython/python3-sys" , "cpython/extension-module" }
650
651
else :
651
- raise DistutilsPlatformError (f"unknown Rust binding: '{ ext .binding } '" )
652
+ raise PlatformError (f"unknown Rust binding: '{ ext .binding } '" )
652
653
653
654
654
655
_PyLimitedApi = Literal ["cp37" , "cp38" , "cp39" , "cp310" , "cp311" , "cp312" , True , False ]
0 commit comments