Skip to content

Deprecate deadlineWith and add deadlineFor instead #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gittrack
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[git-source-track]
upstream_root = ../allwpilib/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command
upstream_branch = main
upstream_commit = 25ad6eafd5eeaf57ed25db2414a20838bf098399
upstream_commit = 0f8aa8aedff3bec7fca50dc43f803b1608d9a421
validation_root = commands2

29 changes: 29 additions & 0 deletions commands2/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,35 @@ def deadlineWith(self, *parallel: Command) -> ParallelDeadlineGroup:
command ends and interrupting all the others. Often more convenient/less-verbose than
constructing a new ParallelDeadlineGroup explicitly.

.. note:: This decorator works by adding this command to a composition.
The command the decorator was called on cannot be scheduled
independently or be added to a different composition (namely,
decorators), unless it is manually cleared from the list of composed
commands with :func:`commands2.CommandScheduler.removeComposedCommand`.
The command composition returned from this method can be further
decorated without issue.

:param parallel: the commands to run in parallel
:returns: the decorated command
"""
import warnings

warnings.warn(
"deadlineWith is deprecated use deadlineFor instead",
DeprecationWarning,
stacklevel=2,
)

from .paralleldeadlinegroup import ParallelDeadlineGroup

return ParallelDeadlineGroup(self, *parallel)

def deadlineFor(self, *parallel: Command) -> ParallelDeadlineGroup:
"""
Decorates this command with a set of commands to run parallel to it, ending when the calling
command ends and interrupting all the others. Often more convenient/less-verbose than
constructing a new ParallelDeadlineGroup explicitly.

.. note:: This decorator works by adding this command to a composition.
The command the decorator was called on cannot be scheduled
independently or be added to a different composition (namely,
Expand Down
18 changes: 18 additions & 0 deletions tests/test_command_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,24 @@ def test_deadlineWith(scheduler: commands2.CommandScheduler):
assert not group.isScheduled()


def test_deadlineFor(scheduler: commands2.CommandScheduler):
condition = OOBoolean(False)
condition.set(False)

dictator = commands2.WaitUntilCommand(condition)
endsBefore = commands2.InstantCommand()
endsAfter = commands2.WaitUntilCommand(lambda: False)

group = dictator.deadlineFor(endsBefore, endsAfter)

scheduler.schedule(group)
scheduler.run()
assert group.isScheduled()
condition.set(True)
scheduler.run()
assert not group.isScheduled()


def test_alongWith(scheduler: commands2.CommandScheduler):
condition = OOBoolean()
condition.set(False)
Expand Down
Loading