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

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

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

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

Comments

@QuLogic
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')]
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.

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
@grlee77
Copy link

grlee77 commented Nov 5, 2021

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)

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](https://peps.python.org/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
guide](https://setuptools.pypa.io/en/latest/deprecated/distutils-legacy.html#porting-from-distutils)
when deciding the replacement.

#### Replacement not mentioned in the guide

* Replaced `distutils.utils.get_platform()` with
`sysconfig.get_platform()`.
* Based on the [answer
here](https://stackoverflow.com/questions/71664875/what-is-the-replacement-for-distutils-util-get-platform),
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
code](https://github.com/pypa/setuptools/blob/v59.6.0/setuptools/errors.py).
* Upgrade `setuptools` in `test_packages.sh` 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
details).

### Changes not included in this PR

* We're patching some compiler related functions provided by distutils
in our code
([example](https://github.com/grpc/grpc/blob/ee4efc31c1dde7389ece70ba908049d7baeb9c65/src/python/grpcio/_spawn_patch.py#L30)),
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
that
person, otherwise the pull request would get assigned randomly.

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

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

Successfully merging a pull request may close this issue.

2 participants