Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] distutils.errors.* is not fully re-exported #2698

1 task done
QuLogic opened this issue Jun 16, 2021 · 1 comment · Fixed by #2858
1 task done

[FR] distutils.errors.* is not fully re-exported #2698

QuLogic opened this issue Jun 16, 2021 · 1 comment · Fixed by #2858
enhancement Needs Triage Issues that need to be evaluated for severity and status.


Copy link

QuLogic commented Jun 16, 2021

What's the problem this feature will solve?

The Migration Advice in PEP 0632 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')]

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.

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

  • I agree to follow the PSF Code of Conduct
Copy link

grlee77 commented Nov 5, 2021

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

abravalheri added a commit to abravalheri/setuptools that referenced this issue Nov 5, 2021
As mentioned in pypa#2698, exposing distutil errors via setuptools help the
migration stated by PEP 632.
XuanWang-Amos added a commit to grpc/grpc that referenced this issue Sep 6, 2023
### Background

* `distutils` is deprecated with removal planned for Python 3.12
([pep-0632](, thus we're trying to
replace all distutils usage with setuptools.
* Please note that user still have access to `distutils` if setuptools
is installed and `SETUPTOOLS_USE_DISTUTILS` is set to `local` (The
default in setuptools, more details can be found [in this
discussion](pypa/setuptools#2806 (comment))).

### How we decide the replacement

* We're following setuptools [Porting from Distutils
when deciding the replacement.

#### Replacement not mentioned in the guide

* Replaced `distutils.utils.get_platform()` with
* Based on the [answer
and also checked the document that `sysconfig.get_platform()` is good
enough for our use cases.
* Replaced `DistutilsOptionError` with `OptionError`.
* `setuptools.error` is exporting it as `OptionError` [in the
* Upgrade `setuptools` in `` and changed the version
ping to `59.6.0` in `build_artifact_python.bat`.
* `distutils.errors.*` is not fully re-exported until `59.0.0` (See
[this issue](pypa/setuptools#2698) for more

### Changes not included in this PR

* We're patching some compiler related functions provided by distutils
in our code
but since `setuptools` doesn't have similar interface (See [this issue
for more details](pypa/setuptools#2806)), we
don't have a clear path to replace them yet.


If you know who should review your pull request, please assign it to
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
lang label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
enhancement Needs Triage Issues that need to be evaluated for severity and status.
None yet

Successfully merging a pull request may close this issue.

2 participants