当前位置: 首页>>代码示例>>Python>>正文


Python plac.call方法代码示例

本文整理汇总了Python中plac.call方法的典型用法代码示例。如果您正苦于以下问题:Python plac.call方法的具体用法?Python plac.call怎么用?Python plac.call使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在plac的用法示例。


在下文中一共展示了plac.call方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import plac [as 别名]
# 或者: from plac import call [as 别名]
def main(args=None):
    commands = {
        'train': train,
        'download': download,
        'link': link
    }
    if len(sys.argv) == 1:
        print("{title}: {content}, exits: {exits}".format(
            content=', '.join(commands),
            title="Available commands",
            exits=1)
        )

    command = sys.argv.pop(1)
    sys.argv[0] = 'MicroTokenizer %s' % command

    if command in commands:
        plac.call(commands[command], sys.argv[1:])
    else:
        print("{title}: {content}, exits: {exits}".format(
            content="Available: %s" % ', '.join(commands),
            title="Unknown command: %s" % command,
            exits=1)
        ) 
开发者ID:howl-anderson,项目名称:MicroTokenizer,代码行数:26,代码来源:cli.py

示例2: main

# 需要导入模块: import plac [as 别名]
# 或者: from plac import call [as 别名]
def main(verbose, interactive, multiline, serve, batch, test, fname='',
         *extra):
    "Runner for plac tools, plac batch files and plac tests"
    baseparser = plac.parser_from(main)
    if not fname:
        baseparser.print_help()
    elif sys.argv[1] == fname:  # script mode
        plactool = plac.import_main(fname)
        plactool.prog = os.path.basename(sys.argv[0]) + ' ' + fname
        out = plac.call(plactool, sys.argv[2:], eager=False)
        if plac.iterable(out):
            for output in out:
                print(output)
        else:
            print(out)
    elif interactive or multiline or serve:
        plactool = plac.import_main(fname, *extra)
        plactool.prog = ''
        i = plac.Interpreter(plactool)
        if interactive:
            i.interact(verbose=verbose)
        elif multiline:
            i.multiline(verbose=verbose)
        elif serve:
            i.start_server(serve)
    elif batch:
        run((fname,) + extra, 'execute', verbose)
    elif test:
        run((fname,) + extra, 'doctest', verbose)
        print('run %s plac test(s)' % (len(extra) + 1))
    else:
        baseparser.print_usage() 
开发者ID:micheles,项目名称:plac,代码行数:34,代码来源:plac_runner.py

示例3: test_kwargs

# 需要导入模块: import plac [as 别名]
# 或者: from plac import call [as 别名]
def test_kwargs():
    def main(opt, arg1, *args, **kw):
        print(opt, arg1)
        return args, kw
    main.__annotations__ = dict(opt=('Option', 'option'))
    argskw = plac.call(main, ['arg1', 'arg2', 'a=1', 'b=2'])
    assert argskw == [('arg2',), {'a': '1', 'b': '2'}], argskw

    argskw = plac.call(main, ['arg1', 'arg2', 'a=1', '-o', '2'])
    assert argskw == [('arg2',), {'a': '1'}], argskw

    expect(SystemExit, plac.call, main, ['arg1', 'arg2', 'a=1', 'opt=2']) 
开发者ID:micheles,项目名称:plac,代码行数:14,代码来源:test_plac.py

示例4: test_kwargs2

# 需要导入模块: import plac [as 别名]
# 或者: from plac import call [as 别名]
def test_kwargs2():
    # see https://github.com/micheles/plac/issues/39
    def main(**kw):
        return kw.items()
    assert plac.call(main, ['a=1']) == [('a', '1')]
    expect(SystemExit, plac.call, main, ['foo'])
    expect(SystemExit, plac.call, main, ['foo', 'a=1']) 
开发者ID:micheles,项目名称:plac,代码行数:9,代码来源:test_plac.py

示例5: test_kwargs3

