<commit_before>"""
Compressor main module.
Exposes the entry point to the program for executing as command line,
as well as the main functions to be used as library.
This module contains high-level functionality.
"""
import argparse
import sys
from .core import (
    process_frequencies,
    create_tree_code,
    parse_tree_code,
    save_compressed_file,
    retrieve_compressed_file,
)

VERSION = '0.1.0'


def compress_file(filename: str, dest_file: str=None) -> None:
    """
    Open the <filename> and compress its content on a new one.

    :param filename:  The path to the source file to compress.
    :param dest_file: The name of the target file. If not provided (None),
                      a default will be used with `<filename>.comp`

    :return:          None
    """
    with open(filename, 'r') as source:
        freqs = process_frequencies(source.read())
    checksum = sum(c.freq for c in freqs)  # bytes
    tree_code = create_tree_code(freqs)
    table = parse_tree_code(tree_code)
    save_compressed_file(filename, table, checksum, dest_file)


def extract_file(filename: str, dest_file: str=None) -> None:
    """
    Extract the compressed <filename> into <dest_file>

    :param filename:  The name of the file to open for extraction.
    :param dest_file: The name (path) where to dump the result.
    """
    retrieve_compressed_file(filename, dest_file)


def parse_arguments():
    """
    Parse the command-line (cli) provided arguments.
    """
    parser = argparse.ArgumentParser(
        prog='PyCompress',
        description="Compress text files.",
    )
    parser.add_argument('filename', type=str,<commit_msg>Update annotations & docstrings :smile:<commit_after>"""
Compressor main module.
Exposes the entry point to the program for executing as command line,
as well as the main functions to be used as library.
This module contains high-level functionality.
"""
import argparse
import sys
from .core import (
    process_frequencies,
    create_tree_code,
    parse_tree_code,
    save_compressed_file,
    retrieve_compressed_file,
)

VERSION = '0.1.0'


def compress_file(filename: str, dest_file: str=None) -> None:
    """
    Open the <filename> and compress its contents on a new one.

    :param filename:  The path to the source file to compress.
    :param dest_file: The name of the target file. If not provided (None),
                      a default will be used with `<filename>.comp`
    """
    with open(filename, 'r') as source:
        freqs = process_frequencies(source.read())

    checksum = sum(c.freq for c in freqs)  # bytes
    tree_code = create_tree_code(freqs)
    table = parse_tree_code(tree_code)
    save_compressed_file(filename, table, checksum, dest_file)


def extract_file(filename: str, dest_file: str=None) -> None:
    """
    Extract the compressed <filename> into <dest_file>

    :param filename:  Name of the file to open for extraction.
    :param dest_file: Name (path) where to dump the result.
    """
    retrieve_compressed_file(filename, dest_file)


def parse_arguments() -> dict:
    """
    Parse the command-line (cli) provided arguments.

    :return: dict with the kwargs provided in cli
    """
    parser = argparse.ArgumentParser(
        prog='PyCompress',
        description="Compress text files.",
    )
    parser.add_argument('filename', type=str,
{'fraction_non_alphanumeric': 0.0919369235346623, 'fraction_numerical': 0.0017851829812555787, 'mean_word_length': 3.32133676092545, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5157873', 'n_tokens_mistral': 1014, 'n_tokens_neox': 988, 'n_words': 341}