本文整理汇总了Python中pants.help.build_dictionary_info_extracter.BuildDictionaryInfoExtracter类的典型用法代码示例。如果您正苦于以下问题:Python BuildDictionaryInfoExtracter类的具体用法?Python BuildDictionaryInfoExtracter怎么用?Python BuildDictionaryInfoExtracter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BuildDictionaryInfoExtracter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_target_args
def test_get_target_args(self):
class Target1(Target):
def __init__(self, arg1, arg2=42, **kwargs):
"""
:param arg1: The first arg.
:param arg2: The second arg.
"""
super(Target1, self).__init__(**kwargs)
class Target2(Target1):
pass
class Target3(Target2):
def __init__(self, arg3, arg4=None, **kwargs):
super(Target1, self).__init__(**kwargs)
self.assertEqual(sorted(BuildDictionaryInfoExtracter.basic_target_args + [
FunctionArg('arg1', 'The first arg.', False, None),
FunctionArg('arg2', 'The second arg.', True, 42),
FunctionArg('arg3', '', False, None),
FunctionArg('arg4', '', True, None)
]),
sorted(BuildDictionaryInfoExtracter.get_args_for_target_type(Target3)))
# Check a trivial case.
class Target4(Target):
pass
self.assertEqual(BuildDictionaryInfoExtracter.basic_target_args,
BuildDictionaryInfoExtracter.get_args_for_target_type(Target4))
示例2: console_output
def console_output(self, targets):
buildfile_aliases = self.context.build_file_parser.registered_aliases()
extracter = BuildDictionaryInfoExtracter(buildfile_aliases)
alias = self.get_options().details
if alias:
target_types = buildfile_aliases.target_types_by_alias.get(alias)
if target_types:
tti = next(x for x in extracter.get_target_type_info() if x.build_file_alias == alias)
yield blue('\n{}\n'.format(tti.description))
yield blue('{}('.format(alias))
for arg in extracter.get_target_args(list(target_types)[0]):
default = green('(default: {})'.format(arg.default) if arg.has_default else '')
yield '{:<30} {}'.format(
cyan(' {} = ...,'.format(arg.name)),
' {}{}{}'.format(arg.description, ' ' if arg.description else '', default))
yield blue(')')
else:
yield 'No such target type: {}'.format(alias)
else:
for tti in extracter.get_target_type_info():
description = tti.description or '<Add description>'
yield '{} {}'.format(cyan('{:>30}:'.format(tti.build_file_alias)), description)
示例3: test_get_target_type_info
def test_get_target_type_info(self):
class Target1(Target):
"""Target1 docstring."""
pass
class Target2(Target):
"""Target2 docstring."""
pass
class Target3(Target):
"""Target3 docstring."""
pass
# We shouldn't get as far as invoking the context factory, so it can be trivial.
macro_factory = TargetMacro.Factory.wrap(lambda ctx: None, Target2)
bfa = BuildFileAliases(targets={
'target1': Target1,
'target2': macro_factory,
'target3': Target3,
},
objects={},
context_aware_object_factories={}
)
extracter = BuildDictionaryInfoExtracter(bfa)
args = BuildDictionaryInfoExtracter.basic_target_args
self.assertEqual([BuildSymbolInfo('target1', 'Target1 docstring.', [], args),
BuildSymbolInfo('target2', 'Target2 docstring.', [], args),
BuildSymbolInfo('target3', 'Target3 docstring.', [], args)],
extracter.get_target_type_info())
示例4: test_get_target_type_info
def test_get_target_type_info(self):
class Target1(Target):
"""Target1 docstring."""
pass
class Target2a(Target):
# No docstring, so we should take the onefrom Target2b.
pass
class Target2b(Target):
"""Target2 docstring."""
pass
class Target3(Target):
"""Target3 docstring."""
pass
# We shouldn't get as far as invoking the context factory, so it can be trivial.
macro_factory = TargetMacro.Factory.wrap(lambda ctx: None, Target2a, Target2b)
bfa = BuildFileAliases(targets={
'target1': Target1,
'target2': macro_factory,
'target3': Target3,
},
objects={},
context_aware_object_factories={}
)
extracter = BuildDictionaryInfoExtracter(bfa)
self.assertEquals([TargetTypeInfo('target1', 'Target1 docstring.'),
TargetTypeInfo('target2', 'Target2 docstring.'),
TargetTypeInfo('target3', 'Target3 docstring.')],
extracter.get_target_type_info())
示例5: test_get_function_args
def test_get_function_args(self):
# Test standalone function.
def func(arg1, arg2, arg3=42, arg4=None, arg5='foo'):
pass
self.assertEqual([FunctionArg('arg1', '', False, None), FunctionArg('arg2', '', False, None),
FunctionArg('arg3', '', True, 42), FunctionArg('arg4', '', True, None),
FunctionArg('arg5', '', True, 'foo')],
BuildDictionaryInfoExtracter.get_function_args(func))
# Test member function.
class TestCls(object):
def __init__(self, arg1, arg2=False):
pass
self.assertEqual([FunctionArg('arg1', '', False, None), FunctionArg('arg2', '', True, False)],
BuildDictionaryInfoExtracter.get_function_args(TestCls.__init__))
# Test *args, **kwargs situation.
def generic_func(arg1, arg2=42, *args, **kwargs):
"""
:param arg1: The first arg.
:param arg2: The second arg.
:param args: Some extra varargs.
:param arg3: The third arg.
:param arg4: The fourth arg (default: 'Foo').
"""
self.assertEqual([FunctionArg('arg1', 'The first arg.', False, None),
FunctionArg('arg2', 'The second arg.', True, 42),
FunctionArg('*args', 'Some extra varargs.', False, None),
FunctionArg('arg3', 'The third arg.', True, None),
FunctionArg('arg4', "The fourth arg.", True, "'Foo'")],
BuildDictionaryInfoExtracter.get_function_args(generic_func))
示例6: _gen_build_dictionary
def _gen_build_dictionary(self):
buildfile_aliases = self.context.build_file_parser.registered_aliases()
extracter = BuildDictionaryInfoExtracter(buildfile_aliases)
target_type_infos = extracter.get_target_type_info()
other_infos = sorted(extracter.get_object_info() + extracter.get_object_factory_info())
self._do_render(self.get_options().build_dictionary_template, {
'target_types': {
'infos': target_type_infos
},
'other_symbols': {
'infos': other_infos
}
})
示例7: test_get_description_from_docstring
def test_get_description_from_docstring(self):
class Test1(object):
"""First line.
Subsequent lines.
"""
self.assertEqual("First line.", BuildDictionaryInfoExtracter.get_description_from_docstring(Test1))
class Test2(object):
"""Only one line."""
self.assertEqual("Only one line.", BuildDictionaryInfoExtracter.get_description_from_docstring(Test2))
示例8: _gen_build_dictionary
def _gen_build_dictionary(self):
buildfile_aliases = self.context.build_configuration.registered_aliases()
extracter = BuildDictionaryInfoExtracter(buildfile_aliases)
target_type_infos = extracter.get_target_type_info()
other_infos = sorted(extracter.get_object_info() + extracter.get_object_factory_info())
build_dict_page = self._do_render(self.get_options().build_dictionary_template, {
'target_types': {
'infos': target_type_infos
},
'other_symbols': {
'infos': other_infos
}
})
self.context.products.register_data(self.BUILD_DICTIONARY_PRODUCT, build_dict_page)
示例9: test_get_function_args
def test_get_function_args(self):
# Test standalone function.
def func(arg1, arg2, arg3=42, arg4=None, arg5='foo'):
pass
self.assertEqual([FunctionArg('arg1', '', False, None), FunctionArg('arg2', '', False, None),
FunctionArg('arg3', '', True, 42), FunctionArg('arg4', '', True, None),
FunctionArg('arg5', '', True, 'foo')],
BuildDictionaryInfoExtracter.get_function_args(func))
# Test member function.
class TestCls(object):
def __init__(self, arg1, arg2=False):
pass
self.assertEqual([FunctionArg('arg1', '', False, None), FunctionArg('arg2', '', True, False)],
BuildDictionaryInfoExtracter.get_function_args(TestCls.__init__))
示例10: test_get_description_from_docstring
def test_get_description_from_docstring(self):
class Test1(object):
"""First line.
Subsequent
lines.
with indentations
"""
self.assertEqual(('First line.', ['Subsequent', 'lines.', '', ' with indentations']),
BuildDictionaryInfoExtracter.get_description_from_docstring(Test1))
class Test2(object):
"""Only one line."""
self.assertEqual(('Only one line.', []),
BuildDictionaryInfoExtracter.get_description_from_docstring(Test2))
示例11: test_get_arg_descriptions_from_docstring
def test_get_arg_descriptions_from_docstring(self):
def func(a, b, c):
"""Foo function.
:param a: Parameter a.
:param str b: Parameter b.
:param c: Parameter c.
"""
self.assertEqual({'a': 'Parameter a.', 'b': 'Parameter b.', 'c': 'Parameter c.'},
BuildDictionaryInfoExtracter.get_arg_descriptions_from_docstring(func))
示例12: console_output
def console_output(self, targets):
buildfile_aliases = self.context.build_file_parser.registered_aliases()
extracter = BuildDictionaryInfoExtracter(buildfile_aliases)
alias = self.get_options().details
if alias:
tti = next(x for x in extracter.get_target_type_info() if x.symbol == alias)
yield blue('\n{}\n'.format(tti.description))
yield blue('{}('.format(alias))
for arg in tti.args:
default = green('(default: {})'.format(arg.default) if arg.has_default else '')
yield '{:<30} {}'.format(
cyan(' {} = ...,'.format(arg.name)),
' {}{}{}'.format(arg.description, ' ' if arg.description else '', default))
yield blue(')')
else:
for tti in extracter.get_target_type_info():
yield '{} {}'.format(cyan('{:>30}:'.format(tti.symbol)), tti.description)
示例13: test_get_object_factory_info
def test_get_object_factory_info(self):
class Foo(object):
"""Foo docstring."""
def __call__(self, bar, baz=42):
"""
:param bar: Bar details.
:param int baz: Baz details.
"""
bfa = BuildFileAliases(targets={},
objects={},
context_aware_object_factories={
'foo': Foo
}
)
extracter = BuildDictionaryInfoExtracter(bfa)
self.assertEqual([BuildSymbolInfo('foo', 'Foo docstring.', [],
[FunctionArg('bar', 'Bar details.', False, None),
FunctionArg('baz', 'Baz details.', True, 42)])],
extracter.get_object_factory_info())
示例14: test_get_arg_descriptions_from_docstring
def test_get_arg_descriptions_from_docstring(self):
def func(a, b, c):
"""Foo function.
:param a: Parameter a.
:param str b: Parameter b.
:param c: Parameter c.
"""
self.assertEqual(
{"a": "Parameter a.", "b": "Parameter b.", "c": "Parameter c."},
BuildDictionaryInfoExtracter.get_arg_descriptions_from_docstring(func),
)
示例15: test_get_object_info_datatype
def test_get_object_info_datatype(self):
class FooDatatype(datatype(['bar', 'baz'])):
"""Foo docstring."""
def __new__(cls, bar, baz=42):
"""
:param bar: Bar details.
:param int baz: Baz details.
"""
return super(FooDatatype, cls).__new__(cls, bar, baz)
bfa = BuildFileAliases(targets={},
objects={
'foo': FooDatatype
},
context_aware_object_factories={},
)
extracter = BuildDictionaryInfoExtracter(bfa)
self.assertEqual([BuildSymbolInfo('foo', 'Foo docstring.', [],
[FunctionArg('bar', 'Bar details.', False, None),
FunctionArg('baz', 'Baz details.', True, 42)])],
extracter.get_object_info())