Пример #1
0
def test_tabulate():
    rows = [
        ['foo', 'a'],
        ['barbar', 'baz'],
    ]
    assert '\n'.join(tabulate(rows, margin=0)) == ('foo    | a  \n'
                                                   'barbar | baz')

    assert '\n'.join(tabulate(rows, margin=1)) == ('foo     | a   \n'
                                                   'barbar  | baz ')

    assert '\n'.join(tabulate(rows, headers=['FOO', 'BARBAZZZ'],
                              margin=0)) == ('FOO    | BARBAZZZ\n'
                                             'foo    | a       \n'
                                             'barbar | baz     ')
Пример #2
0
def handle(args):
    from camisole.languages import all
    from camisole.utils import tabulate
    headers = ("Name", "Display name", "Module", "Class name")
    rows = [(lang, cls.name, cls.__module__, cls.__name__)
            for lang, cls in sorted(all().items())]
    print("\n".join(tabulate(rows, headers=headers)))
    return 0
Пример #3
0
def handle(args):
    from camisole.languages import all
    from camisole.utils import tabulate

    async def execute():
        return [(lang,) + await benchmark(lang, args.verbose)
                for lang in sorted(all())]

    rows = asyncio.get_event_loop().run_until_complete(execute())
    headers = ("Language",
               "Memory (kB)",
               "Max RSS (kB)",
               "Time (s)",
               "Wall time (s)")
    print("\n".join(tabulate(rows, headers=headers, align='<><<<')))
    return 0
Пример #4
0
def main():
    import argparse
    import asyncio
    import camisole.loader
    import camisole.http
    import logging
    import os

    parser = argparse.ArgumentParser(
        description="asyncio-based source compiler and test runner")
    parser.add_argument(
        '-l',
        '--logging',
        default='error',
        choices=[l.lower() for l in logging._nameToLevel],
        help="logging level")
    parser.add_argument(
        '-m',
        '--module',
        dest='modules',
        action='append',
        help="extra modules to load (customize search path with CAMISOLEPATH)")

    cmd = parser.add_subparsers(dest='command')

    parse_serve = cmd.add_parser('serve', add_help=False)
    parse_serve.add_argument('-h', '--host', default='0.0.0.0')
    parse_serve.add_argument('-p', '--port', type=int, default=8080)
    parse_serve.add_argument('--help', action='help')

    parse_languages = cmd.add_parser('languages')

    parse_test = cmd.add_parser('test')
    parse_test.add_argument(
        '-v',
        dest='verbose',
        action='append_const',
        const=1,
        help="increase verbosity (up to two)")
    parse_test.add_argument(
        'languages',
        nargs=argparse.REMAINDER,
        help="languages to test")
    args = parser.parse_args()

    logging.basicConfig(level=args.logging.upper())

    # import built-in languages
    camisole.languages._import_builtins()

    # import extra languages
    if args.modules:
        path = os.environ.get('CAMISOLEPATH', '')
        camisole.loader.load_modules(args.modules, path)

    loop = asyncio.get_event_loop()

    if args.command == 'languages':
        from camisole.languages import all
        rows = [(lang, cls.name, cls.__module__, cls.__name__)
                for lang, cls in sorted(all().items())]
        print("\n".join(tabulate(rows,
            headers=("Name", "Display name", "Module", "Class name"))))

    elif args.command == 'test':
        from camisole.languages import all
        languages = args.languages or all().keys()
        verbosity = sum(args.verbose or [])
        loop.run_until_complete(print_working_languages(languages, verbosity))

    elif args.command == 'serve':
        from camisole.languages import all
        logging.info("Registry has %d languages:\n%s", len(all()),
                     '\n'.join(f'    {l!r}' for l in all().values()))
        camisole.http.run(host=args.host, port=args.port)

    else:
        parser.exit(message=parser.format_usage())