Skip to content

Conversation

Tribhuvan0
Copy link
Contributor

@Tribhuvan0 Tribhuvan0 commented Sep 8, 2023

Adapts the color of progress bar according to the color of system background

What does this PR do?

Implemented RichProgressBarTheme with a new feature to detect the terminal background color and adjust the styles based on it. The terminal background color is detected using the Console class from the rich library. If the terminal supports truecolor, the TERMINAL_BG_COLOR environment variable is checked, otherwise, it is assumed to be a dark theme.

This implementation allows the RichProgressBar to be visible by default in both light and dark themes without requiring users to modify the theme.

Fixes #17118
Note: I am a beginner in open source, and haven't contributed to big codebases yet, if there is any issue please let me know

Before submitting
  • Was this discussed/agreed via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)

PR review

Anyone in the community is welcome to review the PR.
Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:

Reviewer checklist
  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

📚 Documentation preview 📚: https://pytorch-lightning--18505.org.readthedocs.build/en/18505/

Adapts the color of progress bar according to the color of system background
@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label Sep 8, 2023
@awaelchli awaelchli added feature Is an improvement or enhancement progress bar: rich community This PR is from the community labels Sep 8, 2023
@awaelchli awaelchli added this to the future milestone Sep 8, 2023
Copy link
Contributor

@awaelchli awaelchli left a comment

Choose a reason for hiding this comment

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

LGTM in general, thanks for working on it. A few tests will need updating:

FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_metrics_format[.3f] - TypeError: __init__() got an unexpected keyword argument 'metrics_format'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_keyboard_interrupt - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_metrics_format[.3e] - TypeError: __init__() got an unexpected keyword argument 'metrics_format'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_correct_value_epoch_end - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar[dataset0] - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_custom_theme - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_leave[False-3] - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_configure_columns - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_num_sanity_val_steps[5] - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_counter_with_val_check_interval - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_can_be_pickled - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_reset_bars - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_leave[True-0] - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_with_refresh_rate[1-2-3-6] - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_with_refresh_rate[7-6-6-3] - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_metric_display_task_id - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar[dataset1] - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_with_refresh_rate[1-0-0-0] - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_with_refresh_rate[3-5-0-2] - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_with_refresh_rate[3-1-1-3] - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_with_refresh_rate[3-6-6-5] - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_metrics_fast_dev_run - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_with_refresh_rate[3-5-2-4] - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_num_sanity_val_steps[1] - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_with_refresh_rate[4-6-6-5] - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_with_refresh_rate[6-5-2-3] - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_metrics_theme_update - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_format'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_with_refresh_rate[3-1-0-1] - AttributeError: 'RichProgressBarTheme' object has no attribute 'metrics_text_delimiter'
FAILED callbacks/progress/test_rich_progress_bar.py::test_rich_progress_bar_colab_light_theme_update - AssertionError: assert 'default' == 'black'
  - black
  + default
= 29 failed, 2750 passed, 446 skipped, 8 xfailed, 3809 warnings in 526.73s (0:08:46) =

You can run them locally like so

pip install -r requirements/pytorch/test.txt
py.test -v tests/tests_pytorch/callbacks/progress/test_rich_progress_bar.py

Comment on lines +210 to +213
@staticmethod
def detect_color_system() -> str:
console = Console()
return console.color_system
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't we make this a proper function?
Is this the recommended way how users should implement their themes with rich?

@manascb1344 manascb1344 mentioned this pull request Jan 7, 2024
5 tasks
Copy link

gitguardian bot commented Jan 16, 2024

⚠️ GitGuardian has uncovered 2 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id Secret Commit Filename
- Generic High Entropy Secret 78fa3af tests/tests_app/utilities/test_login.py View secret
- Base64 Basic Authentication 78fa3af tests/tests_app/utilities/test_login.py View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Our GitHub checks need improvements? Share your feedbacks!

@bhimrazy
Copy link
Collaborator

I think we can close this PR, since the original issue (#17118) has already been addressed in #20260.
cc: @Borda

@bhimrazy bhimrazy marked this pull request as draft August 28, 2025 10:28
@Borda Borda closed this Sep 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community This PR is from the community feature Is an improvement or enhancement has conflicts pl Generic label for PyTorch Lightning package progress bar: rich

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make RichProgressBar visible for both light and dark theme by default

4 participants