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

Re-export errors from distutils #2858

Merged
merged 3 commits into from
Nov 7, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/2698.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Exposed exception classes from ``distutils.errors`` via ``setuptools.errors``.
2 changes: 2 additions & 0 deletions changelog.d/2698.doc.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added mentions to ``setuptools.errors`` as a way of handling custom command
errors.
2 changes: 2 additions & 0 deletions changelog.d/2698.doc.2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added instructions to migrate from ``distutils.commands`` and
``distutils.errors`` in the porting guide.
9 changes: 9 additions & 0 deletions docs/deprecated/distutils-legacy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,17 @@ As Distutils is deprecated, any usage of functions or objects from distutils is

``distutils.cmd.Command`` → ``setuptools.Command``

``distutils.command.{build_clib,build_ext,build_py,sdist}`` → ``setuptools.command.*``

``distutils.log`` → (no replacement yet)

``distutils.version.*`` → ``packaging.version.*``

``distutils.errors.*`` → ``setuptools.errors.*`` [#errors]_

If a project relies on uses of ``distutils`` that do not have a suitable replacement above, please search the `Setuptools issue tracker <https://github.com/pypa/setuptools/issues/>`_ and file a request, describing the use-case so that Setuptools' maintainers can investigate. Please provide enough detail to help the maintainers understand how distutils is used, what value it provides, and why that behavior should be supported.


.. [#errors] Please notice errors related to the command line usage of
``setup.py``, such as ``DistutilsArgError``, are intentionally not exposed
by setuptools, since this is considered a deprecated practice.
8 changes: 8 additions & 0 deletions docs/userguide/extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ entry points in the active distributions on ``sys.path``. In fact, this is
how setuptools' own commands are installed: the setuptools project's setup
script defines entry points for them!

.. note::
When creating commands, and specially when defining custom ways of building
compiled extensions (for example via ``build_ext``), you might want to
handle exceptions such as ``CompileError``, ``LinkError``, ``LibError``,
jaraco marked this conversation as resolved.
Show resolved Hide resolved
among others. These exceptions are available in the ``setuptools.errors``
module.


Adding ``setup()`` Arguments
----------------------------

Expand Down
24 changes: 24 additions & 0 deletions setuptools/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Provides exceptions used by setuptools modules.
"""

from distutils import errors as _distutils_errors
from distutils.errors import DistutilsError


Expand All @@ -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