<commit_before>"""
Tim: Helpers related to functionality.
"""
import os


__all__ = ['create_project_dir', 'env', ]


def create_project_dir(project_path):
    """
    Generates a project_dir function for use in Django settings modules

    You can create a ``project_dir`` function for your settings module
    using this function.  Provide it with the path to your settings
    module and returns a function that can combine that with any set of
    path elements to create a cross-platform path.

    Example::

        >>> project_dir = create_project_dir("/foobar/settings.py")
        >>> project_dir("templates")
        '/foobar/templates'

    Generally, you would use this as ``create_project_dir(__file__)``.
    """
    def project_dir(*paths):
        base = os.path.realpath(os.path.dirname(project_path))
        return os.path.join(base, *paths)

    return project_dir


def get_env(key, default, force_bool=False, type_func=None, **defaults):
    """
    Returns the correct environment variable

    This provides a few useful additions on top of a generic call to
    ``os.environ.get(key, default)``.  First, you can coerce a value
    into a boolean by using the kwarg ``force_bool=True``.  For example:

    ::

        >>> import os
        >>> os.environ['some-value'] = 'Yes'
        >>> get_env('some-value', 'default', force_bool=True)
        True

    This works with ``yes``, ``true``, and ``1``.  Capitalization is
    ignored for all of these.

    Next, you can provide a ``type_func`` to force a conversion to a
    particular type.  This is useful for values that need to be an
    integer, since everything in ``os.environ`` is a string.  For
    example:

    ::

        >>> os.environ['some-int'] = '1234'
        >>> get_env('some-int', 'default', type_func=int)
        1234

    Finally, you can provide extra defaults that change depending on the
    environment.  For example, let's say you have a dev and testing
    environment you can use ``get_env`` like this:

    ::

        >>> os.environ['ENVIRONMENT'] = 'testing'
        >>> get_env('some-key', 'default', dev='dev', testing='testing')
        'testing'
        >>> os.environ['ENVIRONMENT'] = 'dev'
        >>> get_env('some-key', 'default', dev='dev', testing='testing')
        'dev'

    """
    env = os.environ.get('ENVIRONMENT')
    a = os.environ.get(key, defaults.get(env, default))
    if force_bool:
        return str(a).lower() in ['1', 'yes', 'true', ]
    return a if type_func is None else type_func(a)


class _Env(dict):
    """A wrapper around os.environ that supports environments and `Boolean`."""
    def __init__(self):
        self.update(os.environ.copy())

    def get(self, key, default=None, *args, **kwargs):
        """
        Get information from your environment.

        A wrapper around dj-settings-helper's ``get_env`` that mimics the api of
        ``os.environ``.
        """
        return get_env(key, default, *args, **kwargs)


env = _Env()<commit_msg>kill the docstrings until new syntax is found<commit_after>"""
Tim: Helpers related to functionality.
"""
import os


__all__ = ['create_project_dir', 'env', ]


def create_project_dir(project_path):
    def project_dir(*paths):
        base = os.path.realpath(os.path.dirname(project_path))
        return os.path.join(base, *paths)

    return project_dir


def get_env(key, default, force_bool=False, type_func=None, **defaults):
    env = os.environ.get('ENVIRONMENT')
    a = os.environ.get(key, defaults.get(env, default))
    if force_bool:
        return str(a).lower() in ['1', 'yes', 'true', ]
    return a if type_func is None else type_func(a)


class _Env(dict):
    """A wrapper around os.environ that supports environments and `Boolean`."""
    def __init__(self):
        self.update(os.environ.copy())

    def get(self, key, default=None, *args, **kwargs):
        """
        Get information from your environment.

        A wrapper around dj-settings-helper's ``get_env`` that mimics the api of
        ``os.environ``.
        """
        return get_env(key, default, *args, **kwargs)


env = _Env()
{'fraction_non_alphanumeric': 0.1307934967240961, 'fraction_numerical': 0.0026692550351856345, 'mean_word_length': 3.0019417475728156, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 36, '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': '1316265', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1229, 'n_words': 396}