Repository: pypa/setuptools

Issue:
[FR] distutils.errors.* is not fully re-exported
### What's the problem this feature will solve?

The [Migration Advice in PEP 0632](https://www.python.org/dev/peps/pep-0632/#migration-advice) says that `setuptools` is a sufficient replacement for `distutils.errors`. However, only `DistutilsError` and `RemovedCommandError` exist there. In `distutils`, there are:
```
In [7]: [e for e in dir(distutils.errors) if e.endswith('Error')]
Out[7]: 
['CCompilerError',
 'CompileError',
 'DistutilsArgError',
 'DistutilsByteCompileError',
 'DistutilsClassError',
 'DistutilsError',
 'DistutilsExecError',
 'DistutilsFileError',
 'DistutilsGetoptError',
 'DistutilsInternalError',
 'DistutilsModuleError',
 'DistutilsOptionError',
 'DistutilsPlatformError',
 'DistutilsSetupError',
 'DistutilsTemplateError',
 'LibError',
 'LinkError',
 'PreprocessError',
 'UnknownFileError']
```
While all of the `Distutils`-prefixed ones derive from `DistutilsError`, the ones without the prefix are derived from `CCompilerError`, and so cannot be caught using anything exported by `setuptools`. Concretely, this makes it difficult to check for compiler flags, as [done here](https://github.com/matplotlib/matplotlib/blob/69395749a4e588eade55b90dbf095549258f4b16/setup.py#L62-L72).

### Describe the solution you'd like

Re-export all `distutils.errors.*` in `setuptools.errors`.

### Alternative Solutions

Currently, we use `distutils.errors`, but won't be able to after Python 3.12. One can use a generic `Exception` too, but that's not recommended.

Or as a complete alternative, if `setuptools` had a way to check whether a compiler supported a flag in a builtin way, then we wouldn't need to catch the `CompileError` ourselves.

### Additional context

_No response_

### Code of Conduct

- [X] I agree to follow the PSF Code of Conduct


Discussion:
I had this same question regarding use of this in scikit-image's setup.py. What is the recommended path forward here? (`CompileError` and `LinkError` are the two being used in our case)

Resolving patch:
diff --git a/setuptools/errors.py b/setuptools/errors.py
--- a/setuptools/errors.py
+++ b/setuptools/errors.py
@@ -3,6 +3,7 @@
 Provides exceptions used by setuptools modules.
 """
 
+from distutils import errors as _distutils_errors
 from distutils.errors import DistutilsError
 
 
@@ -14,3 +15,26 @@ class RemovedCommandError(DistutilsError, RuntimeError):
     error is raised if a command exists in ``distutils`` but has been actively
     removed in ``setuptools``.
     """
+
+
+# Re-export errors from distutils to facilitate the migration to PEP632
+
+ByteCompileError = _distutils_errors.DistutilsByteCompileError
+CCompilerError = _distutils_errors.CCompilerError
+ClassError = _distutils_errors.DistutilsClassError
+CompileError = _distutils_errors.CompileError
+ExecError = _distutils_errors.DistutilsExecError
+FileError = _distutils_errors.DistutilsFileError
+InternalError = _distutils_errors.DistutilsInternalError
+LibError = _distutils_errors.LibError
+LinkError = _distutils_errors.LinkError
+ModuleError = _distutils_errors.DistutilsModuleError
+OptionError = _distutils_errors.DistutilsOptionError
+PlatformError = _distutils_errors.DistutilsPlatformError
+PreprocessError = _distutils_errors.PreprocessError
+SetupError = _distutils_errors.DistutilsSetupError
+TemplateError = _distutils_errors.DistutilsTemplateError
+UnknownFileError = _distutils_errors.UnknownFileError
+
+# The root error class in the hierarchy
+BaseError = _distutils_errors.DistutilsError


Test patch: