west: add --color option to control output colorization#930
west: add --color option to control output colorization#930TharakaUJ wants to merge 2 commits intozephyrproject-rtos:mainfrom
Conversation
|
I initially considered adding support for a Also for now 'auto' value just initialize Let me know if any changes to be made. |
|
This change would be very welcome with regards to environments like VS Code where executing child processes like |
|
Thanks @TharakaUJ ! Can you please run |
|
Thanks! I ran |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #930 +/- ##
==========================================
- Coverage 85.95% 85.84% -0.12%
==========================================
Files 11 11
Lines 3454 3511 +57
==========================================
+ Hits 2969 3014 +45
- Misses 485 497 +12
|
|
@TharakaUJ thanks for the PR, I still need to do a full review, but I wonder if we could test this somehow. Codecov coverage shows that most of the changes isn't even executed during testing. |
ok. I will look into adding test cases. Thank you! |
|
Make sure to run the formatter on the newly added tests, thanks! |
|
Thanks, applied the suggestion. |
|
@TharakaUJ please squash and force-push, the zephyrproject cares about git history and does not accept "fixup" commits in it (like 147920c)
|
|
Thank you. Squashed the fixup commit. |
There was a problem hiding this comment.
Sorry I really don't understand why we need this new cmd._color_override field and new override function. It should be possible to keep all the logic centralized in a single accessor like color_ui() rather than scattered in different places like this, why not?
BTW you can probably remove some of the if self.color_ui checks in the code to simplify it now that this PR uses colorama.init(strip=True) (some other places will likely still need that check).
Last but not least: make sure you test thoroughly on both Linux and Windows. I started to do some manual testing that I will summarize soon in #651 (EDIT: done) and I found some existing issues even before this PR. Fixing them is out of scope for this PR but we have to be sure this #930 is not making anything worse. Also, #651 provides a good list of manual tests.
src/west/app/main.py
Outdated
| config_value = self.config.get('color.ui', 'auto') | ||
| # Handle both string values (always/never/auto) and | ||
| # boolean values (true/false) for backward compatibility | ||
| if config_value in ('always', 'true', 'True', '1'): |
There was a problem hiding this comment.
I don't think we can do that because color.ui=True (or 1, etc.) had no effect since forever. Now with this PR it becomes always. That could seriously mess up some CI logs and others.
I think it's OK for True and always to have different meanings.
src/west/app/main.py
Outdated
| elif color_mode == 'never': | ||
| colorama.init(strip=True) | ||
| else: | ||
| # 'auto' or None: use colorama's default behavior |
There was a problem hiding this comment.
| # 'auto' or None: use colorama's default behavior | |
| # 'auto' or None or "true": defer to colorama's terminal detection |
src/west/app/main.py
Outdated
| color_mode = self.color_mode | ||
|
|
||
| if color_mode is None and self.config: | ||
| config_value = self.config.get('color.ui', 'auto') |
There was a problem hiding this comment.
We don't want to access self.config.get('color.ui',... in two different places in the code, this seems too complicated and too high-maintenance. You can read the config value at a different time and place if there's a good reason for that, but don't add a new place while keeping the old place.
grep.color and other quirks add enough complexity already :-(
There was a problem hiding this comment.
Please keep using getboolean() and catch the ValueError when it's always or never rather than duplicating the special values from configparser.
|
Thank you the detailed feedback. I will look into necessary changes. |
Add a global --color option with values 'always', 'never', and 'auto' to override automatic terminal detection. The command-line option takes precedence over configuration settings. When provided, it overrides the value returned by WestCommand.color_ui. Signed-off-by: Tharaka Jayasena <9dmpires2k17.tuj@gmail.com>
Add tests for: - CLI override precedence in WestCommand.color_ui - behavior with and without configuration - parsing of the new --color argument in parse_early_args Signed-off-by: Tharaka Jayasena <9dmpires2k17.tuj@gmail.com>
|
I made some changes and force pushed. I thought a early review might helpful to stay on needed track. |
Got rid of most of the _color_override logic. But still could not centralize all the logic, mainly because I'm not sure whether calling |
Thanks and thanks for the heads-up.
Why would we need Ideally, the only color-related code in WestCommands should be decisions like "how important is this log message?" and never "What does the user/configuration/terminal want?". OK, now I just realized we haven't looked at colorization from a west API perspective... no idea what is the colorization status there :-( |
Add a global --color option with values 'always', 'never', and 'auto' to override automatic terminal detection.
The command-line option takes precedence over configuration settings. When provided, it overrides the value returned by WestCommand.color_ui.
fixes #651