# 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
                continue
            file = line.decode('utf-8')
            path = os.path.join(dir, file)
            if path not in paths_seen:
                paths_seen.add(path)
                yield (file, path)


def _get_files_walk(dir: str) -> Iterable[Tuple[str, str]]:
    for dirpath, dirnames, filenames in os.walk(dir):
        dirnames[:] = [dirname for dirname in dirnames if not dirname.startswith('.')]
        for filename in filenames:
            if filename.startswith('.'):
                continue
            filename = os.path.join(dirpath, filename)
            file_abs_path = os.path.join(dir, filename)
            file_rel_path = filename[len(dir):].lstrip(os.sep)
            yield (file_rel_path, file_abs_path)


def _get_files_inner(dir: str, allow_git: bool = True) -> Tuple[GitUsage, Iterable[Tuple[str, str]]]:
    # Inner, pre-vhignore-supporting generator function...
    gitignore_path = os.path.join(dir, '.gitignore')

    if allow_git:
        if os.path.exists(os.path.join(dir, '.git')):
            # We have .git, so we can try to use Git to figure out a file list of nonignored files
            try:
                return (GitUsage.GIT_LS_FILES, _get_files_with_git(dir))  # return the generator
            except subprocess.CalledProcessError as cpe:

# 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

                continue
            file = line.decode('utf-8')
            path = os.path.join(dir, file)
            if path not in paths_seen:
                paths_seen.add(path)
                yield (file, path)


def _get_files_walk(dir: str) -> Iterable[Tuple[str, str]]:
    for dirpath, dirnames, filenames in os.walk(dir):
        dirnames[:] = [dirname for dirname in dirnames if not dirname.startswith('.')]
        for filename in filenames:
            if filename.startswith('.'):
                continue
            filename = os.path.join(dirpath, filename)
            file_abs_path = os.path.join(dir, filename)
            file_rel_path = filename[len(dir):].lstrip(os.sep)
            yield (file_rel_path, file_abs_path)


def _get_files_inner(dir: str, allow_git: bool = True) -> Tuple[GitUsage, Iterable[Tuple[str, str]]]:
    # Inner, pre-vhignore-supporting generator function...
    gitignore_path = os.path.join(dir, '.gitignore')

    if allow_git:
        if os.path.exists(os.path.join(dir, '.git')):
            # We have .git, so we can try to use Git to figure out a file list of nonignored files
            try:
                return (GitUsage.GIT_LS_FILES, _get_files_with_git(dir))  # return the generator
            except subprocess.CalledProcessError as cpe:

                warn(f'.git exists, but we could not use git ls-files (error {cpe.returncode}), falling back to non-git')