def METHOD_NAME(kernel: Optional[str] = None):
    kernelspecs = loads(subprocess.check_output(["jupyter", "kernelspec", "list", "--json"]))
    check.invariant(len(kernelspecs["kernelspecs"]) > 0, "No available Jupyter kernelspecs!")
    if kernel is None:
        preferred_kernels = list(
            filter(
                lambda kernel_name: kernel_name in kernelspecs["kernelspecs"],
                ["dagster", "python3", "python"],
            )
        ) + list(kernelspecs["kernelspecs"].keys())
        kernel = preferred_kernels[0]
        print(f"No kernel specified, defaulting to '{kernel}'")  # noqa: T201
    check.invariant(
        kernel in kernelspecs["kernelspecs"],
        "Could not find kernel '{kernel}': available kernels are [{kernels}]".format(
            kernel=kernel,
            kernels=", ".join([f"'{k}'" for k in kernelspecs["kernelspecs"]]),
        ),
    )
    return {
        "name": kernel,
        "language": kernelspecs["kernelspecs"][kernel]["spec"]["language"],
        "display_name": kernelspecs["kernelspecs"][kernel]["spec"]["display_name"],
    }