<commit_before>import argh
import os
import toml
from glob import glob
from .run_spec import run_spec
from .cli import to_hosts
from .run_crate import CrateNode, get_crate


class Executor:
    def __init__(self, track_dir, result_hosts=None, crate_root=None):
        self.track_dir = track_dir
        self.result_hosts = result_hosts
        self.crate_root = crate_root

    def _expand_paths(self, paths):
        paths = (os.path.join(self.track_dir, path) for path in paths)
        paths = (os.path.abspath(path) for path in paths)
        return (p for path in paths for p in glob(path))

    def _run_specs(self, specs, benchmark_host):
        specs = self._expand_paths(specs)
        for spec in specs:
            print('### Running spec file: ', os.path.basename(spec))
            run_spec(spec, to_hosts(benchmark_host), self.result_hosts)

    def execute(self, track):
        configurations = list(self._expand_paths(track['configurations']))
        versions = track['versions']
        for version in versions:
            print('# Version: ', version)
            for c, configuration in enumerate(configurations):
                print('## Starting Crate {0}, configuration: {1}'.format(
                    os.path.basename(version),
                    os.path.basename(configuration)
                ))
                configuration = toml.load(os.path.join(self.track_dir, configuration))
                crate_dir = get_crate(version, self.crate_root)
                with CrateNode(crate_dir=crate_dir,
                               env=configuration.get('env'),
                               settings=configuration.get('settings')) as node:
                    node.start()
                    self._run_specs(track['specs'], node.http_url)


@argh.arg('-r', '--result_hosts', type=to_hosts)
def run_track(track, result_hosts=None, crate_root=None):
    """Execute a track file"""
    executor = Executor(
        track_dir=os.path.dirname(track),
        result_hosts=result_hosts,
        crate_root=crate_root
    )
    executor.execute(toml.load(track))


def main():
    argh.dispatch_command(run_track)


if __name__ == "__main__":
    main()<commit_msg>Add `output-fmt` option to run-track<commit_after>import argh
import os
import toml
from glob import glob
from .run_spec import run_spec
from .cli import to_hosts
from .run_crate import CrateNode, get_crate


class Executor:
    def __init__(self, track_dir, result_hosts=None, crate_root=None, output_fmt=None):
        self.track_dir = track_dir
        self.result_hosts = result_hosts
        self.crate_root = crate_root
        self.output_fmt = output_fmt

    def _expand_paths(self, paths):
        paths = (os.path.join(self.track_dir, path) for path in paths)
        paths = (os.path.abspath(path) for path in paths)
        return (p for path in paths for p in glob(path))

    def _run_specs(self, specs, benchmark_host):
        specs = self._expand_paths(specs)
        for spec in specs:
            print('### Running spec file: ', os.path.basename(spec))
            run_spec(
                spec,
                to_hosts(benchmark_host),
                self.result_hosts,
                output_fmt=self.output_fmt)

    def execute(self, track):
        configurations = list(self._expand_paths(track['configurations']))
        versions = track['versions']
        for version in versions:
            print('# Version: ', version)
            for c, configuration in enumerate(configurations):
                print('## Starting Crate {0}, configuration: {1}'.format(
                    os.path.basename(version),
                    os.path.basename(configuration)
                ))
                configuration = toml.load(os.path.join(self.track_dir, configuration))
                crate_dir = get_crate(version, self.crate_root)
                with CrateNode(crate_dir=crate_dir,
                               env=configuration.get('env'),
                               settings=configuration.get('settings')) as node:
                    node.start()
                    self._run_specs(track['specs'], node.http_url)


@argh.arg('-r', '--result_hosts', type=to_hosts)
@argh.arg('-of', '--output-fmt', choices=['full', 'short'], default='full')
def run_track(track, result_hosts=None, crate_root=None, output_fmt=None):
    """Execute a track file"""
    executor = Executor(
        track_dir=os.path.dirname(track),
        result_hosts=result_hosts,
        crate_root=crate_root,
        output_fmt=output_fmt
    )
    executor.execute(toml.load(track))


def main():
    argh.dispatch_command(run_track)


if __name__ == "__main__":
    main()
{'fraction_non_alphanumeric': 0.10876068376068376, 'fraction_numerical': 0.0008547008547008547, 'mean_word_length': 2.4043636363636365, 'pattern_counts': {'":': 2, '<': 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': '5659492', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1363, 'n_words': 307}