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


Python products.UnionProducts类代码示例

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


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

示例1: UnionProductsTest

class UnionProductsTest(BaseTest):
  def setUp(self):
    super(UnionProductsTest, self).setUp()
    self.products = UnionProducts()

  def test_get_for_target(self):
    c = self.make_target('c')
    b = self.make_target('b', dependencies=[c])
    a = self.make_target('a', dependencies=[b, c])
    self.products.add_for_target(a, [1])
    self.products.add_for_target(b, [2])
    self.products.add_for_target(c, [3])

    self.assertEquals(self.products.get_for_target(a), OrderedSet([1, 2, 3]))
    self.assertEquals(self.products.get_for_target(b), OrderedSet([2, 3]))
    self.assertEquals(self.products.get_for_target(c), OrderedSet([3]))

  def test_empty_products(self):
    c = self.make_target('c')
    self.assertFalse(self.products.get_for_target(c))

  def test_non_empty_products(self):
    c = self.make_target('c')
    self.products.add_for_target(c, [3])
    self.assertTrue(self.products.get_for_target(c))
开发者ID:WamBamBoozle,项目名称:pants,代码行数:25,代码来源:test_union_products.py

示例2: test_single_classpath_element_no_excludes

  def test_single_classpath_element_no_excludes(self):
    a = self.make_target('a', JvmTarget)

    classpath_product = UnionProducts()
    path = os.path.join(self.build_root, 'jar/path')
    classpath_product.add_for_target(a, [('default', path)])
    classpath = ClasspathUtil.compute_classpath([a], classpath_product, [], ['default'])
    self.assertEqual([path], classpath)
开发者ID:MathewJennings,项目名称:pants,代码行数:8,代码来源:test_classpath_util.py

示例3: test_relies_on_product_to_validate_paths_outside_buildroot

  def test_relies_on_product_to_validate_paths_outside_buildroot(self):
    a = self.make_target('a', JvmTarget)

    classpath_product = UnionProducts()
    classpath_product.add_for_target(a, [('default', '/dev/null')])

    classpath = ClasspathUtil.compute_classpath([a], classpath_product, [], ['default'])

    self.assertEqual(['/dev/null'], classpath)
开发者ID:Gabriel439,项目名称:pants,代码行数:9,代码来源:test_classpath_util.py

示例4: test_excluded_classpath_element

  def test_excluded_classpath_element(self):
    a = self.make_target('a', JvmTarget, excludes=[Exclude('com.example', 'lib')])

    classpath_product = UnionProducts()
    example_jar_path = os.path.join(self.build_root, 'ivy/jars/com.example/lib/123.4.jar')
    classpath_product.add_for_target(a, [('default', example_jar_path)])

    classpath = ClasspathUtil.compute_classpath([a], classpath_product, [], ['default'])

    self.assertEqual([], classpath)
开发者ID:MathewJennings,项目名称:pants,代码行数:10,代码来源:test_classpath_util.py

示例5: test_parent_excludes_ignored_for_resolving_child_target

  def test_parent_excludes_ignored_for_resolving_child_target(self):
    b = self.make_target('b', JvmTarget)
    self.make_target('a', JvmTarget, dependencies=[b], excludes=[Exclude('com.example', 'lib')])

    classpath_product = UnionProducts()
    example_jar_path = os.path.join(self.build_root, 'ivy/jars/com.example/lib/123.4.jar')
    classpath_product.add_for_target(b, [('default', example_jar_path)])

    classpath = ClasspathUtil.compute_classpath([b], classpath_product, [], ['default'])

    self.assertEqual([example_jar_path], classpath)
开发者ID:MathewJennings,项目名称:pants,代码行数:11,代码来源:test_classpath_util.py

