Skip to content

fix(logging): auto-detect rich only on a terminal or in Jupyter - #112

Open
timtreis wants to merge 3 commits into
scverse:mainfrom
timtreis:fix/logging-rich-only-tty
Open

timtreis wants to merge 3 commits into
scverse:mainfrom
timtreis:fix/logging-rich-only-tty

Conversation

@timtreis

Copy link
Copy Markdown
Member

Summary: With config.rich = None (the default), the shared logger now uses rich only when stderr is a terminal or a Jupyter kernel. In CI logs, log files and pipes it falls back to the plain handler, which writes one line per record.

Outside a terminal, rich sets the console width to 80 columns. Its log layout is a table that expands to the full console width, so long messages wrap onto several lines and every line is padded with trailing spaces. Setting soft_wrap=True on the console doesn't change the layout, because the table expands regardless.

Changes:

  • A new _auto_rich() returns true when rich is installed and Console(stderr=True).is_terminal or .is_jupyter holds. rich's own terminal check also respects FORCE_COLOR and TTY_COMPATIBLE.
  • config.rich = True still forces rich everywhere.
  • Notebooks keep rich output. Docs builds that hide stderr with myst-nb nb_output_stderr = "remove" still show rich log lines, because rich sends them as display data in a kernel. Such builds can set config.rich = False, or SCVERSE_RICH=0 after the env var PR.

@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.83333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 94.26%. Comparing base (055df50) to head (6d9f5ba).

Files with missing lines Patch % Lines
src/scverse_misc/logging.py 95.83% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #112      +/-   ##
==========================================
- Coverage   94.31%   94.26%   -0.06%     
==========================================
  Files          13       13              
  Lines         845      854       +9     
==========================================
+ Hits          797      805       +8     
- Misses         48       49       +1     
Files with missing lines Coverage Δ
src/scverse_misc/logging.py 97.40% <95.83%> (+0.85%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

1 participant