<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> import logging <EOL> from pants . build_graph . address_lookup_error import AddressLookupError <EOL> from pants . source . payload_fields import DeferredSourcesField <EOL> from pants . task . task import Task <EOL> logger = logging . getLogger ( __name__ ) <EOL> class DeferredSourcesMapper ( Task ) : <EOL> """<STR_LIT>""" <EOL> class SourcesTargetLookupError ( AddressLookupError ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class NoUnpackedSourcesError ( AddressLookupError ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> @ classmethod <EOL> def product_types ( cls ) : <EOL> """<STR_LIT>""" <EOL> return [ '<STR_LIT>' ] <EOL> @ classmethod <EOL> def prepare ( cls , options , round_manager ) : <EOL> round_manager . require_data ( '<STR_LIT>' ) <EOL> def execute ( self ) : <EOL> deferred_sources_fields = [ ] <EOL> def find_deferred_sources_fields ( target ) : <EOL> for name , payload_field in target . payload . fields : <EOL> if isinstance ( payload_field , DeferredSourcesField ) : <EOL> deferred_sources_fields . append ( ( target , name , payload_field ) ) <EOL> addresses = [ target . address for target in self . context . targets ( ) ] <EOL> self . context . build_graph . walk_transitive_dependency_graph ( addresses , <EOL> find_deferred_sources_fields ) <EOL> unpacked_sources = self . context . products . get_data ( '<STR_LIT>' ) <EOL> for ( target , name , payload_field ) in deferred_sources_fields : <EOL> sources_target = self . context . build_graph . get_target ( payload_field . address ) <EOL> if not sources_target : <EOL> raise self . SourcesTargetLookupError ( <EOL> "<STR_LIT>" <EOL> . format ( sources_spec = payload_field . address . spec , target = target . address . spec , name = name ) ) <EOL> if not sources_target in unpacked_sources : <EOL> raise self . NoUnpackedSourcesError ( <EOL> "<STR_LIT>" <EOL> . format ( spec = sources_target . address . spec , target = target . address . spec , name = name ) ) <EOL> sources , rel_unpack_dir = unpacked_sources [ sources_target ] <EOL> self . context . source_roots . add_source_root ( rel_unpack_dir ) <EOL> payload_field . populate ( sources , rel_unpack_dir ) </s>
