GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Use color to highlight error locations · Issue #112730 · python/cpython

Use color to highlight error locations #112730

New issue
Copy link
New issue
Copy link
Closed
Closed
Use color to highlight error locations#112730
Copy link
Labels
3.13only security fixesonly security fixestype-featureA feature request or enhancementA feature request or enhancement

Description

@pablogsal
pablogsal
opened on Dec 4, 2023
Issue body actions

This has several advantages:

  • Will help a lot with readability as parsing the error lines is easier if color highlights the error ranges.
  • In the future we can optionally (via config) drop the ranges and only use color, recovering back the extra lines that the carets are taking.
  • All the cool kids are doing it: This feature has already been successfully implemented in various tools. It has proven to be an effective aid for developers in quickly identifying the source and location of errors.

Control features:

  • The feature will use 16 ANSI color scapes so the actual color is configured via the terminal emulator.
  • Users can set the following env vars to control it (in the following order):
    • PY_COLORS=1 activates the feature (used by pytest: https://github.com/pytest-dev/pytest/blob/022f1b4de546c8b3529e071965555888ecf01cb4/src/_pytest/_io/terminalwriter.py#L28)
    • PY_COLORS=0 deactivates the feature
    • NO_COLOR=1 deactivates the feature
    • FORCE_COLOR=1 activates the feature
    • Feature is deactivated if terminal is not a tty or if TERM is set to dumb.

Linked PRs

  • gh-112730: Use color to highlight error locations #112732
  • gh-112730: Update docs for colour env vars #112837
  • gh-112730: Make the test suite resilient to color-activation environment variables #117672
  • gh-112730: use keyword only argument for colorize #118086
  • gh-112730: Respect tests that require environment variables with no-colorize fixes #118288
Reacted by André Roberge, Rajarishi Devarajan, tuxayo and Yashas G V
Reacted by Hugo van Kemenade, Kirill Podoprigora, Erlend E. Aasland, baggiponte, itzAkari, Mohamed El Mouctar Haidara, Alex Waygood, Rajarishi Devarajan and tuxayo

Activity

Next
  1. pablogsal
    added 2 commits that reference this issue on Dec 4, 2023

    pythongh-112730: Use color to highlight error locations

    b0d9a03

    pythongh-112730: Use color to highlight error locations

    bc6e729
  2. pablogsal
    assigned
    ambv
    and unassigned
    ambv
    on Dec 4, 2023
  3. pablogsal
    added 6 commits that reference this issue on Dec 4, 2023

    pythongh-112730: Use color to highlight error locations

    c40cb47

    pythongh-112730: Use color to highlight error locations

    74c1a84

    pythongh-112730: Use color to highlight error locations

    2fc1050

    pythongh-112730: Use color to highlight error locations

    182fae6

    pythongh-112730: Use color to highlight error locations

    9c7387e

    pythongh-112730: Use color to highlight error locations

    9bc06ed
  4. hugovk commented on Dec 5, 2023

    @hugovk
    hugovk
    on Dec 5, 2023
    Member
    More actions

    This looks really good, thanks!

    Perhaps something for a followup, can we customise the colouring a bit?

    PR #112732 right now:

    image

    GitHub / MagicPython

    GitHub markdown (with pytb after the triple backticks):

    Traceback (most recent call last):
      File "/Users/hugo/github/python/cpython/main/1.py", line 1, in <module>
        1/0
        ~^~
    ZeroDivisionError: division by zero
    (GitHub screenshot)

    image

    (Uses https://github.com/MagicStack/MagicPython for Python tracebacks: https://github.com/github-linguist/linguist/blob/master/vendor/README.md)

    Sphinx / pygments

    Sphinx with .. code-block:: pytb, for example on the PEPs repo:

    image

    (Uses Pygments' Native style)

  5. pablogsal commented on Dec 5, 2023

    @pablogsal
    pablogsal
    on Dec 5, 2023
    MemberAuthor
    More actions

    Perhaps something for a followup, can we customise the colouring a bit?

    Yup, see #112732 (comment).

    I want to explore customization options AFTER we land the basic version first. EDIT Or are you referring to customizing the coloring as "adding more colors"?

    On the other hand, are you suggesting to also colorize the name of the exception, the file, the number and the Traceback text?

    I have been told that yellow and cian are really bad for light mode, so we should do something else there.

  6. pablogsal commented on Dec 5, 2023

    @pablogsal
    pablogsal
    on Dec 5, 2023
    MemberAuthor
    More actions

    @hugovk What about like this?

    Screenshot 2023-12-05 at 14 11 59
    Screenshot 2023-12-05 at 14 12 54

  7. hugovk commented on Dec 5, 2023

    @hugovk
    hugovk
    on Dec 5, 2023
    Member
    More actions

    I wasn't thinking about allowing the user to customise them (although that's something to consider) but about having different colours for the different elements (exception name, file, etc).

    Yes, we should check the contrast is good for both light and dark modes.

    The GitHub colours (ignoring the plain black/white text) look the same for each mode and display well for both:

    image

    image

    edit: and the blues are different, but you get the idea :)

  8. pablogsal commented on Dec 5, 2023

    @pablogsal
    pablogsal
    on Dec 5, 2023
    MemberAuthor
    More actions

    I am quite colorblind myself 😅 Do you mind telling me what colors are supposed to be every piece? As in "filename is ..., line number is ...., function name is ..., source code is ..., error location is ...)

    Reacted by Hugo van Kemenade
  9. 19 remaining items

  10. pablogsal commented on Apr 8, 2024

    @pablogsal
    pablogsal
    on Apr 8, 2024
    MemberAuthor
    More actions

    Maybe we could just add a support decorator that just does the appropriate monkey patching in the colorise function to avoid being affected by the force colours variable. To avoid regressions, setting FORCE_COLORS in GH actions sounds like a good idea.

    Reacted by Alex Waygood
  11. pablogsal commented on Apr 8, 2024

    @pablogsal
    pablogsal
    on Apr 8, 2024
    MemberAuthor
    More actions

    I personally think it's very useful for Python to use the same env vars that are being increasingly widely adopted elsewhere. So I suppose I lean towards changing -E so that it also ignores the FORCE_COLOR variable.

    I think if we don't do this it's going to be a full pain for us and a lot of users that have the variable set in CI and are running subprocesses in tests

  12. pablogsal
    added a commit that references this issue on Apr 9, 2024

    pythongh-112730: Make the test suite relient to color-activation envi…

    e08e26c
  13. methane
    added 2 commits that reference this issue on Apr 19, 2024

    pythongh-112730: use keyword only argument for colorize

    3f59131

    pythongh-112730: use keyword only argument for colorize

    d48bfc3
  14. pablogsal
    added a commit that references this issue on Apr 24, 2024

    gh-112730: Make the test suite resilient to color-activation environm…

    345e1e0
  15. encukou commented on Apr 25, 2024

    @encukou
    encukou
    on Apr 25, 2024
    Member
    More actions

    #117672 broke several stable buildbots, see e.g. here. As Jakub noted they seem to be --enable-shared builds that rely on LD_LIBRARY_PATH to find libpython.

    Do you have time to look into this?

  16. pablogsal commented on Apr 25, 2024

    @pablogsal
    pablogsal
    on Apr 25, 2024
    MemberAuthor
    More actions

    I will look into this today. We can revert in the meanwhile if you wish

  17. pablogsal
    added 2 commits that reference this issue on Apr 25, 2024

    pythongh-112730: Respect tests that require environment variables wit…

    5db08d0

    gh-112730: Respect tests that require environment variables with no-c…

    b43c7e1
  18. pablogsal commented on Apr 26, 2024

    @pablogsal
    pablogsal
    on Apr 26, 2024
    MemberAuthor
    More actions

    I think this will be fixed by #118288

    Reacted by Petr Viktorin
  19. hugovk commented on Jun 15, 2024

    @hugovk
    hugovk
    on Jun 15, 2024
    Member
    More actions

    #118288 has been merged, closing.

  20. hugovk
    closed this as completedon Jun 15, 2024
  21. Glyphack
    added 2 commits that reference this issue on Sep 2, 2024

    pythongh-112730: Use color to highlight error locations (pythongh-112732

    37e5f1e

    pythongh-112730: Update docs for colour env vars (python#112837)

    5e33ba2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixesonly security fixestype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.