示例6: test_path_with_differing_conf_ignored

  def test_path_with_differing_conf_ignored(self):
    a = self.make_target('a', JvmTarget)

    classpath_product = UnionProducts()

    path = os.path.join(self.build_root, 'jar/path')
    classpath_product.add_for_target(a, [('default', path)])

    classpath = ClasspathUtil.compute_classpath([a], classpath_product, [], ['not-default'])

    self.assertEqual([], classpath)
开发者ID:Gabriel439,项目名称:pants,代码行数:11,代码来源:test_classpath_util.py

示例7: test_fails_on_paths_outside_buildroot

  def test_fails_on_paths_outside_buildroot(self):
    a = self.make_target('a', JvmTarget)

    classpath_product = UnionProducts()
    classpath_product.add_for_target(a, [('default', '/dev/null')])

    with self.assertRaises(TaskError) as cm:
      ClasspathUtil.compute_classpath([a], classpath_product, [], ['default'])

    self.assertEqual(
      str('Classpath entry /dev/null for target a:a is located outside the buildroot.'),
      str(cm.exception))
开发者ID:MathewJennings,项目名称:pants,代码行数:12,代码来源:test_classpath_util.py

示例8: test_exclude_leaves_other_jars_unaffected

  def test_exclude_leaves_other_jars_unaffected(self):
    b = self.make_target('b', JvmTarget, excludes=[Exclude('com.example', 'lib')])
    a = self.make_target('a', JvmTarget, dependencies=[b])

    classpath_product = UnionProducts()
    com_example_jar_path = os.path.join(self.build_root, 'ivy/jars/com.example/lib/123.4.jar')
    org_example_jar_path = os.path.join(self.build_root, 'ivy/jars/org.example/lib/123.4.jar')
    classpath_product.add_for_target(a, [('default', com_example_jar_path),
                                         ('default', org_example_jar_path)])

    classpath = ClasspathUtil.compute_classpath([a], classpath_product, [], ['default'])

    self.assertEqual([org_example_jar_path], classpath)
开发者ID:MathewJennings,项目名称:pants,代码行数:13,代码来源:test_classpath_util.py

示例9: test_extra_path_added

  def test_extra_path_added(self):
    a = self.make_target('a', JvmTarget)

    classpath_product = UnionProducts()

    path = os.path.join(self.build_root, 'jar/path')
    classpath_product.add_for_target(a, [('default', path)])

    extra_path = 'new-path'
    classpath = ClasspathUtil.compute_classpath([a], classpath_product,
                                                [('default', extra_path)], ['default'])

    self.assertEqual([path, extra_path], classpath)
开发者ID:Gabriel439,项目名称:pants,代码行数:13,代码来源:test_classpath_util.py

示例10: test_path_with_overlapped_conf_added

  def test_path_with_overlapped_conf_added(self):
    a = self.make_target('a', JvmTarget)

    classpath_product = UnionProducts()

    path = os.path.join(self.build_root, 'jar/path')
    classpath_product.add_for_target(a, [('default', path)])

    classpath = ClasspathUtil.compute_classpath([a],
                                                classpath_product,
                                                extra_classpath_tuples=[],
                                                confs=['not-default', 'default'])

    self.assertEqual([path], classpath)
开发者ID:benjyw,项目名称:pants,代码行数:14,代码来源:test_classpath_util.py

示例11: setUp

 def setUp(self):
   super(UnionProductsTest, self).setUp()
   self.products = UnionProducts()
开发者ID:kslundberg,项目名称:pants,代码行数:3,代码来源:test_union_products.py

示例12: UnionProductsTest

