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


Python BuildGraph.targets方法代码示例

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


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

示例1: test_file_have_coding_utf8

# 需要导入模块: from pants.base.build_graph import BuildGraph [as 别名]
# 或者: from pants.base.build_graph.BuildGraph import targets [as 别名]
  def test_file_have_coding_utf8(self):
    """
    Look through all .py files and ensure they start with the line '# coding=utf8'
    """

    build_configuration = load_build_configuration_from_source()
    build_file_parser = BuildFileParser(root_dir=get_buildroot(),
                                        build_configuration=build_configuration)
    address_mapper = BuildFileAddressMapper(build_file_parser)
    build_graph = BuildGraph(address_mapper=address_mapper)

    for address in address_mapper.scan_addresses(get_buildroot()):
      build_graph.inject_address_closure(address)

    def has_hand_coded_python_files(tgt):
      return (not tgt.is_synthetic) and tgt.is_original and tgt.has_sources('.py')

    nonconforming_files = []

    for target in build_graph.targets(has_hand_coded_python_files):
      for src in target.sources_relative_to_buildroot():
        with open(os.path.join(get_buildroot(), src), 'r') as python_file:
          coding_line = python_file.readline()
          if '' == coding_line and os.path.basename(src) == '__init__.py':
            continue
          if coding_line[0:2] == '#!':
            # Executable file:  look for the coding on the second line.
            coding_line = python_file.readline()
          if not coding_line.rstrip() == '# coding=utf-8':
            nonconforming_files.append(src)

    if len(nonconforming_files) > 0:
      self.fail('Expected these files to contain first line "# coding=utf8": '
                + str(nonconforming_files))
开发者ID:jmdcal,项目名称:pants,代码行数:36,代码来源:test_utf8_header.py


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