本文整理汇总了Python中pants.build_graph.build_configuration.BuildConfiguration.register_aliases方法的典型用法代码示例。如果您正苦于以下问题:Python BuildConfiguration.register_aliases方法的具体用法?Python BuildConfiguration.register_aliases怎么用?Python BuildConfiguration.register_aliases使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pants.build_graph.build_configuration.BuildConfiguration
的用法示例。
在下文中一共展示了BuildConfiguration.register_aliases方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BaseTest
# 需要导入模块: from pants.build_graph.build_configuration import BuildConfiguration [as 别名]
# 或者: from pants.build_graph.build_configuration.BuildConfiguration import register_aliases [as 别名]
#.........这里部分代码省略.........
@property
def alias_groups(self):
return BuildFileAliases(targets={'target': Target})
def setUp(self):
super(BaseTest, self).setUp()
Goal.clear()
Subsystem.reset()
self.real_build_root = BuildRoot().path
self.build_root = os.path.realpath(mkdtemp(suffix='_BUILD_ROOT'))
self.addCleanup(safe_rmtree, self.build_root)
self.pants_workdir = os.path.join(self.build_root, '.pants.d')
safe_mkdir(self.pants_workdir)
self.options = defaultdict(dict) # scope -> key-value mapping.
self.options[''] = {
'pants_workdir': self.pants_workdir,
'pants_supportdir': os.path.join(self.build_root, 'build-support'),
'pants_distdir': os.path.join(self.build_root, 'dist'),
'pants_configdir': os.path.join(self.build_root, 'config'),
'cache_key_gen_version': '0-test',
}
BuildRoot().path = self.build_root
self.addCleanup(BuildRoot().reset)
# We need a pants.ini, even if empty. get_buildroot() uses its presence.
self.create_file('pants.ini')
self._build_configuration = BuildConfiguration()
self._build_configuration.register_aliases(self.alias_groups)
self.build_file_parser = BuildFileParser(self._build_configuration, self.build_root)
self.address_mapper = BuildFileAddressMapper(self.build_file_parser, FilesystemBuildFile)
self.build_graph = BuildGraph(address_mapper=self.address_mapper)
def buildroot_files(self, relpath=None):
"""Returns the set of all files under the test build root.
:param string relpath: If supplied, only collect files from this subtree.
:returns: All file paths found.
:rtype: set
"""
def scan():
for root, dirs, files in os.walk(os.path.join(self.build_root, relpath or '')):
for f in files:
yield os.path.relpath(os.path.join(root, f), self.build_root)
return set(scan())
def reset_build_graph(self):
"""Start over with a fresh build graph with no targets in it."""
self.address_mapper = BuildFileAddressMapper(self.build_file_parser, FilesystemBuildFile)
self.build_graph = BuildGraph(address_mapper=self.address_mapper)
def set_options_for_scope(self, scope, **kwargs):
self.options[scope].update(kwargs)
def context(self, for_task_types=None, options=None, passthru_args=None, target_roots=None,
console_outstream=None, workspace=None, for_subsystems=None):
# Many tests use source root functionality via the SourceRootConfig.global_instance()
# (typically accessed via Target.target_base), so we always set it up, for convenience.
optionables = {SourceRootConfig}
extra_scopes = set()
示例2: BuildConfigurationTest
# 需要导入模块: from pants.build_graph.build_configuration import BuildConfiguration [as 别名]
# 或者: from pants.build_graph.build_configuration.BuildConfiguration import register_aliases [as 别名]
class BuildConfigurationTest(unittest.TestCase):
def setUp(self):
self.build_configuration = BuildConfiguration()
def _register_aliases(self, **kwargs):
self.build_configuration.register_aliases(BuildFileAliases(**kwargs))
def test_register_bad(self):
with self.assertRaises(TypeError):
self.build_configuration.register_aliases(42)
def test_register_target_alias(self):
class Fred(Target):
pass
self._register_aliases(targets={'fred': Fred})
aliases = self.build_configuration.registered_aliases()
self.assertEqual({}, aliases.target_macro_factories)
self.assertEqual({}, aliases.objects)
self.assertEqual({}, aliases.context_aware_object_factories)
self.assertEqual(dict(fred=Fred), aliases.target_types)
with self._create_mock_build_file('fred') as build_file:
parse_state = self.build_configuration.initialize_parse_state(build_file)
self.assertEqual(0, len(parse_state.objects))
self.assertEqual(1, len(parse_state.parse_globals))
target_call_proxy = parse_state.parse_globals['fred']
target_call_proxy(name='jake')
self.assertEqual(1, len(parse_state.objects))
target_proxy = parse_state.objects[0]
self.assertEqual('jake', target_proxy.addressed_name)
self.assertEqual(Fred, target_proxy.addressed_type)
def test_register_target_macro_facory(self):
class Fred(Target):
pass
class FredMacro(TargetMacro):
def __init__(self, parse_context):
self._parse_context = parse_context
def expand(self, *args, **kwargs):
return self._parse_context.create_object(Fred, name='frog', dependencies=[kwargs['name']])
class FredFactory(TargetMacro.Factory):
@property
def target_types(self):
return {Fred}
def macro(self, parse_context):
return FredMacro(parse_context)
factory = FredFactory()
self._register_aliases(targets={'fred': factory})
aliases = self.build_configuration.registered_aliases()
self.assertEqual({}, aliases.target_types)
self.assertEqual({}, aliases.objects)
self.assertEqual({}, aliases.context_aware_object_factories)
self.assertEqual(dict(fred=factory), aliases.target_macro_factories)
with self._create_mock_build_file('fred') as build_file:
parse_state = self.build_configuration.initialize_parse_state(build_file)
self.assertEqual(0, len(parse_state.objects))
self.assertEqual(1, len(parse_state.parse_globals))
target_call_proxy = parse_state.parse_globals['fred']
target_call_proxy(name='jake')
self.assertEqual(1, len(parse_state.objects))
target_proxy = parse_state.objects[0]
self.assertEqual('frog', target_proxy.addressed_name)
self.assertEqual(Fred, target_proxy.addressed_type)
self.assertEqual(['jake'], target_proxy.dependency_specs)
def test_register_exposed_object(self):
self._register_aliases(objects={'jane': 42})
aliases = self.build_configuration.registered_aliases()
self.assertEqual({}, aliases.target_types)
self.assertEqual({}, aliases.target_macro_factories)
self.assertEqual({}, aliases.context_aware_object_factories)
self.assertEqual(dict(jane=42), aliases.objects)
with self._create_mock_build_file('jane') as build_file:
parse_state = self.build_configuration.initialize_parse_state(build_file)
self.assertEqual(0, len(parse_state.objects))
self.assertEqual(1, len(parse_state.parse_globals))
self.assertEqual(42, parse_state.parse_globals['jane'])
def test_register_exposed_context_aware_function(self):
self.do_test_exposed_context_aware_function(lambda context: lambda: context.rel_path)
self.do_test_exposed_context_aware_function(lambda context=None: lambda: context.rel_path)
def george_method(self, parse_context):
#.........这里部分代码省略.........
示例3: setUp
# 需要导入模块: from pants.build_graph.build_configuration import BuildConfiguration [as 别名]
# 或者: from pants.build_graph.build_configuration.BuildConfiguration import register_aliases [as 别名]
def setUp(self):
super(BaseTestWithParser, self).setUp()
build_configuration = BuildConfiguration()
build_configuration.register_aliases(self.alias_groups)
self.build_file_parser = BuildFileParser(build_configuration, self.build_root)
示例4: BaseTest
# 需要导入模块: from pants.build_graph.build_configuration import BuildConfiguration [as 别名]
# 或者: from pants.build_graph.build_configuration.BuildConfiguration import register_aliases [as 别名]
#.........这里部分代码省略.........
:API: public
"""
super(BaseTest, self).setUp()
# Avoid resetting the Runtracker here, as that is specific to fork'd process cleanup.
clean_global_runtime_state(reset_subsystem=True)
self.real_build_root = BuildRoot().path
self.build_root = os.path.realpath(mkdtemp(suffix='_BUILD_ROOT'))
self.subprocess_dir = os.path.join(self.build_root, '.pids')
self.addCleanup(safe_rmtree, self.build_root)
self.pants_workdir = os.path.join(self.build_root, '.pants.d')
safe_mkdir(self.pants_workdir)
self.options = defaultdict(dict) # scope -> key-value mapping.
self.options[''] = {
'pants_workdir': self.pants_workdir,
'pants_supportdir': os.path.join(self.build_root, 'build-support'),
'pants_distdir': os.path.join(self.build_root, 'dist'),
'pants_configdir': os.path.join(self.build_root, 'config'),
'pants_subprocessdir': self.subprocess_dir,
'cache_key_gen_version': '0-test',
}
self.options['cache'] = {
'read_from': [],
'write_to': [],
}
BuildRoot().path = self.build_root
self.addCleanup(BuildRoot().reset)
self._build_configuration = BuildConfiguration()
self._build_configuration.register_aliases(self.alias_groups)
self.build_file_parser = BuildFileParser(self._build_configuration, self.build_root)
self.project_tree = FileSystemProjectTree(self.build_root)
self.reset_build_graph()
def buildroot_files(self, relpath=None):
"""Returns the set of all files under the test build root.
:API: public
:param string relpath: If supplied, only collect files from this subtree.
:returns: All file paths found.
:rtype: set
"""
def scan():
for root, dirs, files in os.walk(os.path.join(self.build_root, relpath or '')):
for f in files:
yield os.path.relpath(os.path.join(root, f), self.build_root)
return set(scan())
def reset_build_graph(self):
"""Start over with a fresh build graph with no targets in it."""
self.address_mapper = BuildFileAddressMapper(self.build_file_parser, self.project_tree,
build_ignore_patterns=self.build_ignore_patterns)
self.build_graph = MutableBuildGraph(address_mapper=self.address_mapper)
def set_options_for_scope(self, scope, **kwargs):
self.options[scope].update(kwargs)
def context(self, for_task_types=None, for_subsystems=None, options=None,
target_roots=None, console_outstream=None, workspace=None,
**kwargs):
"""
示例5: build_config
# 需要导入模块: from pants.build_graph.build_configuration import BuildConfiguration [as 别名]
# 或者: from pants.build_graph.build_configuration.BuildConfiguration import register_aliases [as 别名]
def build_config(cls):
build_config = BuildConfiguration()
build_config.register_aliases(cls.alias_groups())
return build_config