<commit_before>from __future__ import print_function

import argparse
import sys
import os

from bokeh.settings import settings
from bokeh.application import Application
from bokeh.server.server import Server
from bokeh.application.spellings import ScriptHandler, DirectoryHandler
from bokeh.io import output_file, save, show

import logging
log = logging.getLogger(__name__)

def die(message):
    print(message, file=sys.stderr)
    sys.exit(1)

class Subcommand(object):
    """Abstract base class for subcommands"""

    def __init__(self, parser):
        """Initialize the subcommand with its parser; can call parser.add_argument to add subcommand flags"""
        self.parser = parser

    def func(self, args):
        """Takes over main program flow to perform the subcommand"""
        pass

class ApplicationsSubcommand(Subcommand):
    """Abstract base class for subcommand that operates on a list of applications."""

    def __init__(self, **kwargs):
        super(ApplicationsSubcommand, self).__init__(**kwargs)
        self.parser.add_argument('files', metavar='DIRECTORY-OR-SCRIPT', nargs='*',  help="The app directories or scripts to serve (serve empty document if not specified)", default=None)

    def build_applications(self, args):
        if args.files:
            files = args.files
        else:
            files = []

        applications = {}

        for file in files:
            file = os.path.abspath(file)
            if os.path.isdir(file):
                handler = DirectoryHandler(filename=file)
            else:
                handler = ScriptHandler(filename=file)
<commit_msg>die with error message if handler init fails<commit_after>from __future__ import print_function

import argparse
import sys
import os

from bokeh.settings import settings
from bokeh.application import Application
from bokeh.server.server import Server
from bokeh.application.spellings import ScriptHandler, DirectoryHandler
from bokeh.io import output_file, save, show

import logging
log = logging.getLogger(__name__)

def die(message):
    print(message, file=sys.stderr)
    sys.exit(1)

class Subcommand(object):
    """Abstract base class for subcommands"""

    def __init__(self, parser):
        """Initialize the subcommand with its parser; can call parser.add_argument to add subcommand flags"""
        self.parser = parser

    def func(self, args):
        """Takes over main program flow to perform the subcommand"""
        pass

class ApplicationsSubcommand(Subcommand):
    """Abstract base class for subcommand that operates on a list of applications."""

    def __init__(self, **kwargs):
        super(ApplicationsSubcommand, self).__init__(**kwargs)
        self.parser.add_argument('files', metavar='DIRECTORY-OR-SCRIPT', nargs='*',  help="The app directories or scripts to serve (serve empty document if not specified)", default=None)

    def build_applications(self, args):
        if args.files:
            files = args.files
        else:
            files = []

        applications = {}

        for file in files:
            file = os.path.abspath(file)
            if os.path.isdir(file):
                handler = DirectoryHandler(filename=file)
            else:
                handler = ScriptHandler(filename=file)

            if handler.failed:
                die("Error running application handler %r: %s %s " % (handler, handler.error, handler.error_detail))

{'fraction_non_alphanumeric': 0.08966121495327103, 'fraction_numerical': 0.0005841121495327102, 'mean_word_length': 3.106714628297362, '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': '5969864', 'n_tokens_mistral': 915, 'n_tokens_neox': 890, 'n_words': 297}