Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[ci skip-rust]

[ci skip-build-wheels]
  • Loading branch information
stuhood committed Aug 4, 2020
1 parent 3a62ed5 commit ec9d3be
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
12 changes: 5 additions & 7 deletions src/python/pants/backend/project_info/dependees.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from enum import Enum
from typing import Iterable, Set, cast

from pants.base.specs import AddressSpecs, DescendantAddresses
from pants.base.specs import Specs
from pants.engine.addresses import Address, Addresses
from pants.engine.collection import DeduplicatedCollection
from pants.engine.console import Console
Expand All @@ -27,16 +27,14 @@ class AddressToDependees:
@rule
async def map_addresses_to_dependees() -> AddressToDependees:
# Get every target in the project so that we can iterate over them to find their dependencies.
all_explicit_targets = await Get(Targets, AddressSpecs([DescendantAddresses("")]))
all_targets = await Get(Targets, Specs, Specs.matching_all())
dependencies_per_target = await MultiGet(
Get(Addresses, DependenciesRequest(tgt.get(Dependencies))) for tgt in all_explicit_targets
Get(Addresses, DependenciesRequest(tgt.get(Dependencies))) for tgt in all_targets
)

address_to_dependees = defaultdict(set)
for tgt, dependencies in zip(all_explicit_targets, dependencies_per_target):
for tgt, dependencies in zip(all_targets, dependencies_per_target):
for dependency in dependencies:
# TODO(#10354): teach dependees how to work with generated subtargets.
dependency = dependency.maybe_convert_to_base_target()
address_to_dependees[dependency].add(tgt.address)
return AddressToDependees(
FrozenDict(
Expand All @@ -55,7 +53,7 @@ class DependeesRequest:
def __init__(
self, addresses: Iterable[Address], *, transitive: bool, include_roots: bool
) -> None:
self.addresses = FrozenOrderedSet(addr.maybe_convert_to_base_target() for addr in addresses)
self.addresses = FrozenOrderedSet(addresses)
self.transitive = transitive
self.include_roots = include_roots

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from typing import Dict, Optional, Set

from pants.backend.python.target_types import PythonRequirementsField, PythonSources
from pants.base.specs import AddressSpecs, DescendantAddresses
from pants.base.specs import AddressSpecs, DescendantAddresses, Specs
from pants.core.util_rules.strip_source_roots import (
SourceRootStrippedSources,
StripSourcesFieldRequest,
)
from pants.engine.addresses import Address, Addresses
from pants.engine.addresses import Address
from pants.engine.rules import Get, MultiGet, collect_rules, rule
from pants.engine.target import Subtargets, Targets
from pants.engine.target import Targets
from pants.util.frozendict import FrozenDict


Expand Down Expand Up @@ -61,14 +61,7 @@ def address_for_module(self, module: str) -> Optional[Address]:

@rule
async def map_first_party_modules_to_addresses() -> FirstPartyModuleToAddressMapping:
all_base_addresses = await Get(Addresses, AddressSpecs([DescendantAddresses("")]))
all_subtarget_collections = await MultiGet(
Get(Subtargets, Address, a) for a in all_base_addresses
)
all_targets = {subtargets.base for subtargets in all_subtarget_collections}
all_targets.update(
st for subtargets in all_subtarget_collections for st in subtargets.subtargets.values()
)
all_targets = await Get(Targets, Specs, Specs.matching_all())
candidate_targets = tuple(tgt for tgt in all_targets if tgt.has_field(PythonSources))

stripped_sources_per_target = await MultiGet(
Expand Down
8 changes: 8 additions & 0 deletions src/python/pants/base/specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,14 @@ class Specs:
address_specs: AddressSpecs
filesystem_specs: FilesystemSpecs

@classmethod
def matching_all(cls) -> "Specs":
"""Returns a set of Specs that will match all Addresses in the workspace."""
return Specs(
address_specs=AddressSpecs([DescendantAddresses("")]),
filesystem_specs=FilesystemSpecs([FilesystemGlobSpec("**/*")]),
)

@property
def provided(self) -> bool:
"""Did the user provide specs?"""
Expand Down
16 changes: 5 additions & 11 deletions src/python/pants/engine/internals/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,19 +451,13 @@ async def resolve_addresses_with_origins(specs: Specs) -> AddressesWithOrigins:
)
# It's possible to resolve the same address both with filesystem specs and address specs. We
# dedupe, but must go through some ceremony for the equality check because the OriginSpec will
# differ. We must also consider that the filesystem spec may have resulted in a generated
# subtarget; if the user explicitly specified the original owning target, we should use the
# original target rather than its generated subtarget.
# differ.
address_spec_addresses = FrozenOrderedSet(awo.address for awo in from_address_specs)
return AddressesWithOrigins(
[
(
*from_address_specs,
*(
awo
for awo in from_filesystem_specs
if awo.address.maybe_convert_to_base_target() not in address_spec_addresses
),
]
*(awo for awo in from_filesystem_specs if awo.address not in address_spec_addresses),
)
)


Expand Down Expand Up @@ -896,7 +890,7 @@ async def find_valid_field_sets(
targets_to_valid_field_sets[tgt_with_origin] = valid_field_sets
if request.error_if_no_valid_targets and not targets_to_valid_field_sets:
raise NoValidTargetsException.create_from_field_sets(
targets_with_origins,
TargetsWithOrigins(targets_with_origins),
field_set_types=field_set_types,
goal_description=request.goal_description,
union_membership=union_membership,
Expand Down

0 comments on commit ec9d3be

Please sign in to comment.