<commit_before>"""StagPy is a tool to postprocess StagYY output files.

StagPy is both a CLI tool and a powerful Python library. See the
documentation at
http://stagpy.readthedocs.io/en/stable/

If the environment variable STAGPY_NO_CONFIG is set to 'True', StagPy does not
attempt to read any configuration file.
"""

from setuptools_scm import get_version
from pkg_resources import get_distribution, DistributionNotFound
import importlib
import os
import signal
import sys
from . import config


def sigint_handler(*_):
    """Handler of SIGINT signal.

    It is set when you use StagPy as a command line tool to handle gracefully
    keyboard interruption.
    """
    print('\nSo long, and thanks for all the fish.')
    sys.exit()


def _load_mpl():
    """Load matplotlib and set some configuration"""
    mpl = importlib.import_module('matplotlib')
    if conf.plot.matplotback:
        mpl.use(conf.plot.matplotback)
    plt = importlib.import_module('matplotlib.pyplot')
    if conf.plot.useseaborn:
        sns = importlib.import_module('seaborn')
        sns.set()
    if conf.plot.xkcd:
        plt.xkcd()


_PREV_INT = signal.signal(signal.SIGINT, sigint_handler)

try:
    __version__ = get_version(root='..', relative_to=__file__)
except LookupError:
    __version__ = get_distribution('stagpy').version
except (DistributionNotFound, ValueError):
    __version__ = 'unknown'

_CONF_FILE = config.CONFIG_FILE\
    if os.getenv('STAGPY_NO_CONFIG') != 'True' else None
# pylint: disable=invalid-name
conf = config.StagpyConfiguration(_CONF_FILE)
# pylint: enable=invalid-name

_load_mpl()

signal.signal(signal.SIGINT, _PREV_INT)
<commit_msg>New _env function in __init__<commit_after>"""StagPy is a tool to postprocess StagYY output files.

StagPy is both a CLI tool and a powerful Python library. See the
documentation at
http://stagpy.readthedocs.io/en/stable/

If the environment variable STAGPY_NO_CONFIG is set to 'True', StagPy does not
attempt to read any configuration file.
"""

from setuptools_scm import get_version
from pkg_resources import get_distribution, DistributionNotFound
import importlib
import os
import signal
import sys
from . import config


def sigint_handler(*_):
    """Handler of SIGINT signal.

    It is set when you use StagPy as a command line tool to handle gracefully
    keyboard interruption.
    """
    print('\nSo long, and thanks for all the fish.')
    sys.exit()


def _load_mpl():
    """Load matplotlib and set some configuration"""
    mpl = importlib.import_module('matplotlib')
    if conf.plot.matplotback:
        mpl.use(conf.plot.matplotback)
    plt = importlib.import_module('matplotlib.pyplot')
    if conf.plot.useseaborn:
        sns = importlib.import_module('seaborn')
        sns.set()
    if conf.plot.xkcd:
        plt.xkcd()


def _env(var):
    """Return whether var is set to True."""
    return os.getenv(var) == 'True'


_PREV_INT = signal.signal(signal.SIGINT, sigint_handler)

try:
    __version__ = get_version(root='..', relative_to=__file__)
except LookupError:
    __version__ = get_distribution('stagpy').version
except (DistributionNotFound, ValueError):
    __version__ = 'unknown'

_CONF_FILE = config.CONFIG_FILE if not _env('STAGPY_NO_CONFIG') else None
# pylint: disable=invalid-name
conf = config.StagpyConfiguration(_CONF_FILE)
# pylint: enable=invalid-name

_load_mpl()

signal.signal(signal.SIGINT, _PREV_INT)

{'fraction_non_alphanumeric': 0.09536384976525822, 'fraction_numerical': 0.0, 'mean_word_length': 4.157337367624811, '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': '1025302', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1078, 'n_words': 316}