# Path: coconut/root.py
# def _indent(code, by=1, tabsize=4, newline=False):
#     """Indents every nonempty line of the given code."""
#     return "".join(
#         (" " * (tabsize * by) if line else "") + line
#         for line in code.splitlines(True)
#     ) + ("\n" if newline else "")
# 
# 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
# def univ_open(filename, opentype="r+", encoding=None, **kwargs):
#     """Open a file using default_encoding."""
#     if encoding is None:
#         encoding = default_encoding
#     if "b" not in opentype:
#         kwargs["encoding"] = encoding
#     # we use io.open from coconut.root here
#     return open(filename, opentype, **kwargs)
# 
# Path: coconut/terminal.py
# def internal_assert(condition, message=None, item=None, extra=None):
#     """Raise InternalException if condition is False. Execute functions on DEVELOP only."""
#     if DEVELOP and callable(condition):
#         condition = condition()
#     if not condition:
#         if message is None:
#             message = "assertion failed"
#             if item is None:
#                 item = condition
#         elif callable(message):
#             message = message()
#         if callable(extra):
#             extra = extra()
#         error = CoconutInternalException(message, item, extra)
#         if embed_on_internal_exc:
#             logger.warn_err(error)
#             embed(depth=1)
#         else:
#             raise error
# 
# Path: coconut/compiler/util.py
# def get_target_info(target):
#     """Return target information as a version tuple."""
#     if not target:
#         return ()
#     elif len(target) == 1:
#         return (int(target),)
#     else:
#         return (int(target[0]), int(target[1:]))
# 
# def split_comment(line):
#     """Split line into base and comment."""
#     base = rem_comment(line)
#     return base, line[len(base):]
# 
# def get_vers_for_target(target):
#     """Gets a list of the versions supported by the given target."""
#     target_info = get_target_info(target)
#     if not target_info:
#         return supported_py2_vers + supported_py3_vers
#     elif len(target_info) == 1:
#         if target_info == (2,):
#             return supported_py2_vers
#         elif target_info == (3,):
#             return supported_py3_vers
#         else:
#             raise CoconutInternalException("invalid target info", target_info)
#     elif target_info[0] == 2:
#         return tuple(ver for ver in supported_py2_vers if ver >= target_info)
#     elif target_info[0] == 3:
#         return tuple(ver for ver in supported_py3_vers if ver >= target_info)
#     else:
#         raise CoconutInternalException("invalid target info", target_info)


from coconut.root import *  # NOQA
from functools import partial
from coconut.root import _indent
from coconut.constants import (
    hash_prefix,
    tabideal,
    default_encoding,
    template_ext,
    justify_len,
    report_this_text,
)
from coconut.util import univ_open
from coconut.terminal import internal_assert
from coconut.compiler.util import (
    get_target_info,
    split_comment,
    get_vers_for_target,
)
import os.path

# -----------------------------------------------------------------------------------------------------------------------
# FORMAT DICTIONARY:
# -----------------------------------------------------------------------------------------------------------------------


class Comment(object):
    """When passed to str.format, allows {COMMENT.<>} to serve as a comment."""

    def __getattr__(self, attr):
        """Return an empty string for all comment attributes."""
        return ""


COMMENT = Comment()


def process_header_args(which, target, use_hash, no_tco, strict, no_wrap):
    """Create the dictionary passed to str.format in the header."""
    target_startswith = one_num_ver(target)
    target_info = get_target_info(target)
    pycondition = partial(base_pycondition, target)

    format_dict = dict(
        COMMENT=COMMENT,
        empty_dict="{}",
        lbrace="{",
        rbrace="}",
        target_startswith=target_startswith,
        default_encoding=default_encoding,

# Path: coconut/root.py
# def _indent(code, by=1, tabsize=4, newline=False):
#     """Indents every nonempty line of the given code."""
#     return "".join(
#         (" " * (tabsize * by) if line else "") + line
#         for line in code.splitlines(True)
#     ) + ("\n" if newline else "")
# 
# 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
# def univ_open(filename, opentype="r+", encoding=None, **kwargs):
#     """Open a file using default_encoding."""
#     if encoding is None:
#         encoding = default_encoding
#     if "b" not in opentype:
#         kwargs["encoding"] = encoding
#     # we use io.open from coconut.root here
#     return open(filename, opentype, **kwargs)
# 
# Path: coconut/terminal.py
# def internal_assert(condition, message=None, item=None, extra=None):
#     """Raise InternalException if condition is False. Execute functions on DEVELOP only."""
#     if DEVELOP and callable(condition):
#         condition = condition()
#     if not condition:
#         if message is None:
#             message = "assertion failed"
#             if item is None:
#                 item = condition
#         elif callable(message):
#             message = message()
#         if callable(extra):
#             extra = extra()
#         error = CoconutInternalException(message, item, extra)
#         if embed_on_internal_exc:
#             logger.warn_err(error)
#             embed(depth=1)
#         else:
#             raise error
# 
# Path: coconut/compiler/util.py
# def get_target_info(target):
#     """Return target information as a version tuple."""
#     if not target:
#         return ()
#     elif len(target) == 1:
#         return (int(target),)
#     else:
#         return (int(target[0]), int(target[1:]))
# 
# def split_comment(line):
#     """Split line into base and comment."""
#     base = rem_comment(line)
#     return base, line[len(base):]
# 
# def get_vers_for_target(target):
#     """Gets a list of the versions supported by the given target."""
#     target_info = get_target_info(target)
#     if not target_info:
#         return supported_py2_vers + supported_py3_vers
#     elif len(target_info) == 1:
#         if target_info == (2,):
#             return supported_py2_vers
#         elif target_info == (3,):
#             return supported_py3_vers
#         else:
#             raise CoconutInternalException("invalid target info", target_info)
#     elif target_info[0] == 2:
#         return tuple(ver for ver in supported_py2_vers if ver >= target_info)
#     elif target_info[0] == 3:
#         return tuple(ver for ver in supported_py3_vers if ver >= target_info)
#     else:
#         raise CoconutInternalException("invalid target info", target_info)


# Path: coconut/compiler/header.py
from coconut.root import *  # NOQA
from functools import partial
from coconut.root import _indent
from coconut.constants import (
    hash_prefix,
    tabideal,
    default_encoding,
    template_ext,
    justify_len,
    report_this_text,
)
from coconut.util import univ_open
from coconut.terminal import internal_assert
from coconut.compiler.util import (
    get_target_info,
    split_comment,
    get_vers_for_target,
)
import os.path


# -----------------------------------------------------------------------------------------------------------------------
# FORMAT DICTIONARY:
# -----------------------------------------------------------------------------------------------------------------------


class Comment(object):
    """When passed to str.format, allows {COMMENT.<>} to serve as a comment."""

    def __getattr__(self, attr):
        """Return an empty string for all comment attributes."""
        return ""


COMMENT = Comment()


def process_header_args(which, target, use_hash, no_tco, strict, no_wrap):
    """Create the dictionary passed to str.format in the header."""
    target_startswith = one_num_ver(target)
    target_info = get_target_info(target)
    pycondition = partial(base_pycondition, target)

    format_dict = dict(
        COMMENT=COMMENT,
        empty_dict="{}",
        lbrace="{",
        rbrace="}",
        target_startswith=target_startswith,
        default_encoding=default_encoding,

        hash_line=hash_prefix + use_hash + "\n" if use_hash is not None else "",