# Path: coconut/constants.py
# def fixpath(path):
# def str_to_bool(boolstr, default=False):
# WINDOWS = os.name == "nt"
# PYPY = platform.python_implementation() == "PyPy"
# CPYTHON = platform.python_implementation() == "CPython"
# PY32 = sys.version_info >= (3, 2)
# PY33 = sys.version_info >= (3, 3)
# PY34 = sys.version_info >= (3, 4)
# PY35 = sys.version_info >= (3, 5)
# PY36 = sys.version_info >= (3, 6)
# PY38 = sys.version_info >= (3, 8)
# PY310 = sys.version_info >= (3, 10)
# IPY = (
#     ((PY2 and not PY26) or PY35)
#     and not (PYPY and WINDOWS)
#     # necessary until jupyter-console fixes https://github.com/jupyter/jupyter_console/issues/245
#     and not PY310
# )
# MYPY = (
#     PY34
#     and not WINDOWS
#     and not PYPY
# )
# PURE_PYTHON = str_to_bool(os.environ.get(pure_python_env_var, ""))


from coconut.root import *  # NOQA
from zlib import crc32
from warnings import warn
from types import MethodType
from coconut.constants import (
    fixpath,
    default_encoding,
    icoconut_custom_kernel_dir,
    icoconut_custom_kernel_install_loc,
    icoconut_custom_kernel_file_loc,
    WINDOWS,
    reserved_prefix,
)
    from _pytest.assertion.rewrite import rewrite_asserts  # hidden since it's not always available
import sys
import os
import shutil
import json
import traceback
import time
import ast
    install_custom_kernel(executable)
    return [
        (
            icoconut_custom_kernel_install_loc,
            [icoconut_custom_kernel_file_loc],
        ),
    ]


def install_custom_kernel(executable=None, logger=None):
    """Force install the custom kernel."""
    kernel_source = os.path.join(icoconut_custom_kernel_dir, "kernel.json")
    kernel_dest = fixpath(os.path.join(sys.exec_prefix, icoconut_custom_kernel_install_loc))
    try:
        make_custom_kernel(executable)
        if not os.path.exists(kernel_dest):
            os.makedirs(kernel_dest)
        shutil.copy(kernel_source, kernel_dest)
    except OSError:
        existing_kernel = os.path.join(kernel_dest, "kernel.json")
        if os.path.exists(existing_kernel):
            if logger is not None:
                logger.log_exc()
            errmsg = "Failed to update Coconut Jupyter kernel installation; the 'coconut' kernel might not work properly as a result"
        else:
            if logger is None:
                traceback.print_exc()
            else:
                logger.print_exc()
            errmsg = "Coconut Jupyter kernel installation failed due to above error"

# Path: coconut/constants.py
# def fixpath(path):
# def str_to_bool(boolstr, default=False):
# WINDOWS = os.name == "nt"
# PYPY = platform.python_implementation() == "PyPy"
# CPYTHON = platform.python_implementation() == "CPython"
# PY32 = sys.version_info >= (3, 2)
# PY33 = sys.version_info >= (3, 3)
# PY34 = sys.version_info >= (3, 4)
# PY35 = sys.version_info >= (3, 5)
# PY36 = sys.version_info >= (3, 6)
# PY38 = sys.version_info >= (3, 8)
# PY310 = sys.version_info >= (3, 10)
# IPY = (
#     ((PY2 and not PY26) or PY35)
#     and not (PYPY and WINDOWS)
#     # necessary until jupyter-console fixes https://github.com/jupyter/jupyter_console/issues/245
#     and not PY310
# )
# MYPY = (
#     PY34
#     and not WINDOWS
#     and not PYPY
# )
# PURE_PYTHON = str_to_bool(os.environ.get(pure_python_env_var, ""))


# Path: coconut/util.py
from coconut.root import *  # NOQA
from zlib import crc32
from warnings import warn
from types import MethodType
from coconut.constants import (
    fixpath,
    default_encoding,
    icoconut_custom_kernel_dir,
    icoconut_custom_kernel_install_loc,
    icoconut_custom_kernel_file_loc,
    WINDOWS,
    reserved_prefix,
)
    from _pytest.assertion.rewrite import rewrite_asserts  # hidden since it's not always available
import sys
import os
import shutil
import json
import traceback
import time
import ast

    install_custom_kernel(executable)
    return [
        (
            icoconut_custom_kernel_install_loc,
            [icoconut_custom_kernel_file_loc],
        ),
    ]


def install_custom_kernel(executable=None, logger=None):
    """Force install the custom kernel."""
    kernel_source = os.path.join(icoconut_custom_kernel_dir, "kernel.json")
    kernel_dest = fixpath(os.path.join(sys.exec_prefix, icoconut_custom_kernel_install_loc))
    try:
        make_custom_kernel(executable)
        if not os.path.exists(kernel_dest):
            os.makedirs(kernel_dest)
        shutil.copy(kernel_source, kernel_dest)
    except OSError:
        existing_kernel = os.path.join(kernel_dest, "kernel.json")
        if os.path.exists(existing_kernel):
            if logger is not None:
                logger.log_exc()
            errmsg = "Failed to update Coconut Jupyter kernel installation; the 'coconut' kernel might not work properly as a result"
        else:
            if logger is None:
                traceback.print_exc()
            else:
                logger.print_exc()
            errmsg = "Coconut Jupyter kernel installation failed due to above error"

        if WINDOWS: