Skip to content

By default, provide a much more concise error message. #4985

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

Merged
merged 3 commits into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions docs/userguide/development_mode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,25 @@ More information is available on the text of :pep:`PEP 660 <660#what-to-put-in-t
used.


Debugging Tips
--------------

If encountering problems installing a project in editable mode,
follow these recommended steps to help debug:

- Try to install the project normally, without using the editable mode.
Does the error still persist?
(If it does, try fixing the problem before attempting the editable mode).
- When using binary extensions, make sure all OS-level
dependencies are installed (e.g. compilers, toolchains, binary libraries, ...).
- Try the latest version of setuptools (maybe the error was already fixed).
- When the project or its dependencies are using any setuptools extension
or customization, make sure they support the editable mode.

After following the steps above, if the problem still persists and
you think this is related to how setuptools handles editable installations,
please submit a `reproducible example <https://stackoverflow.com/help/minimal-reproducible-example>`_ at `the bug tracker <https://github.com/pypa/setuptools/issues>`_.

----

.. rubric:: Notes
Expand Down
1 change: 1 addition & 0 deletions newsfragments/4984.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Simplified the error reporting in editable installs.
40 changes: 9 additions & 31 deletions setuptools/command/editable_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@

from .. import Command, _normalization, _path, _shutil, errors, namespaces
from .._path import StrPath
from ..compat import py312
from ..compat import py310, py312
from ..discovery import find_package_path
from ..dist import Distribution
from ..warnings import InformationOnly, SetuptoolsDeprecationWarning, SetuptoolsWarning
from ..warnings import InformationOnly, SetuptoolsDeprecationWarning
from .build import build as build_cls
from .build_py import build_py as build_py_cls
from .dist_info import dist_info as dist_info_cls
Expand Down Expand Up @@ -137,10 +137,14 @@ def run(self) -> None:
bdist_wheel.write_wheelfile(self.dist_info_dir)

self._create_wheel_file(bdist_wheel)
except Exception:
traceback.print_exc()
except Exception as ex:
project = self.distribution.name or self.distribution.get_name()
_DebuggingTips.emit(project=project)
py310.add_note(
ex,
f"An error occurred when building editable wheel for {project}.\n"
"See debugging tips in: "
"https://setuptools.pypa.io/en/latest/userguide/development_mode.html#debugging-tips",
)
raise

def _ensure_dist_info(self):
Expand Down Expand Up @@ -902,29 +906,3 @@ def _finder_template(

class LinksNotSupported(errors.FileError):
"""File system does not seem to support either symlinks or hard links."""


class _DebuggingTips(SetuptoolsWarning):
_SUMMARY = "Problem in editable installation."
_DETAILS = """
An error happened while installing `{project}` in editable mode.

The following steps are recommended to help debug this problem:

- Try to install the project normally, without using the editable mode.
Does the error still persist?
(If it does, try fixing the problem before attempting the editable mode).
- If you are using binary extensions, make sure you have all OS-level
dependencies installed (e.g. compilers, toolchains, binary libraries, ...).
- Try the latest version of setuptools (maybe the error was already fixed).
- If you (or your project dependencies) are using any setuptools extension
or customization, make sure they support the editable mode.

After following the steps above, if the problem still persists and
you think this is related to how setuptools handles editable installations,
please submit a reproducible example
(see https://stackoverflow.com/help/minimal-reproducible-example) to:

https://github.com/pypa/setuptools/issues
"""
_SEE_DOCS = "userguide/development_mode.html"
11 changes: 11 additions & 0 deletions setuptools/compat/py310.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,14 @@
import tomllib
else: # pragma: no cover
import tomli as tomllib


if sys.version_info >= (3, 11):

def add_note(ex, note):
ex.add_note(note)

else: # pragma: no cover

def add_note(ex, note):
vars(ex).setdefault('__notes__', []).append(note)
5 changes: 2 additions & 3 deletions setuptools/tests/test_editable_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

from setuptools._importlib import resources as importlib_resources
from setuptools.command.editable_wheel import (
_DebuggingTips,
_encode_pth,
_find_namespaces,
_find_package_roots,
Expand Down Expand Up @@ -1201,9 +1200,9 @@ def test_debugging_tips(tmpdir_cwd, monkeypatch):
simulated_failure = Mock(side_effect=SimulatedErr())
monkeypatch.setattr(cmd, "get_finalized_command", simulated_failure)

expected_msg = "following steps are recommended to help debug"
with pytest.raises(SimulatedErr), pytest.warns(_DebuggingTips, match=expected_msg):
with pytest.raises(SimulatedErr) as ctx:
cmd.run()
assert any('debugging-tips' in note for note in ctx.value.__notes__)


@pytest.mark.filterwarnings("error")
Expand Down
Loading