Skip to content

reprexlite.session_info

Classes

Package

Package(distribution: Distribution)

Interface for adapting importlib.metadata.Distribution instances for introspection by SessionInfo.

Source code in reprexlite/session_info.py
44
45
def __init__(self, distribution: importlib.metadata.Distribution):
    self.distribution = distribution

SessionInfo

SessionInfo()

Class for pretty-formatting Python session info. Includes details about your Python version, your operating system, and the Python packages installed in your current environment.

Attributes:

Name Type Description
python_version str

Python version for current session

python_build_date str

Date

os str

OS information for current session

packages List[Package]

List of Python packages installed in current virtual environment.

Source code in reprexlite/session_info.py
17
18
19
20
21
22
23
24
def __init__(self) -> None:
    self.python_version: str = platform.python_version()
    self.python_build_date: str = platform.python_build()[1]

    self.os: str = platform.platform()
    self.packages: List[Package] = [
        Package(distr) for distr in importlib.metadata.Distribution.discover()
    ]

Functions

tabulate

tabulate(rows: List[Tuple[str, str]]) -> List[str]

Utility function for printing a two-column table as text with whitespace padding.

Parameters:

Name Type Description Default
rows List[Tuple[str, str]]

Rows of table as tuples of (left cell, right cell)

required

Returns:

Type Description
List[str]

Rows of table formatted as strings with whitespace padding

Source code in reprexlite/session_info.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def tabulate(rows: List[Tuple[str, str]]) -> List[str]:
    """Utility function for printing a two-column table as text with whitespace padding.

    Args:
        rows (List[Tuple[str, str]]): Rows of table as tuples of (left cell, right cell)

    Returns:
        Rows of table formatted as strings with whitespace padding
    """
    left_max = max(len(row[0]) for row in rows)
    out = []
    for left, right in rows:
        padding = (left_max + 1 - len(left)) * " "
        out.append(left + padding + right)
    return out