Skip to content

Commit

Permalink
Rename --changed-dependees to --changed-dependents (pantsbuild#17395)
Browse files Browse the repository at this point in the history
Deprecates the old name.
  • Loading branch information
benjyw authored Oct 29, 2022
1 parent 521ee5f commit 147df94
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 65 deletions.
2 changes: 1 addition & 1 deletion build-support/githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if git diff "${MERGE_BASE}" --name-only | grep '\.rs$' > /dev/null; then
fi

echo "* Typechecking"
./pants --changed-since="${MERGE_BASE}" --changed-dependees=transitive check
./pants --changed-since="${MERGE_BASE}" --changed-dependents=transitive check

echo "* Checking linters, formatters, and headers"
./pants --changed-since="${MERGE_BASE}" lint ||
Expand Down
6 changes: 3 additions & 3 deletions docs/markdown/Python/python-goals/python-check-goal.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,13 @@ If you're using a version of MyPy older than `0.700`, consider upgrading to unlo
Additionally consider not providing `python_version` in your config or args.


Tip: only run over changed files and their dependees
----------------------------------------------------
Tip: only run over changed files and their dependents
-----------------------------------------------------

When changing type hints code, you not only need to run over the changed files, but also any code that depends on the changed files:

```bash
$ ./pants --changed-since=HEAD --changed-dependees=transitive check
$ ./pants --changed-since=HEAD --changed-dependents=transitive check
```

See [Advanced target selection](doc:advanced-target-selection) for more information.
4 changes: 2 additions & 2 deletions docs/markdown/Using Pants/advanced-target-selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ To run against another branch, run:
./pants --changed-since=origin/main lint
```

By default, `--changed-since` will only run over files directly changed. Often, though, you will want to run over any [dependees](doc:project-introspection) of those changed files, meaning any targets that depend on the changed files. Use ` --changed-dependees=direct` or ` --changed-dependees=transitive` for this:
By default, `--changed-since` will only run over files directly changed. Often, though, you will want to run over any [dependents](doc:project-introspection) of those changed files, meaning any targets that depend on the changed files. Use ` --changed-dependents=direct` or ` --changed-dependents=transitive` for this:

```bash
❯ ./pants \
--changed-since=origin/main \
--changed-dependees=transitive \
--changed-dependents=transitive \
test
```

Expand Down
6 changes: 3 additions & 3 deletions docs/markdown/Using Pants/using-pants-in-ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ We recommend running these commands in CI:
lint
❯ ./pants \
--changed-since=origin/main \
--changed-dependees=transitive \
--changed-dependents=transitive \
check test
```
Because most linters do not care about a target's dependencies, we lint all changed files and targets, but not any dependees of those changes.
Because most linters do not care about a target's dependencies, we lint all changed files and targets, but not any dependents of those changes.
Meanwhile, tests should be rerun when any changes are made to the tests _or_ to dependencies of those tests, so we use the option `--changed-dependees=transitive`. `check` should also run on any transitive changes.
Meanwhile, tests should be rerun when any changes are made to the tests _or_ to dependencies of those tests, so we use the option `--changed-dependents=transitive`. `check` should also run on any transitive changes.
See [Advanced target selection](doc:advanced-target-selection) for more information on `--changed-since` and alternative techniques to select targets to run in CI.
Expand Down
2 changes: 1 addition & 1 deletion pants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ repo_id = "7775F8D5-FC58-4DBC-9302-D00AE4A1505F"


[cli.alias]
all-changed = "--changed-since=HEAD --changed-dependees=transitive"
all-changed = "--changed-since=HEAD --changed-dependents=transitive"
run-pyupgrade = "--backend-packages=pants.backend.experimental.python.lint.pyupgrade fmt"


Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/core/target_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ class TargetGeneratorSourcesHelperTarget(Target):
"""
A private helper target type used by some target generators.
This tracks their `source` / `sources` field so that `--changed-since --changed-dependees`
This tracks their `source` / `sources` field so that `--changed-since --changed-dependents`
works properly for generated targets.
"""
)
Expand Down Expand Up @@ -742,7 +742,7 @@ class LockfileTarget(Target):
"""
A target for lockfiles in order to include them in the dependency graph of other targets.
This tracks them so that `--changed-since --changed-dependees` works properly for targets
This tracks them so that `--changed-since --changed-dependents` works properly for targets
relying on a particular lockfile.
"""
)
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/engine/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
def SubsystemRule(subsystem: Type[Subsystem]) -> Rule:
"""Returns a TaskRule that constructs an instance of the subsystem."""
warn_or_error(
removal_version="2.17.0dev0",
removal_version="2.17.0.dev0",
entity=f"using `SubsystemRule({subsystem.__name__})`",
hint=f"Use `*{subsystem.__name__}.rules()` instead.",
)
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/init/specs_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def calculate_specs(
changed_files = tuple(changed_options.changed_files(maybe_git_worktree.git_worktree))
file_literal_specs = tuple(FileLiteralSpec(f) for f in changed_files)

changed_request = ChangedRequest(changed_files, changed_options.dependees)
changed_request = ChangedRequest(changed_files, changed_options.dependents)
(changed_addresses,) = session.product_request(
ChangedAddresses,
[Params(changed_request, options_bootstrapper, bootstrap_environment)],
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/option/alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class CliOptions(Subsystem):
[cli.alias]
green = "fmt lint check"
all-changed = "--changed-since=HEAD --changed-dependees=transitive"
all-changed = "--changed-since=HEAD --changed-dependents=transitive"
This would allow you to run `{bin_name()} green all-changed`, which is shorthand for
`{bin_name()} fmt lint check --changed-since=HEAD --changed-dependees=transitive`.
`{bin_name()} fmt lint check --changed-since=HEAD --changed-dependents=transitive`.
Notice: this option must be placed in a config file (e.g. `pants.toml` or `pantsrc`)
to have any effect.
Expand Down
43 changes: 29 additions & 14 deletions src/python/pants/vcs/changed.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pants.backend.project_info import dependents
from pants.backend.project_info.dependents import Dependents, DependentsRequest
from pants.base.build_environment import get_buildroot
from pants.base.deprecated import resolve_conflicting_options
from pants.engine.addresses import Address, Addresses
from pants.engine.collection import Collection
from pants.engine.internals.graph import Owners, OwnersRequest
Expand All @@ -25,7 +26,7 @@
from pants.vcs.git import GitWorktree


class DependeesOption(Enum):
class DependentsOption(Enum):
NONE = "none"
DIRECT = "direct"
TRANSITIVE = "transitive"
Expand All @@ -34,7 +35,7 @@ class DependeesOption(Enum):
@dataclass(frozen=True)
class ChangedRequest:
sources: tuple[str, ...]
dependees: DependeesOption
dependents: DependentsOption


class ChangedAddresses(Collection[Address]):
Expand All @@ -45,20 +46,20 @@ class ChangedAddresses(Collection[Address]):
async def find_changed_owners(
request: ChangedRequest, specs_filter: SpecsFilter
) -> ChangedAddresses:
no_dependees = request.dependees == DependeesOption.NONE
no_dependents = request.dependents == DependentsOption.NONE
owners = await Get(
Owners,
OwnersRequest(
request.sources,
# If `--changed-dependees` is used, we cannot eagerly filter out root targets. We
# need to first find their dependees, and only then should we filter. See
# If `--changed-dependents` is used, we cannot eagerly filter out root targets. We
# need to first find their dependents, and only then should we filter. See
# https://github.com/pantsbuild/pants/issues/15544
filter_by_global_options=no_dependees,
filter_by_global_options=no_dependents,
# Changing a BUILD file might impact the targets it defines.
match_if_owning_build_file_included_in_sources=True,
),
)
if no_dependees:
if no_dependents:
return ChangedAddresses(owners)

# See https://github.com/pantsbuild/pants/issues/15313. We filter out target generators because
Expand All @@ -71,15 +72,15 @@ async def find_changed_owners(
owner_target_generators = FrozenOrderedSet(
addr.maybe_convert_to_target_generator() for addr in owners if addr.is_generated_target
)
dependees = await Get(
dependents = await Get(
Dependents,
DependentsRequest(
owners,
transitive=request.dependees == DependeesOption.TRANSITIVE,
transitive=request.dependents == DependentsOption.TRANSITIVE,
include_roots=False,
),
)
result = FrozenOrderedSet(owners) | (dependees - owner_target_generators)
result = FrozenOrderedSet(owners) | (dependents - owner_target_generators)
if specs_filter.is_specified:
# Finally, we must now filter out the result to only include what matches our tags, as the
# last step of https://github.com/pantsbuild/pants/issues/15544.
Expand All @@ -104,11 +105,19 @@ class ChangedOptions:

since: str | None
diffspec: str | None
dependees: DependeesOption
dependents: DependentsOption

@classmethod
def from_options(cls, options: OptionValueContainer) -> ChangedOptions:
return cls(options.since, options.diffspec, options.dependees)
dependents = resolve_conflicting_options(
old_option="dependees",
new_option="dependents",
old_scope=Changed.options_scope,
new_scope=Changed.options_scope,
old_container=options,
new_container=options,
)
return cls(options.since, options.diffspec, dependents)

@property
def provided(self) -> bool:
Expand Down Expand Up @@ -148,9 +157,15 @@ class Changed(Subsystem):
default=None,
help="Calculate changes contained within a given Git spec (commit range/SHA/ref).",
)
dependents = EnumOption(
default=DependentsOption.NONE,
help="Include direct or transitive dependents of changed targets.",
)
dependees = EnumOption(
default=DependeesOption.NONE,
help="Include direct or transitive dependees of changed targets.",
default=DependentsOption.NONE,
help="Include direct or transitive dependents of changed targets.",
removal_version="2.23.0.dev0",
removal_hint="Use --dependents instead",
)


Expand Down
Loading

0 comments on commit 147df94

Please sign in to comment.