4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
"""Output format probe — what shape should rendered output take.
|
|
|
|
Pure env/TTY check. No injection needed — every caller wants the same
|
|
answer for a given process. Returns one of :data:`OUTPUT_FORMAT_RICH`,
|
|
:data:`OUTPUT_FORMAT_TEXT`, or :data:`OUTPUT_FORMAT_NONE` (callers
|
|
typically compare against the named constant rather than the bare
|
|
string).
|
|
|
|
Caller is responsible for honoring the verdict.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
|
|
# Output-format return values. Use these constants in callers instead
|
|
# of the bare strings so a future rename happens in one place.
|
|
OUTPUT_FORMAT_RICH = "rich"
|
|
OUTPUT_FORMAT_TEXT = "text"
|
|
OUTPUT_FORMAT_NONE = "none"
|
|
|
|
# Env-var keys the probe consults, in priority order. Named constants
|
|
# match the rest of the observability surface (``HERMES_LOG_PATH`` etc.)
|
|
# and make ``grep`` for "who reads TRACER_OUTPUT_FORMAT" trivial.
|
|
_ENV_OUTPUT_FORMAT = "TRACER_OUTPUT_FORMAT"
|
|
_ENV_NO_COLOR = "NO_COLOR"
|
|
_ENV_SLACK_WEBHOOK = "SLACK_WEBHOOK_URL"
|
|
|
|
|
|
def get_output_format() -> str:
|
|
"""Return one of the ``OUTPUT_FORMAT_*`` constants based on env + TTY.
|
|
|
|
Priority order:
|
|
1. ``TRACER_OUTPUT_FORMAT`` env var — explicit override wins.
|
|
2. ``NO_COLOR`` set (any value) — force text.
|
|
3. ``SLACK_WEBHOOK_URL`` set — force text (Slack-bound output).
|
|
4. Default: rich if stdout is a TTY, text otherwise.
|
|
"""
|
|
if fmt := os.getenv(_ENV_OUTPUT_FORMAT):
|
|
return fmt
|
|
if os.getenv(_ENV_NO_COLOR) is not None:
|
|
return OUTPUT_FORMAT_TEXT
|
|
if os.getenv(_ENV_SLACK_WEBHOOK):
|
|
return OUTPUT_FORMAT_TEXT
|
|
return OUTPUT_FORMAT_RICH if sys.stdout.isatty() else OUTPUT_FORMAT_TEXT
|