示例#1
0
 def test_single(self):
   subclasses_of_b = SubclassesOf(self.B)
   self.assertEqual((self.B,), subclasses_of_b.types)
   self.assertFalse(subclasses_of_b.satisfied_by(self.A()))
   self.assertTrue(subclasses_of_b.satisfied_by(self.B()))
   self.assertFalse(subclasses_of_b.satisfied_by(self.BPrime()))
   self.assertTrue(subclasses_of_b.satisfied_by(self.C()))
示例#2
0
 def test_multiple(self):
   subclasses_of_b_or_c = SubclassesOf(self.B, self.C)
   self.assertEqual((self.B, self.C), subclasses_of_b_or_c.types)
   self.assertTrue(subclasses_of_b_or_c.satisfied_by(self.B()))
   self.assertTrue(subclasses_of_b_or_c.satisfied_by(self.C()))
   self.assertFalse(subclasses_of_b_or_c.satisfied_by(self.BPrime()))
   self.assertFalse(subclasses_of_b_or_c.satisfied_by(self.A()))
示例#3
0
 def test_multiple(self):
     subclasses_of_b_or_c = SubclassesOf(self.B, self.C)
     self.assertEqual((self.B, self.C), subclasses_of_b_or_c.types)
     self.assertTrue(subclasses_of_b_or_c.satisfied_by(self.B()))
     self.assertTrue(subclasses_of_b_or_c.satisfied_by(self.C()))
     self.assertFalse(subclasses_of_b_or_c.satisfied_by(self.BPrime()))
     self.assertFalse(subclasses_of_b_or_c.satisfied_by(self.A()))
示例#4
0
  def __init__(self, native, build_root, ignore_patterns, rule_index, root_subject_types):
    self._native = native
    # TODO: The only (?) case where we use inheritance rather than exact type unions.
    has_products_constraint = SubclassesOf(HasProducts)

    # Create the ExternContext, and the native Scheduler.
    self._tasks = native.new_tasks()
    self._register_tasks(rule_index.tasks)
    self._register_intrinsics(rule_index.intrinsics)
    self._register_singletons(rule_index.singletons)
    self.root_subject_types = root_subject_types

    self._scheduler = native.new_scheduler(
        self._tasks,
        build_root,
        ignore_patterns,
        Snapshot,
        _Snapshots,
        FileContent,
        FilesContent,
        Path,
        Dir,
        File,
        Link,
        has_products_constraint,
        constraint_for(Address),
        constraint_for(Variants),
        constraint_for(PathGlobs),
        constraint_for(Snapshot),
        constraint_for(_Snapshots),
        constraint_for(FilesContent),
        constraint_for(Dir),
        constraint_for(File),
        constraint_for(Link),
      )
示例#5
0
    def __init__(self, goals, tasks, project_tree, native, graph_lock=None):
        """
    :param goals: A dict from a goal name to a product type. A goal is just an alias for a
           particular (possibly synthetic) product.
    :param tasks: A set of (output, input selection clause, task function) triples which
           is used to compute values in the product graph.
    :param project_tree: An instance of ProjectTree for the current build root.
    :param native: An instance of engine.subsystem.native.Native.
    :param graph_lock: A re-entrant lock to use for guarding access to the internal product Graph
                       instance. Defaults to creating a new threading.RLock().
    """
        self._products_by_goal = goals
        self._project_tree = project_tree
        self._native = native
        self._product_graph_lock = graph_lock or threading.RLock()
        self._run_count = 0

        # Create a handle for the ExternContext (which must be kept alive as long as this object), and
        # the native Scheduler.
        self._context = ExternContext()
        self._context_handle = native.new_handle(self._context)

        # TODO: The only (?) case where we use inheritance rather than exact type unions.
        has_products_constraint = TypeConstraint(
            self._to_id(SubclassesOf(HasProducts)))

        scheduler = native.lib.scheduler_create(
            self._context_handle, extern_key_for, extern_id_to_str,
            extern_val_to_str, extern_satisfied_by, extern_store_list,
            extern_project, extern_project_multi, self._to_key('name'),
            self._to_key('products'), self._to_key('default'),
            self._to_constraint(Address), has_products_constraint,
            self._to_constraint(Variants))
        self._scheduler = native.gc(scheduler, native.lib.scheduler_destroy)
        self._execution_request = None

        # Validate and register all provided and intrinsic tasks.
        select_product = lambda product: Select(product)
        # TODO: This bounding of input Subject types allows for closed-world validation, but is not
        # strictly necessary for execution. We might eventually be able to remove it by only executing
        # validation below the execution roots (and thus not considering paths that aren't in use).
        root_selector_fns = {
            Address: select_product,
            AscendantAddresses: select_product,
            DescendantAddresses: select_product,
            PathGlobs: select_product,
            SiblingAddresses: select_product,
            SingleAddress: select_product,
        }
        intrinsics = create_fs_intrinsics(
            project_tree) + create_snapshot_intrinsics(project_tree)
        singletons = create_snapshot_singletons(project_tree)
        node_builder = NodeBuilder.create(tasks, intrinsics, singletons)
        RulesetValidator(node_builder, goals, root_selector_fns).validate()
        self._register_tasks(node_builder.tasks)
        self._register_intrinsics(node_builder.intrinsics)
        self._register_singletons(node_builder.singletons)
示例#6
0
class Target(Struct, HasStructs):
  collection_field = 'configurations'

  def __init__(self, name=None, configurations=None, **kwargs):
    super(Target, self).__init__(name=name, **kwargs)
    self.configurations = configurations

  @addressable_list(SubclassesOf(Struct))
  def configurations(self):
    pass