class UnionProductsTest(BaseTest):
  def setUp(self):
    super(UnionProductsTest, self).setUp()
    self.products = UnionProducts()

  def test_get_for_target(self):
    c = self.make_target('c')
    b = self.make_target('b', dependencies=[c])
    a = self.make_target('a', dependencies=[b, c])
    self.products.add_for_target(a, [1])
    self.products.add_for_target(b, [2])
    self.products.add_for_target(c, [3])

    self.assertEquals(self.products.get_for_target(a), OrderedSet([1, 2, 3]))
    self.assertEquals(self.products.get_for_target(b), OrderedSet([2, 3]))
    self.assertEquals(self.products.get_for_target(c), OrderedSet([3]))
    self.assertEquals(self.products.get_for_target(a, transitive=False), OrderedSet([1]))
    self.assertEquals(self.products.get_for_target(b, transitive=False), OrderedSet([2]))
    self.assertEquals(self.products.get_for_target(c, transitive=False), OrderedSet([3]))

  def test_copy(self):
    c = self.make_target('c')
    b = self.make_target('b', dependencies=[c])
    a = self.make_target('a', dependencies=[b, c])
    self.products.add_for_target(a, [1])
    self.products.add_for_target(b, [2])

    copied = self.products.copy()

    self.assertEquals(self.products.get_for_target(a), OrderedSet([1, 2]))
    self.assertEquals(self.products.get_for_target(b), OrderedSet([2]))
    self.assertEquals(copied.get_for_target(a), OrderedSet([1, 2]))
    self.assertEquals(copied.get_for_target(b), OrderedSet([2]))

    copied.add_for_target(c, [3])

    self.assertEquals(self.products.get_for_target(a), OrderedSet([1, 2]))
    self.assertEquals(self.products.get_for_target(b), OrderedSet([2]))
    self.assertEquals(self.products.get_for_target(c), OrderedSet())
    self.assertEquals(copied.get_for_target(a), OrderedSet([1, 2, 3]))
    self.assertEquals(copied.get_for_target(b), OrderedSet([2, 3]))
    self.assertEquals(copied.get_for_target(c), OrderedSet([3]))

  def test_remove_for_target(self):
    c = self.make_target('c')
    b = self.make_target('b', dependencies=[c])
    a = self.make_target('a', dependencies=[b, c])
    self.products.add_for_target(a, [1])
    self.products.add_for_target(b, [2])
    self.products.add_for_target(c, [3])

    self.products.remove_for_target(a, [1])

    self.assertEquals(self.products.get_for_target(a), OrderedSet([2, 3]))
    self.assertEquals(self.products.get_for_target(b), OrderedSet([2, 3]))
    self.assertEquals(self.products.get_for_target(c), OrderedSet([3]))

  def test_empty_products(self):
    c = self.make_target('c')
    self.assertFalse(self.products.get_for_target(c))

  def test_non_empty_products(self):
    c = self.make_target('c')
    self.products.add_for_target(c, [3])
    self.assertTrue(self.products.get_for_target(c))

  def test_target_for_product_existing_product(self):
    c = self.make_target('c')
    self.products.add_for_target(c, [3])

    found_target = self.products.target_for_product(3)

    self.assertEqual(c, found_target)

  def test_target_for_product_nonexistent_product(self):
    c = self.make_target('c')
    self.products.add_for_target(c, [3])

    found_target = self.products.target_for_product(1000)

    self.assertIsNone(found_target)
开发者ID:kslundberg,项目名称:pants,代码行数:81,代码来源:test_union_products.py

示例13: __init__

 def __init__(self):
   self._classpaths = UnionProducts()
   self._excludes = UnionProducts()
   self._buildroot = get_buildroot()
开发者ID:Gabriel439,项目名称:pants,代码行数:4,代码来源:classpath_products.py

示例14: ClasspathProducts