# 需要导入模块: import plac [as 别名]
# 或者: from plac import call [as 别名]
def test_kwargs3():
    # see https://github.com/micheles/plac/issues/38
    def main(opt='foo', **kw):
        return opt, kw
    main.__annotations__ = dict(opt=('Option', 'option'))
    assert plac.call(main, ['-o', 'abc=']) == ['abc=', {}]
    assert plac.call(main, ['-o', 'abc=', 'z=1']) == ['abc=', {'z': '1'}]
    assert plac.call(main, ['z=1']) == ['foo', {'z': '1'}] 
开发者ID:micheles,项目名称:plac,代码行数:10,代码来源:test_plac.py

示例6: test_cmds

# 需要导入模块: import plac [as 别名]
# 或者: from plac import call [as 别名]
def test_cmds():
    assert 'commit' == plac.call(cmds, ['commit'])
    assert ['help', 'foo'] == plac.call(cmds, ['help', 'foo'])
    expect(SystemExit, plac.call, cmds, []) 
开发者ID:micheles,项目名称:plac,代码行数:6,代码来源:test_plac.py

示例7: test_sub_help

# 需要导入模块: import plac [as 别名]
# 或者: from plac import call [as 别名]
def test_sub_help():
    c = Cmds()
    c.add_help = True
    expect(SystemExit, plac.call, c, ['commit', '-h']) 
开发者ID:micheles,项目名称:plac,代码行数:6,代码来源:test_plac.py

示例8: test_yield

# 需要导入模块: import plac [as 别名]
# 或者: from plac import call [as 别名]
def test_yield():
    def main():
        for i in (1, 2, 3):
            yield i
    assert plac.call(main, []) == [1, 2, 3] 
开发者ID:micheles,项目名称:plac,代码行数:7,代码来源:test_plac.py

示例9: check_script

# 需要导入模块: import plac [as 别名]
# 或者: from plac import call [as 别名]
def check_script(args):
    if failing_scripts.intersection(args):
        assert subprocess.call(args) > 0, (  # expected failure
            'Unexpected success for %s' % ' '.join(args))
    else:
        assert subprocess.call(args) == 0, 'Failed %s' % ' '.join(args) 
开发者ID:micheles,项目名称:plac,代码行数:8,代码来源:test_plac.py

示例10: main

# 需要导入模块: import plac [as 别名]
# 或者: from plac import call [as 别名]
def main(interactive, *subcommands):
    """
    This script works both interactively and non-interactively.
    Use .help to see the internal commands.
    """
    if interactive:
        plac.Interpreter(ishelve.main).interact()
    else:
        for out in plac.call(ishelve.main, subcommands):
            print(out) 
开发者ID:micheles,项目名称:plac,代码行数:12,代码来源:shelve_interpreter.py

示例11: test

# 需要导入模块: import plac [as 别名]
# 或者: from plac import call [as 别名]
def test():
    assert plac.call(ishelve.main, ['.clear']) == ['cleared the shelve']
    assert plac.call(ishelve.main, ['a=1']) == ['setting a=1']
    assert plac.call(ishelve.main, ['a']) == ['1']
    assert plac.call(ishelve.main, ['.delete=a']) == ['deleted a']
    assert plac.call(ishelve.main, ['a']) == ['a: not found'] 
开发者ID:micheles,项目名称:plac,代码行数:8,代码来源:test_ishelve.py

示例12: entrypoint

# 需要导入模块: import plac [as 别名]
# 或者: from plac import call [as 别名]
def entrypoint():
  plac.call(main) 
开发者ID:abatilo,项目名称:typed-json-dataclass,代码行数:4,代码来源:main.py

示例13: main

# 需要导入模块: import plac [as 别名]
# 或者: from plac import call [as 别名]
def main():
    plac.call(cli) 
开发者ID:fhamborg,项目名称:news-please,代码行数:4,代码来源:__main__.py

示例14: entry_point

# 需要导入模块: import plac [as 别名]
# 或者: from plac import call [as 别名]
def entry_point():
    plac.call(main) 
开发者ID:chakki-works,项目名称:sumeval,代码行数:4,代码来源:sum_eval.py


注:本文中的plac.call方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。