Skip to content

Commit

Permalink
Address code review feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjyw committed Oct 7, 2019
1 parent f27519c commit 4fdfeaa
Showing 1 changed file with 7 additions and 38 deletions.
45 changes: 7 additions & 38 deletions src/python/pants/engine/build_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,41 +186,9 @@ def _hydrate(item_type, spec_path, **kwargs):
return item


@dataclass(frozen=True)
class AddressMapperAndSpecs:
# TODO: We only need this class because Get() requires a single Param.
address_mapper: AddressMapper
specs: Specs


@rule
def bind_addressmapper_and_specs(
address_mapper: AddressMapper, specs: Specs
) -> AddressMapperAndSpecs:
return AddressMapperAndSpecs(address_mapper, specs)


@rule
def addresses_from_address_families(
address_mapper: AddressMapper, specs: Specs
) -> BuildFileAddresses:
"""Given an AddressMapper and list of Specs, return matching BuildFileAddresses.
:raises: :class:`ResolveError` if:
- there were no matching AddressFamilies, or
- the Spec matches no addresses for SingleAddresses.
:raises: :class:`AddressLookupError` if no targets are matched for non-SingleAddress specs.
"""
provenanced_build_file_addresses = yield Get(
ProvenancedBuildFileAddresses,
AddressMapperAndSpecs, AddressMapperAndSpecs(address_mapper, specs))
yield BuildFileAddresses(
tuple(pbfa.build_file_address for pbfa in provenanced_build_file_addresses))


@rule
def provenanced_addresses_from_address_families(
address_mapper_and_specs: AddressMapperAndSpecs
address_mapper: AddressMapper, specs: Specs
) -> ProvenancedBuildFileAddresses:
"""Given an AddressMapper and list of Specs, return matching ProvenancedBuildFileAddresses.
Expand All @@ -229,9 +197,6 @@ def provenanced_addresses_from_address_families(
- the Spec matches no addresses for SingleAddresses.
:raises: :class:`AddressLookupError` if no targets are matched for non-SingleAddress specs.
"""
address_mapper = address_mapper_and_specs.address_mapper
specs = address_mapper_and_specs.specs

# Capture a Snapshot covering all paths for these Specs, then group by directory.
snapshot = yield Get(Snapshot, PathGlobs, _spec_to_globs(address_mapper, specs))
dirnames = {dirname(f) for f in snapshot.files}
Expand Down Expand Up @@ -272,6 +237,11 @@ def provenanced_addresses_from_address_families(
))


@rule
def remove_provenance(pbfas: ProvenancedBuildFileAddresses) -> BuildFileAddresses:
yield BuildFileAddresses(tuple(pbfa.build_file_address for pbfa in pbfas))


@dataclass(frozen=True)
class AddressProvenanceMap:
bfaddr_to_spec: Dict[BuildFileAddress, Spec]
Expand Down Expand Up @@ -313,10 +283,9 @@ def address_mapper_singleton() -> AddressMapper:
parse_address_family,
# Spec handling: locate directories that contain build files, and request
# AddressFamilies for each of them.
addresses_from_address_families,
provenanced_addresses_from_address_families,
remove_provenance,
address_provenance_map,
bind_addressmapper_and_specs,
# Root rules representing parameters that might be provided via root subjects.
RootRule(Address),
RootRule(BuildFileAddress),
Expand Down

0 comments on commit 4fdfeaa

Please sign in to comment.