示例#7
0
文件: util.py 项目: lorinad/pants
class Target(Struct, HasProducts):
    def __init__(self, name=None, configurations=None, **kwargs):
        super(Target, self).__init__(name=name, **kwargs)
        self.configurations = configurations

    @property
    def products(self):
        return self.configurations

    @addressable_list(SubclassesOf(Struct))
    def configurations(self):
        pass
示例#8
0
 def test_single(self):
     subclasses_of_b = SubclassesOf(self.B)
     self.assertEqual((self.B, ), subclasses_of_b.types)
     self.assertFalse(subclasses_of_b.satisfied_by(self.A()))
     self.assertTrue(subclasses_of_b.satisfied_by(self.B()))
     self.assertFalse(subclasses_of_b.satisfied_by(self.BPrime()))
     self.assertTrue(subclasses_of_b.satisfied_by(self.C()))
示例#9
0
文件: struct.py 项目: neven7/pants
class StructWithDeps(Struct):
    """A subclass of Struct with dependencies."""
    def __init__(self, dependencies=None, **kwargs):
        """
    :param list dependencies: The direct dependencies of this struct.
    """
        # TODO: enforce the type of variants using the Addressable framework.
        super(StructWithDeps, self).__init__(**kwargs)
        self.dependencies = dependencies

    @addressable_list(SubclassesOf(Struct))
    def dependencies(self):
        """The direct dependencies of this target.
示例#10
0
  def __init__(self,
               goals,
               tasks,
               project_tree,
               native,
               graph_lock=None):
    """
    :param goals: A dict from a goal name to a product type. A goal is just an alias for a
           particular (possibly synthetic) product.
    :param tasks: A set of (output, input selection clause, task function) triples which
           is used to compute values in the product graph.
    :param project_tree: An instance of ProjectTree for the current build root.
    :param native: An instance of engine.subsystem.native.Native.
    :param graph_lock: A re-entrant lock to use for guarding access to the internal product Graph
                       instance. Defaults to creating a new threading.RLock().
    """
    self._products_by_goal = goals
    self._project_tree = project_tree
    self._native = native
    self._product_graph_lock = graph_lock or threading.RLock()
    self._run_count = 0

    # TODO: The only (?) case where we use inheritance rather than exact type unions.
    has_products_constraint = SubclassesOf(HasProducts)

    # Create the ExternContext, and the native Scheduler.
    self._scheduler = native.new_scheduler(has_products_constraint,
                                           constraint_for(Address),
                                           constraint_for(Variants))
    self._execution_request = None

    # Validate and register all provided and intrinsic tasks.
    # TODO: This bounding of input Subject types allows for closed-world validation, but is not
    # strictly necessary for execution. We might eventually be able to remove it by only executing
    # validation below the execution roots (and thus not considering paths that aren't in use).
    select_product = lambda product: Select(product)
    root_selector_fns = {
      Address: select_product,
      AscendantAddresses: select_product,
      DescendantAddresses: select_product,
      PathGlobs: select_product,
      SiblingAddresses: select_product,
      SingleAddress: select_product,
    }
    intrinsics = create_fs_intrinsics(project_tree) + create_snapshot_intrinsics(project_tree)
    singletons = create_snapshot_singletons(project_tree)
    rule_index = RuleIndex.create(tasks, intrinsics, singletons)
    RulesetValidator(rule_index, goals, root_selector_fns).validate()
    self._register_tasks(rule_index.tasks)
    self._register_intrinsics(rule_index.intrinsics)
    self._register_singletons(rule_index.singletons)
示例#11
0
class Target(Struct, HasStructs):
    """A placeholder for the most-numerous Struct subclass.

  This particular implementation holds a collection of other Structs in a `configurations` field.
  """
    collection_field = 'configurations'

    def __init__(self, name=None, configurations=None, **kwargs):
        """
    :param string name: The name of this target which forms its address in its namespace.
    :param list configurations: The configurations that apply to this target in various contexts.
    """
        super(Target, self).__init__(name=name, **kwargs)

        self.configurations = configurations

    @addressable_list(SubclassesOf(Struct))
    def configurations(self):
        """The configurations that apply to this target in various contexts.
示例#12
0
    def __init__(self, native, build_root, work_dir, ignore_patterns,
                 rule_index):
        self._native = native
        # TODO: The only (?) case where we use inheritance rather than exact type unions.
        has_products_constraint = SubclassesOf(HasProducts)
        self._root_subject_types = sorted(rule_index.roots)

        # Create the ExternContext, and the native Scheduler.
        self._tasks = native.new_tasks()
        self._register_rules(rule_index)

        self._scheduler = native.new_scheduler(
            self._tasks,
            self._root_subject_types,
            build_root,
            work_dir,
            ignore_patterns,
            Snapshot,
            _Snapshots,
            FileContent,
            FilesContent,
            Path,
            Dir,
            File,
            Link,
            ExecuteProcessResult,
            has_products_constraint,
            constraint_for(Address),
            constraint_for(Variants),
            constraint_for(PathGlobs),
            constraint_for(Snapshot),
            constraint_for(_Snapshots),
            constraint_for(FilesContent),
            constraint_for(Dir),
            constraint_for(File),
            constraint_for(Link),
            constraint_for(ExecuteProcessRequest),
            constraint_for(ExecuteProcessResult),
            constraint_for(GeneratorType),
        )
示例#13
0
 def test_none(self):
     with self.assertRaises(ValueError):
         SubclassesOf()