<commit_before>import logging
import threading
import time

import sentry_sdk
from sentry_sdk.integrations.pyramid import PyramidIntegration

import shavar.lists


__version__ = '0.12.8.5'
DEFAULT_REFRESH_LISTS_DELAY = 600  # 10m
logger = logging.getLogger('shavar')


class RefreshListsConfigThread(threading.Thread):
    def __init__(self, delay, config):
        threading.Thread.__init__(self)
        self.delay = delay
        self.config = config

    def run(self):
        logger.info("Starting RefreshListsConfigThread")
        refresh_lists_config(self.delay, self.config)


def refresh_lists_config(delay, config):
    while(delay):
        time.sleep(delay)
        logger.info("Refreshing lists config ...")
        shavar.lists.includeme(config)
        logger.info("Refreshing lists config done.")


def includeme(config):
    "Load shavar WSGI app into the provided Pyramid configurator"
    # Dependencies first
    config.include("mozsvc")
    config.include('pyramid_mako')
    # Have to get the lists loaded before the views
    shavar.lists.includeme(config)
    config.include("shavar.views")


def get_configurator(global_config, **settings):
    import mozsvc.config
    config = mozsvc.config.get_configurator(global_config, **settings)
    config.begin()
    try:
        config.include(includeme)
    finally:
        config.end()
    return config


def configure_sentry(config):
    dsn = config.registry.settings.get('shavar.sentry_dsn')
    if dsn:
        env_option = {}
        if SENTRY_ENV:
            env_option = {"environment": SENTRY_ENV}
        sentry_sdk.init(
            dsn=dsn,
            integrations=[PyramidIntegration()],
            **env_option
        )


def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """

    config = get_configurator(global_config, **settings)
    configure_sentry(config)
    app = config.make_wsgi_app()
    refreshListsConfigThread = RefreshListsConfigThread(
        config.registry.settings.get(
            'shavar.refresh_lists_delay', DEFAULT_REFRESH_LISTS_DELAY
        ),
        config
    )
    refreshListsConfigThread.daemon = True
    refreshListsConfigThread.start()
    return app
<commit_msg>Get Sentry env value from environment var<commit_after>import logging
import threading
import time

import sentry_sdk
from sentry_sdk.integrations.pyramid import PyramidIntegration

import shavar.lists


__version__ = '0.12.8.5'
DEFAULT_REFRESH_LISTS_DELAY = 600  # 10m
logger = logging.getLogger('shavar')


class RefreshListsConfigThread(threading.Thread):
    def __init__(self, delay, config):
        threading.Thread.__init__(self)
        self.delay = delay
        self.config = config

    def run(self):
        logger.info("Starting RefreshListsConfigThread")
        refresh_lists_config(self.delay, self.config)


def refresh_lists_config(delay, config):
    while(delay):
        time.sleep(delay)
        logger.info("Refreshing lists config ...")
        shavar.lists.includeme(config)
        logger.info("Refreshing lists config done.")


def includeme(config):
    "Load shavar WSGI app into the provided Pyramid configurator"
    # Dependencies first
    config.include("mozsvc")
    config.include('pyramid_mako')
    # Have to get the lists loaded before the views
    shavar.lists.includeme(config)
    config.include("shavar.views")


def get_configurator(global_config, **settings):
    import mozsvc.config
    config = mozsvc.config.get_configurator(global_config, **settings)
    config.begin()
    try:
        config.include(includeme)
    finally:
        config.end()
    return config


def configure_sentry(config):
    dsn = config.registry.settings.get('shavar.sentry_dsn')
    sentry_env = config.registry.settings.get('shavar.sentry_env')
    if dsn:
        env_option = {}
        if sentry_env:
            env_option = {"environment": sentry_env}
        sentry_sdk.init(
            dsn=dsn,
            integrations=[PyramidIntegration()],
            **env_option
        )


def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """

    config = get_configurator(global_config, **settings)
    configure_sentry(config)
    app = config.make_wsgi_app()
    refreshListsConfigThread = RefreshListsConfigThread(
        config.registry.settings.get(
            'shavar.refresh_lists_delay', DEFAULT_REFRESH_LISTS_DELAY
        ),
        config
    )
    refreshListsConfigThread.daemon = True
    refreshListsConfigThread.start()
    return app

{'fraction_non_alphanumeric': 0.09372951715097225, 'fraction_numerical': 0.004369674459252786, 'mean_word_length': 3.1542649727767693, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2312787', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1397, 'n_words': 278}