From 731f9848228e4cffede54ed2056b606b27a35ecb Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Fri, 4 Feb 2022 13:51:58 +0000 Subject: [PATCH 1/5] Expose diagnose.report as a function add a little more info to hint at environment --- .coveragerc | 3 ++- rich/diagnose.py | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/.coveragerc b/.coveragerc index ff1a046c0..2afac8dc6 100644 --- a/.coveragerc +++ b/.coveragerc @@ -2,7 +2,8 @@ omit = rich/jupyter.py rich/_windows.py rich/_timer.py - + rich/diagnose.py + [report] exclude_lines = pragma: no cover diff --git a/rich/diagnose.py b/rich/diagnose.py index 455e11dc0..7ecdff97f 100644 --- a/rich/diagnose.py +++ b/rich/diagnose.py @@ -1,6 +1,35 @@ -if __name__ == "__main__": # pragma: no cover - from rich.console import Console - from rich import inspect +import os +import platform + +from rich import inspect +from rich.console import Console, get_windows_console_features +from rich.panel import Panel +from rich.text import Text + + +def report(): # pragma: no cover + """Print a report to the terminal with debugging information""" + console = Console() + inspect(console) + features = get_windows_console_features() + inspect(features) + + if console.is_jupyter: + jpy_parent_pid = os.getenv("JPY_PARENT_PID") + vs_code_verbose = os.getenv("VSCODE_VERBOSE_LOGGING") + console.print( + Panel( + title="Jupyter Environment Hints", + renderable=Text( + f"JPY_PARENT_PID = {jpy_parent_pid}\n" + f"VSCODE_VERBOSE_LOGGING = {vs_code_verbose}" + ), + ), + ) + + console.print(f'platform="{platform.system()}"') + +if __name__ == "__main__": # pragma: no cover console = Console() inspect(console) From bdad740de91368814c331ea807f362e5bec73336 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Fri, 4 Feb 2022 14:10:12 +0000 Subject: [PATCH 2/5] Update issue template --- .github/ISSUE_TEMPLATE/bug_report.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 05cd2cd11..723781db8 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -20,12 +20,21 @@ Provide a minimal code example that demonstrates the issue if you can. If the is What platform (Win/Linux/Mac) are you running on? What terminal software are you using? -I may ask you to cut and paste the output of the following commands. It may save some time if you do it now. +I may ask you to copy and paste the output of the following commands. It may save some time if you do it now. + +If you're using Rich in a terminal: ``` -python -m rich.diagnose -python -m rich._windows +python -c "from rich.diagnose import report; report()" pip freeze | grep rich ``` - + +If you're using Rich in a Jupyter Notebook, run the following snippet in a cell +and paste the output in your bug report. + +```python +from rich.diagnose import report +report() +``` + From 29bc5dd4905c6bf8ec8d4fd8d789abbdfe5d6b92 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Fri, 4 Feb 2022 14:19:15 +0000 Subject: [PATCH 3/5] Add missing return type annotation to diagnose.report --- rich/diagnose.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rich/diagnose.py b/rich/diagnose.py index 7ecdff97f..7e8ad989b 100644 --- a/rich/diagnose.py +++ b/rich/diagnose.py @@ -7,7 +7,7 @@ from rich.text import Text -def report(): # pragma: no cover +def report() -> None: # pragma: no cover """Print a report to the terminal with debugging information""" console = Console() inspect(console) From bcbaed2b95b3f0ce4d5a72a5fc40274158d96bc9 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Fri, 4 Feb 2022 14:23:32 +0000 Subject: [PATCH 4/5] Added `rich.diagnose.report` note to CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4997ae325..0887ed394 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Add support for US spelling of "gray" in ANSI color names https://github.com/Textualize/rich/issues/1890 +- Added `rich.diagnose.report` to expose environment debugging logic as function https://github.com/Textualize/rich/pull/1917 ## [11.1.0] - 2022-01-28 From c8c2cf117f3510b1105c3fa5a93a811855f7f0b5 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Mon, 7 Feb 2022 10:06:36 +0000 Subject: [PATCH 5/5] Add more diagnose.report env variables, invoke from __main__ --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- rich/diagnose.py | 30 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 723781db8..6d6f45677 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -25,7 +25,7 @@ I may ask you to copy and paste the output of the following commands. It may sav If you're using Rich in a terminal: ``` -python -c "from rich.diagnose import report; report()" +python -m rich.diagnose pip freeze | grep rich ``` diff --git a/rich/diagnose.py b/rich/diagnose.py index 7e8ad989b..09c4e0622 100644 --- a/rich/diagnose.py +++ b/rich/diagnose.py @@ -4,7 +4,7 @@ from rich import inspect from rich.console import Console, get_windows_console_features from rich.panel import Panel -from rich.text import Text +from rich.pretty import Pretty def report() -> None: # pragma: no cover @@ -14,22 +14,22 @@ def report() -> None: # pragma: no cover features = get_windows_console_features() inspect(features) - if console.is_jupyter: - jpy_parent_pid = os.getenv("JPY_PARENT_PID") - vs_code_verbose = os.getenv("VSCODE_VERBOSE_LOGGING") - console.print( - Panel( - title="Jupyter Environment Hints", - renderable=Text( - f"JPY_PARENT_PID = {jpy_parent_pid}\n" - f"VSCODE_VERBOSE_LOGGING = {vs_code_verbose}" - ), - ), - ) + env_names = ( + "TERM", + "COLORTERM", + "CLICOLOR", + "NO_COLOR", + "TERM_PROGRAM", + "COLUMNS", + "LINES", + "JPY_PARENT_PID", + "VSCODE_VERBOSE_LOGGING", + ) + env = {name: os.getenv(name) for name in env_names} + console.print(Panel.fit((Pretty(env)), title="[b]Environment Variables")) console.print(f'platform="{platform.system()}"') if __name__ == "__main__": # pragma: no cover - console = Console() - inspect(console) + report()