diff --git a/.flake8 b/.flake8 index ac93b71e..8d012648 100644 --- a/.flake8 +++ b/.flake8 @@ -1,4 +1,4 @@ [flake8] -exclude=build,tests,tmp,venv,toot/tui/scroll.py +exclude=build,tests,tmp,venv,_env,toot/tui/scroll.py ignore=E128,W503,W504 max-line-length=120 diff --git a/toot/cli/__init__.py b/toot/cli/__init__.py index a4698ff9..f5258410 100644 --- a/toot/cli/__init__.py +++ b/toot/cli/__init__.py @@ -173,6 +173,7 @@ def cli(ctx: click.Context, max_width: int, color: bool, debug: bool, as_user: s from toot.cli import accounts # noqa from toot.cli import auth # noqa +from toot.cli import diag # noqa from toot.cli import lists # noqa from toot.cli import post # noqa from toot.cli import read # noqa diff --git a/toot/cli/diag.py b/toot/cli/diag.py new file mode 100644 index 00000000..39ff73f6 --- /dev/null +++ b/toot/cli/diag.py @@ -0,0 +1,14 @@ +from toot.output import print_diags +from toot.cli import ( + cli, + pass_context, + Context, +) + + +@cli.command() +@pass_context +def diag(ctx: Context): + """Display useful information for diagnosing problems""" + + print_diags() diff --git a/toot/output.py b/toot/output.py index e9b08120..74fc70c8 100644 --- a/toot/output.py +++ b/toot/output.py @@ -314,6 +314,41 @@ def format_account_name(account: Account) -> str: return acct +def print_diags(): + from importlib.metadata import version + + click.echo(f'{green(f"Diagnostic Information")}') + from datetime import datetime, timezone + + now = datetime.now(timezone.utc) + click.echo(f'{green("Current Date/Time:")} {now.strftime("%Y-%m-%d %H:%M:%S %Z")}') + + import platform + click.echo(f'{green(f"Platform:")} {platform.platform()}') + +# Uncomment this when we move to minimum Python version 3.10 +# try: +# name = platform.freedesktop_os_release()['PRETTY_NAME'] +# click.echo(f'{green(f"Distro:")} {name}') +# except: # noqa +# pass + + click.echo(f'{green(f"Python version:")} {platform.python_version()}') + click.echo(green("Dependency versions:")) + + deps = ['beautifulsoup4', 'click', 'requests', 'tomlkit', 'urwid', 'wcwidth', + 'pillow', 'term-image', 'urwidgets', 'flake8', 'pytest', 'setuptools', + 'vermin', 'typing-extensions'] + + for dep in deps: + try: + ver = version(dep) + except: # noqa + ver = yellow("not installed") + + click.echo(f"\t{dep}: {ver}") + + # Shorthand functions for coloring output def blue(text: t.Any) -> str: