<commit_before>"""Pylons environment configuration"""
import os, os.path
import subprocess

from mako.lookup import TemplateLookup
from paste.deploy.converters import asbool
import pylons
from pylons.configuration import PylonsConfig
from pylons.error import handle_mako_error
from sqlalchemy import engine_from_config

import floof.lib.app_globals as app_globals
import floof.lib.debugging
import floof.lib.helpers
from floof.config.routing import make_map
from floof.model import filestore, init_model

def load_environment(global_conf, app_conf):
    """Configure the Pylons environment via the ``pylons.config``
    object
    """
    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=[os.path.join(root, 'templates')])

    # Initialize config with the basic options
    config = PylonsConfig()
    config.init_app(global_conf, app_conf, package='floof', paths=paths)

    config['routes.map'] = make_map(config)
    config['pylons.app_globals'] = app_globals.Globals(config)
    config['pylons.h'] = floof.lib.helpers
    pylons.cache._push_object(config['pylons.app_globals'].cache)

    # Create the Mako TemplateLookup, with the default auto-escaping
    config['pylons.app_globals'].mako_lookup = TemplateLookup(
        directories=paths['templates'],
        error_handler=handle_mako_error,
        module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
        input_encoding='utf-8', default_filters=['escape'],
        imports=['from webhelpers.html import escape'])

    # Setup SQLAlchemy database engine
    # Proxy class is just to record query time; in debugging mode, it also
    # tracks every query
    config['super_debug'] = asbool(config.get('super_debug', False))
    if config['super_debug']:
        sqla_proxy = floof.lib.debugging.SQLAQueryLogProxy()
    else:
        sqla_proxy = floof.lib.debugging.SQLATimerProxy()
    config['super_debug.sqlalchemy_proxy'] = sqla_proxy
    engine = engine_from_config(config, 'sqlalchemy.', proxy=sqla_proxy)
    init_model(engine)

    # Compile stylesheets with Sass
    # This env var is only set from a convenient launcher script
    if 'FLOOF_SKIP_SASS_COMPILATION' not in os.environ:
        sass_paths = u':'.join((
            os.path.join(root, 'sass'),
            os.path.join(root, 'public', 'css'),
        ))
        subprocess.Popen(
            ['sass', '--scss', '--style', 'compressed', '--update', sass_paths],
        ).wait()

    # CONFIGURATION OPTIONS HERE (note: all config options will override
    # any Pylons config options)

    # Create file storage object and stick it back in the config
    storage = filestore.get_storage(config)
    config['filestore'] = storage

    return config<commit_msg>Make the in-app Sass compilation die on errors, to avoid spewing junk to clients.  #442<commit_after>"""Pylons environment configuration"""
import os, os.path
import subprocess

from mako.lookup import TemplateLookup
from paste.deploy.converters import asbool
import pylons
from pylons.configuration import PylonsConfig
from pylons.error import handle_mako_error
from sqlalchemy import engine_from_config

import floof.lib.app_globals as app_globals
import floof.lib.debugging
import floof.lib.helpers
from floof.config.routing import make_map
from floof.model import filestore, init_model

def load_environment(global_conf, app_conf):
    """Configure the Pylons environment via the ``pylons.config``
    object
    """
    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=[os.path.join(root, 'templates')])

    # Initialize config with the basic options
    config = PylonsConfig()
    config.init_app(global_conf, app_conf, package='floof', paths=paths)

    config['routes.map'] = make_map(config)
    config['pylons.app_globals'] = app_globals.Globals(config)
    config['pylons.h'] = floof.lib.helpers
    pylons.cache._push_object(config['pylons.app_globals'].cache)

    # Create the Mako TemplateLookup, with the default auto-escaping
    config['pylons.app_globals'].mako_lookup = TemplateLookup(
        directories=paths['templates'],
        error_handler=handle_mako_error,
        module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
        input_encoding='utf-8', default_filters=['escape'],
        imports=['from webhelpers.html import escape'])

    # Setup SQLAlchemy database engine
    # Proxy class is just to record query time; in debugging mode, it also
    # tracks every query
    config['super_debug'] = asbool(config.get('super_debug', False))
    if config['super_debug']:
        sqla_proxy = floof.lib.debugging.SQLAQueryLogProxy()
    else:
        sqla_proxy = floof.lib.debugging.SQLATimerProxy()
    config['super_debug.sqlalchemy_proxy'] = sqla_proxy
    engine = engine_from_config(config, 'sqlalchemy.', proxy=sqla_proxy)
    init_model(engine)

    # Compile stylesheets with Sass
    # This env var is only set from a convenient launcher script
    if 'FLOOF_SKIP_SASS_COMPILATION' not in os.environ:
        sass_paths = u':'.join((
            os.path.join(root, 'sass'),
            os.path.join(root, 'public', 'css'),
        ))
        subprocess.Popen(['sass',
            '--scss',
            '--style', 'compressed',
            '--stop-on-error',
            '--update', sass_paths,
        ]).wait()

    # CONFIGURATION OPTIONS HERE (note: all config options will override
    # any Pylons config options)

    # Create file storage object and stick it back in the config
    storage = filestore.get_storage(config)
    config['filestore'] = storage

    return config
{'fraction_non_alphanumeric': 0.10852842809364549, 'fraction_numerical': 0.0008361204013377926, 'mean_word_length': 3.565648854961832, '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': '1433493', 'n_tokens_mistral': 1851, 'n_tokens_neox': 1819, 'n_words': 435}