Implementation:Bentoml BentoML CLI Env
| Knowledge Sources | |
|---|---|
| Domains | CLI, Environment, Diagnostics |
| Last Updated | 2026-02-13 15:00 GMT |
Overview
Implements the bentoml env CLI command that prints system environment information for debugging and issue reporting, supporting markdown and bash output formats.
Description
This module provides the env_command Click command which collects and displays comprehensive environment information. It gathers: BentoML version, Python version, platform details, user/group IDs (or Windows admin status), conda environment details (if CONDA_PREFIX is set, including conda/mamba/micromamba detection and conda env export output), and pip package list (via uv pip freeze). The collected information is formatted in either markdown (with collapsible details sections for package lists) or bash (as shell variable assignments) format via pretty_format.
The module defines two lists of environment variables: _ENVVAR (always displayed, including BENTOML_DEBUG, BENTOML_QUIET, BENTOML_PORT, etc.) and _CONDITIONAL_ENVVAR (only displayed if set, including CUDA_VISIBLE_DEVICES, thread count variables, etc.). Helper functions include run_cmd for capturing subprocess output, _format_dropdown for creating HTML details/summary blocks, and format_md/format_bash for the two output modes.
Usage
Use bentoml env when diagnosing issues, creating bug reports, or inspecting the runtime environment of a BentoML installation.
Code Reference
Source Location
- Repository: Bentoml_BentoML
- File: src/bentoml_cli/env.py
- Lines: 1-173
Signature
def run_cmd(cmd: list[str]) -> list[str]: ...
def _format_dropdown(title: str, content: t.Iterable[str]) -> str: ...
def _format_env(env: list[str]) -> list[str]: ...
def format_md(env: list[str], info_dict: dict[str, str | list[str]]) -> list[str]: ...
def format_bash(env: list[str], info_dict: dict[str, str | list[str]]) -> list[str]: ...
def pretty_format(info_dict: dict[str, str | list[str]], output: t.Literal["md", "bash"]) -> str: ...
@click.command(name="env")
@click.option("-o", "--output", type=click.Choice(["md", "bash"]), default="md")
@click.pass_context
def env_command(ctx: click.Context, output: t.Literal["md", "bash"]) -> None: ...
Import
from bentoml_cli.env import env_command
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| output | Literal["md", "bash"] | No | Output format; defaults to "md" (markdown). Use "bash" for shell-compatible format |
Outputs
| Name | Type | Description |
|---|---|---|
| (stdout) | str | Formatted environment information printed to the console via rich.print |
Usage Examples
# Command line usage:
# bentoml env # Output in markdown format
# bentoml env -o bash # Output in bash format
# bentoml env -o md # Output in markdown format (explicit)
# Example markdown output includes:
# #### Environment variable
# ```bash
# BENTOML_DEBUG=
# BENTOML_QUIET=
# ...
# ```
# #### System information
# `bentoml`: 1.x.x
# `python`: 3.x.x
# `platform`: Linux-...