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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jaraco
Copy link
Member

@jaraco jaraco commented May 6, 2025

Fixes #4984

Summary of changes

Closes

Pull Request Checklist

@jaraco jaraco marked this pull request as draft May 6, 2025 20:57
@jaraco
Copy link
Member Author

jaraco commented May 6, 2025

This PR creates a much nicer experience for users who are actively developing their unstable projects and are working through compiler issues.

 pyobjc-core master 🐚 py -3.13 -m pip-run 'git+https://github.com/pypa/setuptools@refs/pull/4985/head' wheel -- -c 'import setuptools.build_meta as backend; backend.build_editable(wheel_directory="throwaway")' 2>1 | tail -n 10
clang -fno-strict-overflow -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -O3 -Wall -I/opt/homebrew/opt/python@3.13/Frameworks/Python.framework/Versions/3.13/include/python3.13 -c Modules/objc/OC_PythonUnicode.m -o /var/folders/f2/2plv6q2n7l932m2x004jlw340000gn/T/tmpw493ws0b.build-temp/Modules/objc/OC_PythonUnicode.o -g -fexceptions -fno-objc-arc -Wall -Wno-variadic-macros -Wstrict-prototypes -Wbad-function-cast -Wmissing-prototypes -Wformat=2 -W -Wpointer-arith -Wmissing-declarations -Wnested-externs -W -Wno-import -Wno-unknown-pragmas -Wshorten-64-to-32 -Werror -Wno-cast-function-type-mismatch -I/usr/include/ffi -fvisibility=hidden -g -UNDEBUG -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -DPyObjC_BUILD_RELEASE=1504
clang -fno-strict-overflow -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -O3 -Wall -I/opt/homebrew/opt/python@3.13/Frameworks/Python.framework/Versions/3.13/include/python3.13 -c Modules/objc/ObjCPointer.m -o /var/folders/f2/2plv6q2n7l932m2x004jlw340000gn/T/tmpw493ws0b.build-temp/Modules/objc/ObjCPointer.o -g -fexceptions -fno-objc-arc -Wall -Wno-variadic-macros -Wstrict-prototypes -Wbad-function-cast -Wmissing-prototypes -Wformat=2 -W -Wpointer-arith -Wmissing-declarations -Wnested-externs -W -Wno-import -Wno-unknown-pragmas -Wshorten-64-to-32 -Werror -Wno-cast-function-type-mismatch -I/usr/include/ffi -fvisibility=hidden -g -UNDEBUG -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -DPyObjC_BUILD_RELEASE=1504
clang -fno-strict-overflow -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -O3 -Wall -I/opt/homebrew/opt/python@3.13/Frameworks/Python.framework/Versions/3.13/include/python3.13 -c Modules/objc/block_support.m -o /var/folders/f2/2plv6q2n7l932m2x004jlw340000gn/T/tmpw493ws0b.build-temp/Modules/objc/block_support.o -g -fexceptions -fno-objc-arc -Wall -Wno-variadic-macros -Wstrict-prototypes -Wbad-function-cast -Wmissing-prototypes -Wformat=2 -W -Wpointer-arith -Wmissing-declarations -Wnested-externs -W -Wno-import -Wno-unknown-pragmas -Wshorten-64-to-32 -Werror -Wno-cast-function-type-mismatch -I/usr/include/ffi -fvisibility=hidden -g -UNDEBUG -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -DPyObjC_BUILD_RELEASE=1504
Modules/objc/block_support.m:39:5: error: unknown type name 'unsiged'; did you mean 'unsigned'?
   39 |     unsiged long int reserved;
      |     ^~~~~~~
      |     unsigned
1 error generated.
error: command '/usr/bin/clang' failed with exit code 1
An error occurred building editable wheel for pyobjc-core

Lots of open questions:

What's the right tradeoff between user-caused errors and internal errors? My instinct is that build_editable has been stable for a while now, so Setuptools can shift the burden to assume the error is on the user's side.

Should the code provide an escape hatch to get more detail? If so, what is the mechanism (environment variable, configuration setting like verbosity or debug, or something else)?

Is print the right way to emit a message that an error occurred? Should it be to stderr? Should some other mechanism (log) be used? I'm thinking the warnings module isn't appropriate here, but maybe I don't understand it well enough.

@jaraco jaraco requested review from abravalheri and Copilot May 6, 2025 21:03
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Aims to provide a more concise error message during editable wheel builds by conditionally printing the traceback only when internal debugging is enabled.

  • Removed unconditional traceback printing in favor of a conditional check on the environment variable
  • Replaced verbose traceback output with a concise error message when not debugging

traceback.print_exc()
_DebuggingTips.emit(project=project)
else:
print("An error occurred building editable wheel for", project)
Copy link
Preview

Copilot AI May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a logging mechanism (e.g., _logger.error) instead of print to ensure the error message is sent to the appropriate error stream and is consistently captured in the logs.

Suggested change
print("An error occurred building editable wheel for", project)
_logger.error("An error occurred building editable wheel for %s", project)

Copilot uses AI. Check for mistakes.

Copy link
Contributor

@abravalheri abravalheri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much @jaraco.

The ideal solution for me would be something like:

  • Move the debugging tips text from the _DebuggingTips class to the docs/userguide/development_mode.rst (and remove the class).

  • Use something like:

    try:
        ...
    except Exception as ex:
        ex.add_note(
            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

I think that would be a fine approach. However it depends on PEP 678 behaviour, which is implemented in 3.11 and is not trivial to backport.

So I think we have a couple of options:

  1. Simply remove the whole try...except... wrapper and let the method crash and bypass the complexity of add_note backporting.
  2. Implement something in compat.py311.add_note:
    2a. We can simply assign the __notes__ to the exception, and optimistically hope that frontends use something like rich which reads __notes__ regardless of the python version to render exceptions instead of using Python's default exception printing12
    2b. Use something simple like print(...) as used in this PR, or warnings.warn(...) or logging.warning as an imperfect replacement for add_note.
    2c. Implement a more complete backport by assigning __notes__ and adding a custom sys.excepthook to ensure they are printed even in Python 3.10. This may be non trivial because of the details and the cases where other packages are already customising sys.excepthook.

To be honest, I don't see much of a problem with option 1 or 2a.

Footnotes

  1. pip uses rich

  2. For Python <= 3.10, the default exception display mechanism will ignore __notes__.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Errors in editable builds are noisy, creating friction
2 participants