<commit_before>"""
virtstrap_system.runner
-----------------------

The system wide script runner
"""
import re
import sys
from argparse import ArgumentParser
from virtstrap.loaders import *
from virtstrap.project import *
from virtstrap.options import create_project_parser
from virtstrap_system.loaders import ProjectCommandCollector
from virtstrap.runner import VirtstrapRunner
from virtstrap import commands
from virtstrap import constants
from virtstrap.registry import CommandDoesNotExist

VS_DIR_OPTION = '--virtstrap-dir'
PROJ_DIR_OPTION = '--project-dir'

EXIT_OK = 0
EXIT_FAIL = 2

class ProjectFactory(commands.ProjectMixin):
    def __call__(self, args):
        project_args = self.gather_project_args(args)

        parser = self.project_parser()
        options = parser.parse_args(project_args)
        try:
            project = self.load_project(options)
        except NoProjectFound:
            return None
        return project

    def project_parser(self):
        return create_project_parser()

    def gather_project_args(self, args):
        project_args = []
        options = ['virtstrap-dir', 'profiles', 'project-dir', 'config-file']
        joined_options = '|'.join(options)
        option_regex = '^--(%s)=' % joined_options
        matcher = re.compile(option_regex)
        for arg in args:
            match = matcher.match(arg)
            if match:
                project_args.append(arg)
        return project_args

NONE_OBJ = object()

def create_loader(args, project):
    main_collector = BuiltinCommandCollector('virtstrap_system.commands')
    plugin_collector = PluginCommandCollector('virtstrap_system.commands')
    project_collector = ProjectCommandCollector(args, project)
    return CommandLoader(collectors=[main_collector, plugin_collector, 
        project_collector])

class VirtstrapSystemWideRunner(VirtstrapRunner):
    def __init__(self, project_factory=None):
        super(VirtstrapSystemWideRunner, self).__init__(
                loader_factory=create_loader)
        self._project = NONE_OBJ
        self._project_factory = project_factory or ProjectFactory()

    def main(self, args=None):<commit_msg>Small aesthetic improvement<commit_after>"""
virtstrap_system.runner
-----------------------

The system wide script runner. The need for separation between the system wide
runner and the project's local runner is to provide support for different
python versions while still using all of the same code. 
"""
import re
import sys
from argparse import ArgumentParser
from virtstrap.loaders import *
from virtstrap.project import *
from virtstrap.options import create_project_parser
from virtstrap_system.loaders import ProjectCommandCollector
from virtstrap.runner import VirtstrapRunner
from virtstrap import commands
from virtstrap import constants
from virtstrap.registry import CommandDoesNotExist

VS_DIR_OPTION = '--virtstrap-dir'
PROJ_DIR_OPTION = '--project-dir'

EXIT_OK = 0
EXIT_FAIL = 2

class ProjectFactory(commands.ProjectMixin):
    def __call__(self, args):
        project_args = self.gather_project_args(args)

        parser = self.project_parser()
        options = parser.parse_args(project_args)
        try:
            project = self.load_project(options)
        except NoProjectFound:
            return None
        return project

    def project_parser(self):
        return create_project_parser()

    def gather_project_args(self, args):
        project_args = []
        options = ['virtstrap-dir', 'profiles', 'project-dir', 'config-file']
        joined_options = '|'.join(options)
        option_regex = '^--(%s)=' % joined_options
        matcher = re.compile(option_regex)
        for arg in args:
            match = matcher.match(arg)
            if match:
                project_args.append(arg)
        return project_args

NONE_OBJ = object()

def create_loader(args, project):
    main_collector = BuiltinCommandCollector('virtstrap_system.commands')
    plugin_collector = PluginCommandCollector('virtstrap_system.commands')
    project_collector = ProjectCommandCollector(args, project)
    return CommandLoader(collectors=[main_collector, plugin_collector, 
        project_collector])

class VirtstrapSystemWideRunner(VirtstrapRunner):
    def __init__(self, project_factory=None, **kwargs):
        kwargs['loader_factory'] = create_loader
        super(VirtstrapSystemWideRunner, self).__init__(**kwargs)
        self._project = NONE_OBJ
        self._project_factory = project_factory or ProjectFactory()

    def main(self, args=None):
{'fraction_non_alphanumeric': 0.08907415533128565, 'fraction_numerical': 0.0008775778850372971, 'mean_word_length': 3.5183349851337957, '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': '5600211', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1232, 'n_words': 307}