Skip to content

debug ¤

Debugging utilities.

Classes:

  • Environment

    Dataclass to store environment information.

  • Package

    Dataclass describing a Python package.

  • Variable

    Dataclass describing an environment variable.

Functions:

Environment dataclass ¤

Environment(
    interpreter_name: str,
    interpreter_version: str,
    platform: str,
    packages: list[Package],
    variables: list[Variable],
)

Dataclass to store environment information.

Attributes:

interpreter_name instance-attribute ¤

interpreter_name: str

Python interpreter name.

interpreter_version instance-attribute ¤

interpreter_version: str

Python interpreter version.

packages instance-attribute ¤

packages: list[Package]

Installed packages.

platform instance-attribute ¤

platform: str

Operating System.

variables instance-attribute ¤

variables: list[Variable]

Environment variables.

Package dataclass ¤

Package(name: str, version: str)

Dataclass describing a Python package.

Attributes:

name instance-attribute ¤

name: str

Package name.

version instance-attribute ¤

version: str

Package version.

Variable dataclass ¤

Variable(name: str, value: str)

Dataclass describing an environment variable.

Attributes:

name instance-attribute ¤

name: str

Variable name.

value instance-attribute ¤

value: str

Variable value.

get_debug_info ¤

get_debug_info() -> Environment

Get debug/environment information.

Returns:

Source code in src/pdm_multirun/debug.py
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def get_debug_info() -> Environment:
    """Get debug/environment information.

    Returns:
        Environment information.
    """
    py_name, py_version = _interpreter_name_version()
    packages = ["pdm-multirun"]
    variables = ["PYTHONPATH", *[var for var in os.environ if var.startswith("PDM_MULTIRUN")]]
    return Environment(
        interpreter_name=py_name,
        interpreter_version=py_version,
        platform=platform.platform(),
        variables=[Variable(var, val) for var in variables if (val := os.getenv(var))],
        packages=[Package(pkg, get_version(pkg)) for pkg in packages],
    )

get_version ¤

get_version(dist: str = 'pdm-multirun') -> str

Get version of the given distribution.

Parameters:

  • dist (str, default: 'pdm-multirun' ) –

    A distribution name.

Returns:

  • str

    A version number.

Source code in src/pdm_multirun/debug.py
59
60
61
62
63
64
65
66
67
68
69
70
71
def get_version(dist: str = "pdm-multirun") -> str:
    """Get version of the given distribution.

    Parameters:
        dist: A distribution name.

    Returns:
        A version number.
    """
    try:
        return metadata.version(dist)
    except metadata.PackageNotFoundError:
        return "0.0.0"

print_debug_info ¤

print_debug_info() -> None

Print debug/environment information.

Source code in src/pdm_multirun/debug.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def print_debug_info() -> None:
    """Print debug/environment information."""
    info = get_debug_info()
    print(f"- __System__: {info.platform}")
    print(f"- __Python__: {info.interpreter_name} {info.interpreter_version}")
    print("- __Environment variables__:")
    for var in info.variables:
        print(f"  - `{var.name}`: `{var.value}`")
    print("- __Installed packages__:")
    for pkg in info.packages:
        print(f"  - `{pkg.name}` v{pkg.version}")