class ClasspathProducts(object):
  def __init__(self):
    self._classpaths = UnionProducts()
    self._excludes = UnionProducts()
    self._buildroot = get_buildroot()

  def add_for_targets(self, targets, classpath_elements):
    """Adds classpath path elements to the products of all the provided targets."""
    for target in targets:
      self.add_for_target(target, classpath_elements)

  def add_for_target(self, target, classpath_elements):
    """Adds classpath path elements to the products of the provided target."""
    self._add_elements_for_target(target, self._wrap_path_elements(classpath_elements))

  def add_jars_for_targets(self, targets, conf, resolved_jars):
    """Adds jar classpath elements to the products of the provided targets in a way that works with
    excludes.
    """
    classpath_entries = []
    for jar in resolved_jars:
      if not jar.pants_path:
        raise TaskError("Jar: {!s} has no specified path.".format(jar.coordinate))
      classpath_entries.append((conf, ArtifactClasspathEntry(jar.coordinate, jar.pants_path)))

    for target in targets:
      self._add_elements_for_target(target, classpath_entries)

  def add_excludes_for_targets(self, targets):
    """Add excludes from the provided targets. Does not look up transitive excludes."""
    for target in targets:
      self._add_excludes_for_target(target)

  def remove_for_target(self, target, classpath_elements):
    """Removes the given entries for the target"""
    self._classpaths.remove_for_target(target, self._wrap_path_elements(classpath_elements))

  def get_for_target(self, target, transitive=True):
    """Gets the transitive classpath products for the given target, in order, respecting target
       excludes."""
    return self.get_for_targets([target], transitive=transitive)

  def get_for_targets(self, targets, transitive=True):
    """Gets the transitive classpath products for the given targets, in order, respecting target
       excludes."""
    classpath_tuples = self._classpaths.get_for_targets(targets, transitive)
    filtered_classpath_tuples = self._filter_by_excludes(classpath_tuples, targets, transitive)
    return [(classpath_tuple[0], classpath_tuple[1].path) for classpath_tuple in filtered_classpath_tuples]

  def _filter_by_excludes(self, classpath_tuples, root_targets, transitive):
    excludes = self._excludes.get_for_targets(root_targets, transitive=transitive)
    return filter(_not_excluded_filter(excludes),
                  classpath_tuples)

  def _add_excludes_for_target(self, target):
    if target.is_exported:
      self._excludes.add_for_target(target, [Exclude(target.provides.org,
                                                     target.provides.name)])
    if isinstance(target, JvmTarget) and target.excludes:
      self._excludes.add_for_target(target, target.excludes)

  def _wrap_path_elements(self, classpath_elements):
    return [(element[0], ClasspathEntry(element[1])) for element in classpath_elements]

  def _add_elements_for_target(self, target, elements):
    self._validate_classpath_tuples(elements, target)
    self._classpaths.add_for_target(target, elements)

  def _validate_classpath_tuples(self, classpath, target):
    """Validates that all files are located within the working copy, to simplify relativization.

    :param classpath: The list of classpath tuples. Each tuple is a 2-tuple of ivy_conf and ClasspathEntry
    :param target: The target that the classpath tuple is being registered for
    :raises: `TaskError` when the path is outside the build root
    """
    for classpath_tuple in classpath:
      conf, classpath_entry = classpath_tuple
      path = classpath_entry.path
      if os.path.relpath(path, self._buildroot).startswith(os.pardir):
        raise TaskError(
          'Classpath entry {} for target {} is located outside the buildroot.'
          .format(path, target.address.spec))
开发者ID:Gabriel439,项目名称:pants,代码行数:82,代码来源:classpath_products.py

示例15: UnionProductsTest

