# 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



FILE_SIZE_WARN_THRESHOLD = 50 * 1024 * 1024
FILE_COUNT_HARD_THRESHOLD = 10000
UNCOMPRESSED_PACKAGE_SIZE_SOFT_THRESHOLD = 150 * 1024 * 1024
COMPRESSED_PACKAGE_SIZE_HARD_THRESHOLD = 1000 * 1024 * 1024

# We guess that Gzip may help halve the package size -
# if the package is actually all source code, it will probably help more.
UNCOMPRESSED_PACKAGE_SIZE_HARD_THRESHOLD = COMPRESSED_PACKAGE_SIZE_HARD_THRESHOLD / 0.5

PACKAGE_SIZE_HELP = '''
It's generally not a good idea to have large files in your working copy,
as most version control systems, Git included, are optimized to work with
code, not data.

Data files such as pretraining data or checkpoint files should be managed
with the Valohai inputs system instead for increased performance.


# 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




FILE_SIZE_WARN_THRESHOLD = 50 * 1024 * 1024
FILE_COUNT_HARD_THRESHOLD = 10000
UNCOMPRESSED_PACKAGE_SIZE_SOFT_THRESHOLD = 150 * 1024 * 1024
COMPRESSED_PACKAGE_SIZE_HARD_THRESHOLD = 1000 * 1024 * 1024

# We guess that Gzip may help halve the package size -
# if the package is actually all source code, it will probably help more.
UNCOMPRESSED_PACKAGE_SIZE_HARD_THRESHOLD = COMPRESSED_PACKAGE_SIZE_HARD_THRESHOLD / 0.5

PACKAGE_SIZE_HELP = '''
It's generally not a good idea to have large files in your working copy,
as most version control systems, Git included, are optimized to work with
code, not data.

Data files such as pretraining data or checkpoint files should be managed
with the Valohai inputs system instead for increased performance.


If you are using Git, consider `git rm`ing the large files and adding