# Path: valohai_cli/exceptions.py
# class ConfigurationError(CLIException, RuntimeError):
#     kind = 'Configuration Error'
# 
# class PackageTooLarge(CLIException):
#     pass
# 
# Path: valohai_cli/messages.py
# def info(message: str, err: bool = True) -> None:
#     click.echo(_format_message(message, ['=>'], color='cyan'), err=err)
# 
# def warn(message: str, err: bool = True) -> None:
#     click.echo(_format_message(message, WARN_EMOJI, 'Warning:', 'yellow'), err=err)
# 
# Path: valohai_cli/utils/file_size_format.py
# def filesizeformat(value: Union[int, float], binary: bool = False) -> str:
#     """Format the value like a 'human-readable' file size (i.e. 13 kB,
#     4.1 MB, 102 Bytes, etc).  Per default decimal prefixes are used (Mega,
#     Giga, etc.), if the second parameter is set to `True` the binary
#     prefixes are used (Mebi, Gibi).
#     """
#     bytes = float(value)
#     base = 1024 if binary else 1000
#     prefixes = binary_prefixes if binary else decimal_prefixes
#     if bytes == 1:
#         return '1 Byte'
#     elif bytes < base:
#         return f'{bytes} Bytes'
#     else:
#         for i, prefix in enumerate(prefixes):
#             unit = base ** (i + 2)
#             if bytes < unit:
#                 return f'{base * bytes / unit:.1f} {prefix}'
#         return f'{base * bytes / unit:.1f} {prefix}'


import fnmatch
import gzip
import os
import subprocess
import tarfile
import tempfile
import click
import gitignorant
from collections import namedtuple
from enum import Enum
from subprocess import check_output
from typing import IO, Dict, Iterable, List, Tuple
from valohai_cli.exceptions import ConfigurationError, PackageTooLarge
from valohai_cli.messages import info, warn
from valohai_cli.utils.file_size_format import filesizeformat
    GIT_LS_FILES = 2


class VhIgnoreUsage(Enum):
    NONE = 0
    VHIGNORE = 1


def package_directory(dir: str, progress: bool = False, validate: bool = True) -> str:
    file_stats = get_files_for_package(dir)

    if validate and 'valohai.yaml' not in file_stats:
        raise ConfigurationError(f'valohai.yaml missing from {dir}')

    if validate:
        package_size_warnings = validate_package_size(file_stats)
        if package_size_warnings:
            for warning in package_size_warnings:
                click.secho('* ' + warning, err=True)
            click.secho(PACKAGE_SIZE_HELP, err=True)
            click.confirm('Continue packaging anyway?', default=True, abort=True, prompt_suffix='', err=True)

    with tempfile.NamedTemporaryFile(delete=False, suffix='.tgz', prefix='valohai-cli-') as fp:
        package_files_into(fp, file_stats, progress=progress)
        total_compressed_size = fp.tell()

    if validate and total_compressed_size >= COMPRESSED_PACKAGE_SIZE_HARD_THRESHOLD:
        raise PackageTooLarge(
            'The total compressed size of the package is {size}, which exceeds the threshold {threshold}'.format(
                size=filesizeformat(total_compressed_size),

# Path: valohai_cli/exceptions.py
# class ConfigurationError(CLIException, RuntimeError):
#     kind = 'Configuration Error'
# 
# class PackageTooLarge(CLIException):
#     pass
# 
# Path: valohai_cli/messages.py
# def info(message: str, err: bool = True) -> None:
#     click.echo(_format_message(message, ['=>'], color='cyan'), err=err)
# 
# def warn(message: str, err: bool = True) -> None:
#     click.echo(_format_message(message, WARN_EMOJI, 'Warning:', 'yellow'), err=err)
# 
# Path: valohai_cli/utils/file_size_format.py
# def filesizeformat(value: Union[int, float], binary: bool = False) -> str:
#     """Format the value like a 'human-readable' file size (i.e. 13 kB,
#     4.1 MB, 102 Bytes, etc).  Per default decimal prefixes are used (Mega,
#     Giga, etc.), if the second parameter is set to `True` the binary
#     prefixes are used (Mebi, Gibi).
#     """
#     bytes = float(value)
#     base = 1024 if binary else 1000
#     prefixes = binary_prefixes if binary else decimal_prefixes
#     if bytes == 1:
#         return '1 Byte'
#     elif bytes < base:
#         return f'{bytes} Bytes'
#     else:
#         for i, prefix in enumerate(prefixes):
#             unit = base ** (i + 2)
#             if bytes < unit:
#                 return f'{base * bytes / unit:.1f} {prefix}'
#         return f'{base * bytes / unit:.1f} {prefix}'


# Path: valohai_cli/packager.py
import fnmatch
import gzip
import os
import subprocess
import tarfile
import tempfile
import click
import gitignorant
from collections import namedtuple
from enum import Enum
from subprocess import check_output
from typing import IO, Dict, Iterable, List, Tuple
from valohai_cli.exceptions import ConfigurationError, PackageTooLarge
from valohai_cli.messages import info, warn
from valohai_cli.utils.file_size_format import filesizeformat

    GIT_LS_FILES = 2


class VhIgnoreUsage(Enum):
    NONE = 0
    VHIGNORE = 1


def package_directory(dir: str, progress: bool = False, validate: bool = True) -> str:
    file_stats = get_files_for_package(dir)

    if validate and 'valohai.yaml' not in file_stats:
        raise ConfigurationError(f'valohai.yaml missing from {dir}')

    if validate:
        package_size_warnings = validate_package_size(file_stats)
        if package_size_warnings:
            for warning in package_size_warnings:
                click.secho('* ' + warning, err=True)
            click.secho(PACKAGE_SIZE_HELP, err=True)
            click.confirm('Continue packaging anyway?', default=True, abort=True, prompt_suffix='', err=True)

    with tempfile.NamedTemporaryFile(delete=False, suffix='.tgz', prefix='valohai-cli-') as fp:
        package_files_into(fp, file_stats, progress=progress)
        total_compressed_size = fp.tell()

    if validate and total_compressed_size >= COMPRESSED_PACKAGE_SIZE_HARD_THRESHOLD:
        raise PackageTooLarge(
            'The total compressed size of the package is {size}, which exceeds the threshold {threshold}'.format(
                size=filesizeformat(total_compressed_size),

                threshold=filesizeformat(COMPRESSED_PACKAGE_SIZE_HARD_THRESHOLD),