class UnionProductsTest(TestBase):
  def setUp(self):
    super(UnionProductsTest, self).setUp()
    self.products = UnionProducts()

  def test_get_for_target(self):
    c = self.make_target('c')
    b = self.make_target('b', dependencies=[c])
    a = self.make_target('a', dependencies=[b, c])
    self.products.add_for_target(a, [1])
    self.products.add_for_target(b, [2])
    self.products.add_for_target(c, [3])

    self.assertEqual(self.products.get_for_targets(a.closure(bfs=True)), OrderedSet([1, 2, 3]))
    self.assertEqual(self.products.get_for_targets(b.closure(bfs=True)), OrderedSet([2, 3]))
    self.assertEqual(self.products.get_for_targets(c.closure(bfs=True)), OrderedSet([3]))
    self.assertEqual(self.products.get_for_target(a), OrderedSet([1]))
    self.assertEqual(self.products.get_for_target(b), OrderedSet([2]))
    self.assertEqual(self.products.get_for_target(c), OrderedSet([3]))

  def test_get_product_target_mappings_for_targets(self):
    b = self.make_target('b')
    a = self.make_target('a', dependencies=[b])
    self.products.add_for_target(a, [1, 3])
    self.products.add_for_target(b, [2, 3])

    self.assertEqual(self.products.get_for_targets(a.closure(bfs=True)), OrderedSet([1, 3, 2]))
    self.assertEqual(self.products.get_for_targets(b.closure(bfs=True)), OrderedSet([2, 3]))

    self.assertEqual(self.products.get_product_target_mappings_for_targets(a.closure(bfs=True)),
                      [(1, a), (3, a), (2, b), (3, b)])

  def test_copy(self):
    c = self.make_target('c')
    b = self.make_target('b', dependencies=[c])
    a = self.make_target('a', dependencies=[b, c])
    self.products.add_for_target(a, [1])
    self.products.add_for_target(b, [2])

    copied = self.products.copy()

    self.assertEqual(self.products.get_for_targets(a.closure(bfs=True)), OrderedSet([1, 2]))
    self.assertEqual(self.products.get_for_targets(b.closure(bfs=True)), OrderedSet([2]))
    self.assertEqual(copied.get_for_targets(a.closure(bfs=True)), OrderedSet([1, 2]))
    self.assertEqual(copied.get_for_targets(b.closure(bfs=True)), OrderedSet([2]))

    copied.add_for_target(c, [3])

    self.assertEqual(self.products.get_for_targets(a.closure(bfs=True)), OrderedSet([1, 2]))
    self.assertEqual(self.products.get_for_targets(b.closure(bfs=True)), OrderedSet([2]))
    self.assertEqual(self.products.get_for_targets(c.closure(bfs=True)), OrderedSet())
    self.assertEqual(copied.get_for_targets(a.closure(bfs=True)), OrderedSet([1, 2, 3]))
    self.assertEqual(copied.get_for_targets(b.closure(bfs=True)), OrderedSet([2, 3]))
    self.assertEqual(copied.get_for_targets(c.closure(bfs=True)), OrderedSet([3]))

  def test_remove_for_target(self):
    c = self.make_target('c')
    b = self.make_target('b', dependencies=[c])
    a = self.make_target('a', dependencies=[b, c])
    self.products.add_for_target(a, [1])
    self.products.add_for_target(b, [2])
    self.products.add_for_target(c, [3])

    self.products.remove_for_target(a, [1])

    self.assertEqual(self.products.get_for_targets(a.closure(bfs=True)), OrderedSet([2, 3]))
    self.assertEqual(self.products.get_for_targets(b.closure(bfs=True)), OrderedSet([2, 3]))
    self.assertEqual(self.products.get_for_targets(c.closure(bfs=True)), OrderedSet([3]))

  def test_empty_products(self):
    c = self.make_target('c')
    self.assertFalse(self.products.get_for_target(c))

  def test_non_empty_products(self):
    c = self.make_target('c')
    self.products.add_for_target(c, [3])
    self.assertTrue(self.products.get_for_target(c))

  def test_target_for_product_existing_product(self):
    c = self.make_target('c')
    self.products.add_for_target(c, [3])

    found_target = self.products.target_for_product(3)

    self.assertEqual(c, found_target)

  def test_target_for_product_nonexistent_product(self):
    c = self.make_target('c')
    self.products.add_for_target(c, [3])

    found_target = self.products.target_for_product(1000)

    self.assertIsNone(found_target)
开发者ID:cosmicexplorer,项目名称:pants,代码行数:93,代码来源:test_union_products.py


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