當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。