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


Python build_file_manipulator.BuildFileManipulator类代码示例

本文整理汇总了Python中pants.contrib.buildgen.build_file_manipulator.BuildFileManipulator的典型用法代码示例。如果您正苦于以下问题:Python BuildFileManipulator类的具体用法?Python BuildFileManipulator怎么用?Python BuildFileManipulator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_forced_target_rules

  def test_forced_target_rules(self):
    expected_target_str = dedent(
      """\
      target_type(
        # This comment should be okay
        name = 'no_bg_no_cry',  # Side comments here will stay
        # This comment should be okay
        dependencies = [
          # only_above
          ':only_above',
          ':only_side',  # only_side
          # nbgbc_above1
          # nbgnc_above2
          'really/need/this:dep',  # nobgnc_side
        ],
        # This comment is also fine
        thing = object()
        # And finally this comment survives
      )"""
    )

    build_file = self.add_to_build_file('BUILD', self.complicated_dep_comments)

    complicated_bfm = BuildFileManipulator.load(build_file, 'no_bg_no_cry', set(['target_type']))
    complicated_bfm.clear_unforced_dependencies()
    target_str = '\n'.join(complicated_bfm.target_lines())
    self.assertEqual(target_str, expected_target_str)
开发者ID:tsdeng,项目名称:pants,代码行数:27,代码来源:test_build_file_manipulator.py

示例2: test_target_insertion_middle

  def test_target_insertion_middle(self):
    expected_build_string = dedent(
      """\
      # This comment should stay
      target_type(
        name = 'target_top',
        dependencies = [
          ':dep_a',
        ]
      )



      target_type(
        name = 'target_middle',
        dependencies = [
          ':dep_b',
          ':new_dep',
        ],
      )
      # This comment should be okay
      target_type(
        name = 'target_bottom',
      )
      # Also this one though it's weird"""
    )

    build_file = self.add_to_build_file('BUILD', self.multi_target_build_string)

    multi_targ_bfm = BuildFileManipulator.load(build_file, 'target_middle', {'target_type'})
    multi_targ_bfm.add_dependency(Address.parse(':new_dep'))
    build_file_str = '\n'.join(multi_targ_bfm.build_file_lines())
    self.assertEqual(build_file_str, expected_build_string)
开发者ID:tsdeng,项目名称:pants,代码行数:33,代码来源:test_build_file_manipulator.py

示例3: test_simple_targets

  def test_simple_targets(self):
    simple_targets = dedent(
      """
      target_type(
        name = 'no_deps',
      )

      target_type(
        name = 'empty_deps',
        dependencies = [
        ]
      )

      target_type(
        name = 'empty_deps_inline',
        dependencies = []
      )
      """
    )

    build_file = self.add_to_build_file('BUILD', simple_targets)

    for no_deps_name in ['no_deps', 'empty_deps', 'empty_deps_inline']:
      no_deps = BuildFileManipulator.load(build_file, no_deps_name, {'target_type'})
      self.assertEqual(tuple(no_deps.dependency_lines()), tuple())
      no_deps.add_dependency(Address.parse(':fake_dep'))
      self.assertEqual(tuple(no_deps.dependency_lines()),
                       tuple(['  dependencies = [',
                              "    ':fake_dep',",
                              '  ],']))
      no_deps.add_dependency(Address.parse(':b_fake_dep'))
      no_deps.add_dependency(Address.parse(':a_fake_dep'))
      self.assertEqual(tuple(no_deps.dependency_lines()),
                       tuple(['  dependencies = [',
                              "    ':a_fake_dep',",
                              "    ':b_fake_dep',",
                              "    ':fake_dep',",
                              '  ],']))
      self.assertEqual(tuple(no_deps.target_lines()),
                       tuple(['target_type(',
                              "  name = '{0}',".format(no_deps_name),
                              '  dependencies = [',
                              "    ':a_fake_dep',",
                              "    ':b_fake_dep',",
                              "    ':fake_dep',",
                              '  ],',
                              ')']))
开发者ID:tsdeng,项目名称:pants,代码行数:47,代码来源:test_build_file_manipulator.py

示例4: test_target_write

  def test_target_write(self):
    expected_build_string = dedent(
      """\
      # This comment should stay
      target_type(
        name = 'target_top',
        dependencies = [
          ':dep_a',
        ]
      )



      target_type(
        name = 'target_middle',
        dependencies = [
          ':dep_b',
          ':new_dep',
        ],
      )
      # This comment should be okay
      target_type(
        name = 'target_bottom',
      )
      # Also this one though it's weird
      """
    )

    build_file = self.add_to_build_file('BUILD', self.multi_target_build_string + '\n')

    multi_targ_bfm = BuildFileManipulator.load(build_file, 'target_middle', {'target_type'})
    multi_targ_bfm.add_dependency(Address.parse(':new_dep'))
    multi_targ_bfm.write(dry_run=False)

    with open(build_file.full_path, 'r') as bf:
      self.assertEqual(bf.read(), expected_build_string)
开发者ID:tsdeng,项目名称:pants,代码行数:36,代码来源:test_build_file_manipulator.py

示例5: test_malformed_targets

  def test_malformed_targets(self):
    bad_targets = dedent(
      """
      target_type(name='name_on_line')

      target_type(
        name=
        'dangling_kwarg_value'
      )

      # TODO(pl):  Split this out.  Right now it fails
      # the test for all of the targets and masks other
      # expected failures
      # target_type(
      #   name=str('non_str_literal')
      # )

      target_type(
        name='end_paren_not_on_own_line')

      target_type(
        object(),
        name='has_non_kwarg'
      )

      target_type(
        name='non_list_deps',
        dependencies=object(),
      )

      target_type(
        name='deps_not_on_own_lines1',
        dependencies=['some_dep'],
      )

      target_type(
        name='deps_not_on_own_lines2',
        dependencies=[
          'some_dep', 'some_other_dep'],
      )

      target_type(
        name = 'sentinel',
      )
      """
    )

    build_file = self.add_to_build_file('BUILD', bad_targets)

    bad_target_names = [
      'name_on_line',
      'dangling_kwarg_value',
      # TODO(pl): See TODO above
      # 'non_str_literal',
      'end_paren_not_on_own_line',
      'name_not_in_build_file',
      'has_non_kwarg',
      'non_list_deps',
    ]
    # Make sure this exception isn't just being thrown no matter what.
    # TODO(pl): These exception types should be more granular.
    BuildFileManipulator.load(build_file, 'sentinel', set(['target_type']))
    for bad_target in bad_target_names:
      with self.assertRaises(BuildTargetParseError):
        BuildFileManipulator.load(build_file, bad_target, set(['target_type']))
开发者ID:tsdeng,项目名称:pants,代码行数:65,代码来源:test_build_file_manipulator.py


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