<commit_before>from .base import AnnexBase

__all__ = ('Annex',)

# -----------------------------------------------------------------------------


def get_annex_class(storage):
    if storage == 'file':
        from .file import FileAnnex
        return FileAnnex
    else:
        raise ValueError("unsupported storage {}".format(storage))


# -----------------------------------------------------------------------------


class Annex(AnnexBase):
    def __init__(self, storage, **kwargs):
        annex_class = get_annex_class(storage)

        # Proxy the actual implementation to prevent use of storage-specific
        # attributes when using the generic annex.
        self._impl = annex_class(**kwargs)

    def save_file(self, key, filename):
        return self._impl.save_file(key, filename)

    def send_file(self, key, **options):
        return self._impl.send_file(key, **options)<commit_msg>Use storage sub-namespace for generic annex<commit_after>from .base import AnnexBase
from . import utils

__all__ = ('Annex',)

# -----------------------------------------------------------------------------


def get_annex_class(storage):
    if storage == 'file':
        from .file import FileAnnex
        return FileAnnex
    else:
        raise ValueError("unsupported storage {}".format(storage))


# -----------------------------------------------------------------------------


class Annex(AnnexBase):
    def __init__(self, storage, **kwargs):
        annex_class = get_annex_class(storage)

        # Proxy the actual implementation to prevent use of storage-specific
        # attributes when using the generic annex.
        self._impl = annex_class(**kwargs)

    @classmethod
    def from_env(cls, namespace):
        storage = utils.get_config_from_env(namespace)['storage']

        # Use storage-specific env namespace when configuring a generic annex,
        # to avoid having unrecognized extra keys when changing storage.
        storage_namespace = '{}_{}'.format(namespace, storage.upper())
        storage_config = utils.get_config_from_env(storage_namespace)

        return cls(storage, **storage_config)

    def save_file(self, key, filename):
        return self._impl.save_file(key, filename)

    def send_file(self, key, **options):
        return self._impl.send_file(key, **options)
{'fraction_non_alphanumeric': 0.21787709497206703, 'fraction_numerical': 0.0, 'mean_word_length': 1.9543147208121827, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4787622', 'n_tokens_mistral': 594, 'n_tokens_neox': 570, 'n_words': 161}