Skip to content

Commit

Permalink
[engine] Move subselectors to selector properties
Browse files Browse the repository at this point in the history
Select/Dependency/ProjectionNodes cause sub-selectors to be generated in order to select different products. This moves those selectors onto the selectors instead of having the nodes construct them directly.

Working on the new validation / graph creation, I find myself needing those sub-selectors in a few other places, so I wanted to give them consistent names.

Testing Done:
Ran engine tests locally. CI away in PR.

Bugs closed: 3867

Reviewed at https://rbcommons.com/s/twitter/r/4235/

closes pantsbuild#3867
  • Loading branch information
baroquebobcat committed Sep 23, 2016
1 parent 67c33a1 commit 1d09690
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
18 changes: 13 additions & 5 deletions src/python/pants/engine/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ class SelectNode(datatype('SelectNode', ['subject', 'variants', 'selector']), No
is_cacheable = False
is_inlineable = True

_variant_selector = Select(Variants)

@property
def variant_key(self):
if isinstance(self.selector, SelectVariant):
Expand Down Expand Up @@ -248,7 +250,7 @@ def step(self, step_context):
# them to task nodes.
variants = self.variants
if type(self.subject) is Address and self.product is not Variants:
variants_node = step_context.select_node(Select(Variants), self.subject, self.variants)
variants_node = step_context.select_node(self._variant_selector, self.subject, self.variants)
dep_state = step_context.get(variants_node)
if type(dep_state) is Waiting:
return dep_state
Expand Down Expand Up @@ -342,11 +344,13 @@ def _dependency_nodes(self, step_context, dep_product):
# If a subject has literal variants for particular dependencies, they win over all else.
dependency, literal_variants = parse_variants(dependency)
variants = Variants.merge(variants, literal_variants)
yield step_context.select_node(Select(self.product), subject=dependency, variants=variants)
yield step_context.select_node(self.selector.projected_product_selector, subject=dependency, variants=variants)

def step(self, step_context):
# Request the product we need in order to request dependencies.
dep_product_node = step_context.select_node(Select(self.dep_product), self.subject, self.variants)
dep_product_node = step_context.select_node(self.selector.dep_product_selector,
self.subject,
self.variants)
dep_product_state = step_context.get(dep_product_node)
if type(dep_product_state) in (Throw, Waiting):
return dep_product_state
Expand Down Expand Up @@ -406,7 +410,9 @@ def input_product(self):

def step(self, step_context):
# Request the product we need to compute the subject.
input_node = step_context.select_node(Select(self.input_product), self.subject, self.variants)
input_node = step_context.select_node(self.selector.input_product_selector,
self.subject,
self.variants)

input_state = step_context.get(input_node)
if type(input_state) in (Throw, Waiting):
Expand All @@ -432,7 +438,9 @@ def step(self, step_context):
self.projected_subject, e)))

# When the output node is available, return its result.
output_node = step_context.select_node(Select(self.product), projected_subject, self.variants)
output_node = step_context.select_node(self.selector.projected_product_selector,
projected_subject,
self.variants)
output_state = step_context.get(output_node)
if type(output_state) in (Return, Throw, Waiting):
return output_state
Expand Down
22 changes: 18 additions & 4 deletions src/python/pants/engine/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ class SelectVariant(datatype('Variant', ['product', 'variant_key']), Selector):
def __new__(cls, product, variant_key):
if not isinstance(variant_key, six.string_types):
raise ValueError('Expected variant_key to be a string, but was {!r}'.format(variant_key))
obj = super(SelectVariant, cls).__new__(cls, product, variant_key)
return obj
return super(SelectVariant, cls).__new__(cls, product, variant_key)

def __repr__(self):
return '{}({}, {})'.format(type(self).__name__,
Expand All @@ -98,8 +97,15 @@ class SelectDependencies(datatype('Dependencies',
optional = False

def __new__(cls, product, dep_product, field=None, field_types=tuple()):
obj = super(SelectDependencies, cls).__new__(cls, product, dep_product, field, field_types)
return obj
return super(SelectDependencies, cls).__new__(cls, product, dep_product, field, field_types)

@property
def dep_product_selector(self):
return Select(self.dep_product)

@property
def projected_product_selector(self):
return Select(self.product)

def __repr__(self):
if self.field_types:
Expand All @@ -124,6 +130,14 @@ class SelectProjection(datatype('Projection', ['product', 'projected_subject', '
"""
optional = False

@property
def input_product_selector(self):
return Select(self.input_product)

@property
def projected_product_selector(self):
return Select(self.product)

def __repr__(self):
return '{}({}, {}, {}, {})'.format(type(self).__name__,
type_or_constraint_repr(self.product),
Expand Down

0 comments on commit 1d09690

Please sign in to comment.