本文整理汇总了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)
)
示例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()
示例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'])
示例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'])
示例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'}]
示例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, [])
示例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'])
示例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]
示例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)
示例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)
示例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']
示例12: entrypoint
# 需要导入模块: import plac [as 别名]
# 或者: from plac import call [as 别名]
def entrypoint():
plac.call(main)
示例13: main
# 需要导入模块: import plac [as 别名]
# 或者: from plac import call [as 别名]
def main():
plac.call(cli)
示例14: entry_point
# 需要导入模块: import plac [as 别名]
# 或者: from plac import call [as 别名]
def entry_point():
plac.call(main)