Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-128595: Default to stdout isatty for colour detection instead of stderr#128498

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
hugovk merged 18 commits intopython:mainfromhugovk:3.14-color-default-stdout
Jan 20, 2025

Conversation

hugovk
Copy link
Member

@hugovkhugovk commentedJan 4, 2025
edited by bedevere-appbot
Loading

As suggested at#128317 (comment), default to checkingstdout'sisatty rather thanstderr's.

Also using the@force_not_colorized_test_class decorator from#127877 to run some tests without worrying about colour.

BeforeAfter
imageimage
imageimage
imageimage
imageimage

zanieb reacted with thumbs up emoji
@hugovk
Copy link
MemberAuthor

Should this be considered a bugfix to backport to 3.13, with its own issue and NEWS, or piggyback ongh-128317 for 3.14 only?

@erlend-aasland
Copy link
Contributor

Should this be considered a bugfix to backport to 3.13, with its own issue and NEWS, or piggyback ongh-128317 for 3.14 only?

I would say it deserves an issue and a NEWS entry. I'm fine with adding it to#128317 if it's not going to be backported. I'm leaning into calling it a bugfix.

hugovk reacted with thumbs up emoji

@hugovkhugovk changed the titleAdd test class helper to force no terminal colourDefault to stdout isatty for colour detection instead of stderrJan 5, 2025
@hugovkhugovk changed the titleDefault to stdout isatty for colour detection instead of stderrgh-128595: Default to stdout isatty for colour detection instead of stderrJan 7, 2025
@hugovkhugovk added the needs backport to 3.13bugs and security fixes labelJan 7, 2025
@hugovk
Copy link
MemberAuthor

Issue, NEWS and backport label applied.

erlend-aasland reacted with rocket emoji

@zanieb
Copy link
Contributor

Agree this sounds like a bug to me :)

@serhiy-storchaka
Copy link
Member

Why not check this for stdout and stderr separately? If the traceback is written to terminal, it should be colorized.

@hugovk
Copy link
MemberAuthor

Why not check this for stdout and stderr separately? If the traceback is written to terminal, it should be colorized.

For example, something like this?

-def can_colorize() -> bool:+def can_colorize(file=sys.stdout) -> bool:     if not sys.flags.ignore_environment:         if os.environ.get("PYTHON_COLORS") == "0":             return False@@ -49,7 +49,7 @@ def can_colorize() -> bool:         if os.environ.get("TERM") == "dumb":             return False-    if not hasattr(sys.stdout, "fileno"):+    if not hasattr(file, "fileno"):         return False      if sys.platform == "win32":@@ -62,6 +62,6 @@ def can_colorize() -> bool:             return False      try:-        return os.isatty(sys.stdout.fileno())+        return os.isatty(file.fileno())     except io.UnsupportedOperation:         return sys.stdout.isatty()

And then places liketraceback.py can do something like this?

 def _print_exception_bltin(exc, /):     file = sys.stderr if sys.stderr is not None else sys.__stderr__-    colorize = _colorize.can_colorize()+    colorize = _colorize.can_colorize(file=file)     return print_exception(exc, limit=BUILTIN_EXCEPTION_LIMIT, file=file, colorize=colorize)

@serhiy-storchaka
Copy link
Member

Yes, except that dynamic valuesys.stdout should not be used as the default value. UseNone and then replace it with the current value ofsys.stdout inside the function.

zanieb, hugovk, erlend-aasland, and vstinner reacted with thumbs up emoji

@vstinner
Copy link
Member

Can you extract the code to disable colors as a separated PR and merge it first?

@hugovk
Copy link
MemberAuthor

Sure! Please see PR#128687.

@hugovk
Copy link
MemberAuthor

Sure! Please see PR#128687.

Now merged, making this PR much simpler.

@serhiy-storchaka
Copy link
Member

Please implement what was discussed above.

hugovk reacted with thumbs up emoji

hugovkand others added4 commitsJanuary 13, 2025 19:00
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>Co-authored-by: Victor Stinner <vstinner@python.org>
hugovkand others added3 commitsJanuary 14, 2025 09:19
Co-authored-by: Victor Stinner <vstinner@python.org>
Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@hugovk
Copy link
MemberAuthor

Thanks again for the reviews!

Next to update#127877.

@hugovkhugovk merged commit6f167d7 intopython:mainJan 20, 2025
46 checks passed
@hugovkhugovk deleted the 3.14-color-default-stdout branchJanuary 20, 2025 10:52
@miss-islington-app
Copy link

Thanks@hugovk for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry,@hugovk, I could not cleanly backport this to3.13 due to a conflict.
Please backport usingcherry_picker on command line.

cherry_picker 6f167d71347de6717d9f6b64026e21f23d41ef0b 3.13

hugovk added a commit to hugovk/cpython that referenced this pull requestJan 20, 2025
… instead of stderr (pythonGH-128498)(cherry picked from commit6f167d7)Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>Co-authored-by: Victor Stinner <vstinner@python.org>
hugovk added a commit to hugovk/cpython that referenced this pull requestJan 20, 2025
… instead of stderr (pythonGH-128498)(cherry picked from commit6f167d7)Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-app
Copy link

GH-129057 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelJan 20, 2025
@picnixz
Copy link
Member

Some build bots are now failing (https://buildbot.python.org/api/v2/logs/12166870/raw_inline):

TypeError: setUpModule..() got an unexpected keyword argument 'file'

hugovk reacted with eyes emoji

@hugovk
Copy link
MemberAuthor

Please see PR#129070 for a fix.

srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull requestJan 21, 2025
…d of stderr (python#128498)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>Co-authored-by: Victor Stinner <vstinner@python.org>
hugovk added a commit that referenced this pull requestJan 21, 2025
…ad of stderr (GH-128498) (#129057)Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>Co-authored-by: Victor Stinner <vstinner@python.org>Fix `test__colorize` unexpected keyword argument 'file' on buildbots (#129070)
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@vstinnervstinnervstinner approved these changes

@serhiy-storchakaserhiy-storchakaserhiy-storchaka left review comments

Assignees

@hugovkhugovk

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@hugovk@erlend-aasland@zanieb@serhiy-storchaka@vstinner@picnixz

[8]ページ先頭

©2009-2025 Movatter.jp