Implementation:Huggingface Datasets EnvironmentCommand
Overview
EnvironmentCommand is a CLI command class that prints system environment information useful for debugging and issue reporting. It extends BaseDatasetsCLICommand and provides an env subcommand that collects version information for the datasets library, Python, key dependencies (PyArrow, pandas, fsspec, huggingface_hub), and the operating system platform, then formats and prints it.
Source File
| Property | Value |
|---|---|
| Repository | huggingface/datasets |
| File | src/datasets/commands/env.py |
| Lines | 41 |
| Domain | CLI, Diagnostics |
Import
from datasets.commands.env import EnvironmentCommand
Class: EnvironmentCommand
Inherits from: BaseDatasetsCLICommand
Constructor
The constructor takes no arguments. The class is instantiated via info_command_factory, which ignores the parsed arguments.
Methods
register_subcommand(parser)
Static method. Registers the env subcommand with the argument parser. No additional arguments are defined beyond the subcommand name itself.
@staticmethod
def register_subcommand(parser: ArgumentParser):
download_parser = parser.add_parser("env", help="Print relevant system environment info.")
download_parser.set_defaults(func=info_command_factory)
run()
Collects system environment information into a dictionary and prints it in a formatted list. The collected information includes:
datasetslibrary version- Platform (OS and architecture)
- Python version
huggingface_hubversion- PyArrow version
- Pandas version
fsspecversion
The output is prefixed with instructions to copy-paste into a GitHub issue.
def run(self):
info = {
"`datasets` version": version,
"Platform": platform.platform(),
"Python version": platform.python_version(),
"`huggingface_hub` version": huggingface_hub.__version__,
"PyArrow version": pyarrow.__version__,
"Pandas version": pandas.__version__,
"`fsspec` version": fsspec.__version__,
}
print("\nCopy-and-paste the text below in your GitHub issue.\n")
print(self.format_dict(info))
return info
format_dict(d)
Static method. Formats a dictionary as a newline-separated list of - key: value pairs, suitable for pasting into Markdown-formatted issue reports.
@staticmethod
def format_dict(d):
return "\n".join([f"- {prop}: {val}" for prop, val in d.items()]) + "\n"
I/O
| Direction | Description |
|---|---|
| Input | No arguments required (the env subcommand takes no parameters)
|
| Output | Prints formatted environment information to stdout; returns the info dictionary |
Example Output
Copy-and-paste the text below in your GitHub issue. - `datasets` version: 3.2.0 - Platform: Linux-6.14.0-1018-aws-x86_64-with-glib2.35 - Python version: 3.10.12 - `huggingface_hub` version: 0.20.1 - PyArrow version: 14.0.2 - Pandas version: 2.1.4 - `fsspec` version: 2023.12.2
Dependencies
| Module | Purpose |
|---|---|
platform |
OS and Python version detection |
fsspec |
Filesystem spec library version |
huggingface_hub |
Hub client library version |
pandas |
Pandas library version |
pyarrow |
PyArrow library version |
datasets.__version__ |
Datasets library version |
datasets.commands.BaseDatasetsCLICommand |
Abstract base class for CLI commands |
Usage
# Print environment information for debugging
datasets-cli env
Related Pages
- Huggingface_Datasets_Datasets_CLI
- Huggingface_Datasets_TestCommand
- Huggingface_Datasets_DeleteFromHubCommand