Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create show_versions.py #9144

Merged
merged 5 commits into from Jun 24, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 57 additions & 0 deletions dask/show_versions.py
@@ -0,0 +1,57 @@
from json import dumps
from platform import uname
from sys import stdout, version_info

from pandas._typing import JSONSerializable
from pandas.compat._optional import get_version, import_optional_dependency
SultanOrazbayev marked this conversation as resolved.
Show resolved Hide resolved


def show_versions(as_json: bool = False) -> None:
"""Provide version information for bug reports.

Parameters
----------
as_json : bool, default False
* If False, outputs info in a YAML format to the console (can be copy-
pasted into an environment.yml file for conda).
* If True, outputs info in JSON format to the console.
SultanOrazbayev marked this conversation as resolved.
Show resolved Hide resolved
"""

def _format_as_conda_environment_yaml(result: dict[str, JSONSerializable]) -> str:
"""A small utility to return dependencies in a conda-friendly format."""
formatted_result = ""
for dep, dep_ver in result.items():
if dep == "Platform" or dep_ver is None:
continue
formatted_result += f"- {dep}={dep_ver}"
formatted_result += "\n"

return formatted_result
SultanOrazbayev marked this conversation as resolved.
Show resolved Hide resolved

deps = [
"dask",
"distributed",
"numpy",
"pandas",
"cloudpickle",
"fsspec",
"bokeh",
"fastparquet",
"pyarrow",
"zarr",
]

result = {
# note: only major, minor, micro are extracted
"Python": ".".join([str(i) for i in version_info[:3]]),
"Platform": uname().system,
}

for modname in deps:
mod = import_optional_dependency(modname, errors="ignore")
SultanOrazbayev marked this conversation as resolved.
Show resolved Hide resolved
result[modname] = get_version(mod) if mod else None

if as_json is True:
stdout.writelines(dumps(result, indent=2))
elif as_json is False:
stdout.writelines(_format_as_conda_environment_yaml(result))