88import subprocess
99import sys
1010import sysconfig
11- from distutils import log
12- from distutils .errors import (
11+ import logging
12+ from setuptools .errors import (
1313 CompileError ,
14- DistutilsExecError ,
15- DistutilsFileError ,
16- DistutilsPlatformError ,
14+ ExecError ,
15+ FileError ,
16+ PlatformError ,
1717)
18- from distutils . sysconfig import get_config_var
18+ from sysconfig import get_config_var
1919from pathlib import Path
2020from typing import Dict , Iterable , List , NamedTuple , Optional , Set , Tuple , cast
2121
3636 get_rustc_cfgs ,
3737)
3838
39+ logger = logging .getLogger (__name__ )
40+
3941
4042def _check_cargo_supports_crate_type_option () -> bool :
4143 version = get_rust_version ()
@@ -153,9 +155,7 @@ def build_extension(
153155 env = _prepare_build_environment ()
154156
155157 if not os .path .exists (ext .path ):
156- raise DistutilsFileError (
157- f"can't find Rust extension project file: { ext .path } "
158- )
158+ raise FileError (f"can't find Rust extension project file: { ext .path } " )
159159
160160 quiet = self .qbuild or ext .quiet
161161 debug = self ._is_debug_build (ext )
@@ -260,7 +260,7 @@ def build_extension(
260260 raise CompileError (format_called_process_error (e , include_stdout = False ))
261261
262262 except OSError :
263- raise DistutilsExecError (
263+ raise ExecError (
264264 "Unable to execute 'cargo' - this package "
265265 "requires Rust to be installed and cargo to be on the PATH"
266266 )
@@ -289,7 +289,7 @@ def build_extension(
289289 if Path (artifact ).with_suffix ("" ).name == name
290290 )
291291 except StopIteration :
292- raise DistutilsExecError (
292+ raise ExecError (
293293 f"Rust build failed; unable to locate executable '{ name } '"
294294 )
295295
@@ -307,11 +307,11 @@ def build_extension(
307307 kinds = {"cdylib" , "dylib" },
308308 )
309309 if len (artifacts ) == 0 :
310- raise DistutilsExecError (
310+ raise ExecError (
311311 "Rust build failed; unable to find any cdylib or dylib build artifacts"
312312 )
313313 elif len (artifacts ) > 1 :
314- raise DistutilsExecError (
314+ raise ExecError (
315315 f"Rust build failed; expected only one cdylib or dylib build artifact but found { artifacts } "
316316 )
317317
@@ -371,7 +371,7 @@ def install_extension(
371371 ext_path = self .get_dylib_ext_path (ext , module_name )
372372 os .makedirs (os .path .dirname (ext_path ), exist_ok = True )
373373
374- log .info ("Copying rust artifact from %s to %s" , dylib_path , ext_path )
374+ logger .info ("Copying rust artifact from %s to %s" , dylib_path , ext_path )
375375
376376 # We want to atomically replace any existing library file. We can't
377377 # just copy the new library directly on top of the old one as that
@@ -546,7 +546,7 @@ def create_universal2_binary(output_path: str, input_paths: List[str]) -> None:
546546 try :
547547 from fat_macho import FatWriter
548548 except ImportError :
549- raise DistutilsExecError (
549+ raise ExecError (
550550 "failed to locate `lipo` or import `fat_macho.FatWriter`. "
551551 "Try installing with `pip install fat-macho` "
552552 )
@@ -648,7 +648,7 @@ def _binding_features(
648648 elif ext .binding is Binding .RustCPython :
649649 return {"cpython/python3-sys" , "cpython/extension-module" }
650650 else :
651- raise DistutilsPlatformError (f"unknown Rust binding: '{ ext .binding } '" )
651+ raise PlatformError (f"unknown Rust binding: '{ ext .binding } '" )
652652
653653
654654_PyLimitedApi = Literal ["cp37" , "cp38" , "cp39" , "cp310" , "cp311" , "cp312" , True , False ]
0 commit comments