From 9574d062192e6116a2090ba9e75e71fcdfad4b70 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 5 Sep 2024 09:46:33 -0400 Subject: [PATCH] In compiler package, rely on compiler errors. --- distutils/compilers/C/base.py | 10 ++++++---- distutils/compilers/C/borland.py | 12 +++++++----- distutils/compilers/C/cygwin.py | 8 +++++--- distutils/compilers/C/msvc.py | 8 +++++--- distutils/compilers/C/unix.py | 7 ++++++- distutils/compilers/C/zos.py | 3 ++- 6 files changed, 31 insertions(+), 17 deletions(-) diff --git a/distutils/compilers/C/base.py b/distutils/compilers/C/base.py index 60e929c0..8bbe3248 100644 --- a/distutils/compilers/C/base.py +++ b/distutils/compilers/C/base.py @@ -15,15 +15,17 @@ from ..._modified import newer_group from ...dir_util import mkpath from ...errors import ( - CompileError, DistutilsModuleError, DistutilsPlatformError, - LinkError, - UnknownFileError, ) from ...file_util import move_file from ...spawn import spawn from ...util import execute, is_mingw, split_quoted +from .errors import ( + CompileError, + LinkError, + UnknownFileType, +) class Compiler: @@ -974,7 +976,7 @@ def _make_out_path(self, output_dir, strip_dir, src_name): try: new_ext = self.out_extensions[ext] except LookupError: - raise UnknownFileError(f"unknown file type '{ext}' (from '{src_name}')") + raise UnknownFileType(f"unknown file type '{ext}' (from '{src_name}')") if strip_dir: base = os.path.basename(base) return os.path.join(output_dir, base + new_ext) diff --git a/distutils/compilers/C/borland.py b/distutils/compilers/C/borland.py index ab29e14d..616b924e 100644 --- a/distutils/compilers/C/borland.py +++ b/distutils/compilers/C/borland.py @@ -17,15 +17,17 @@ from ..._log import log from ..._modified import newer from ...errors import ( - CompileError, DistutilsExecError, - LibError, - LinkError, - UnknownFileError, ) from ...file_util import write_file from . import base from .base import gen_preprocess_options +from .errors import ( + CompileError, + LibError, + LinkError, + UnknownFileType, +) warnings.warn( "bcppcompiler is deprecated and slated to be removed " @@ -347,7 +349,7 @@ def object_filenames(self, source_filenames, strip_dir=False, output_dir=''): # use normcase to make sure '.rc' is really '.rc' and not '.RC' (base, ext) = os.path.splitext(os.path.normcase(src_name)) if ext not in (self.src_extensions + ['.rc', '.res']): - raise UnknownFileError(f"unknown file type '{ext}' (from '{src_name}')") + raise UnknownFileType(f"unknown file type '{ext}' (from '{src_name}')") if strip_dir: base = os.path.basename(base) if ext == '.res': diff --git a/distutils/compilers/C/cygwin.py b/distutils/compilers/C/cygwin.py index a23171ab..5e96d64f 100644 --- a/distutils/compilers/C/cygwin.py +++ b/distutils/compilers/C/cygwin.py @@ -15,14 +15,16 @@ from subprocess import check_output from ...errors import ( - CCompilerError, - CompileError, DistutilsExecError, DistutilsPlatformError, ) from ...file_util import write_file from ...version import LooseVersion, suppress_known_deprecation from . import unix +from .errors import ( + CompileError, + Error, +) def get_msvcr(): @@ -246,7 +248,7 @@ def __init__(self, verbose=False, dry_run=False, force=False): shared_option = "-shared" if is_cygwincc(self.cc): - raise CCompilerError('Cygwin gcc cannot be used with --compiler=mingw32') + raise Error('Cygwin gcc cannot be used with --compiler=mingw32') self.set_executables( compiler=f'{self.cc} -O -Wall', diff --git a/distutils/compilers/C/msvc.py b/distutils/compilers/C/msvc.py index f0c73a26..dc9a39c6 100644 --- a/distutils/compilers/C/msvc.py +++ b/distutils/compilers/C/msvc.py @@ -25,15 +25,17 @@ from ..._log import log from ...errors import ( - CompileError, DistutilsExecError, DistutilsPlatformError, - LibError, - LinkError, ) from ...util import get_host_platform, get_platform from . import base from .base import gen_lib_options +from .errors import ( + CompileError, + LibError, + LinkError, +) def _find_vc2015(): diff --git a/distutils/compilers/C/unix.py b/distutils/compilers/C/unix.py index fc97241f..1ba93e6a 100644 --- a/distutils/compilers/C/unix.py +++ b/distutils/compilers/C/unix.py @@ -26,9 +26,14 @@ from ..._macos_compat import compiler_fixup from ..._modified import newer from ...compat import consolidate_linker_args -from ...errors import CompileError, DistutilsExecError, LibError, LinkError +from ...errors import DistutilsExecError from . import base from .base import gen_lib_options, gen_preprocess_options +from .errors import ( + CompileError, + LibError, + LinkError, +) # XXX Things not currently handled: # * optimization/debug/warning flags; we just use whatever's in Python's diff --git a/distutils/compilers/C/zos.py b/distutils/compilers/C/zos.py index 5de91e49..82d017fc 100644 --- a/distutils/compilers/C/zos.py +++ b/distutils/compilers/C/zos.py @@ -14,8 +14,9 @@ import os from ... import sysconfig -from ...errors import CompileError, DistutilsExecError +from ...errors import DistutilsExecError from . import unix +from .errors import CompileError _cc_args = { 'ibm-openxl': [