robotpy / robotpy-commands-v2

Python implementation of the WPILib Command Framework (2020+)
Other
2 stars 14 forks source link

Port Commands to Pure Python #26

Closed TheTripleV closed 6 months ago

auscompgeek commented 11 months ago

Please create a separate PR with the tests.

TheTripleV commented 9 months ago

Added a run of the tests with wrapped commands to CI.

To make more tests pass, I put in some forwards compatibility changes at https://github.com/TheTripleV/robotpy-commands-v2/blob/mclaren/tests/util.py#L31. Pure commands still works with the old syntax is most cases.

breaking changes


CommandBase and Command were merged into a unified Command. SubsystemBase and Subsystem were merged into a unified Subsystem. This is breaking but is a 2024 change across cpp/java too.


Methods like Command.beforeStarting now take a Command, not a function. I like the whole command framework taking Commands. When I add in some coroutine support after this PR gets merged, I'll inevitably add function support in a ton of places.

CommandScheduler.schedule has been changed from

  1. (self: ..., command: Command) -> None
  2. (self: ..., commands: List[Command]) -> None

to (self: ..., *commands: Command) -> None

In fact, all of the CommandGroups now use *commands. I did make them silently accept lists of commands even though they don't advertise it.


SelectCommand's constructor has been changed from (selector, list[tuple[object, Command]]) to (dict[Hashable, Command], selector). Idk why Java and C++ both have different order arguments but I moved to Java. I'd rather have consistency with Java than C++.

lospugs commented 6 months ago

Ran my tests, things look good for me. From an existing example we had to teach students in 2023, it's only four-ish sets of changes. My workflow: 1- Checkout this repo 1- Create virtualenv 1- Run setup.py install (inside virtual env) 1- Verify sys.path is proper 1- Implement examples with both inlined and class definition files 1- Simulate code to test

Changes that are forced with this PR: 1- Change any reference from CommandBase to Command 1- Change any reference from SubsystemBase to Subsystem 1- Change any in-line method lambdas defined inside subsystem file from [self] as a list, to just self 1- Change button bindings in CommandXboxController from upper case button letters to lower case. (e.g. A() -> a() )

More verbose info in the CD thread: https://www.chiefdelphi.com/t/robotpy-2024-beta/443117/11?u=newtoncrosby

virtuald commented 6 months ago

A version of this has been merged to main and pushed to pypi as version 2024.0.0b3. There are a lot of missing pieces, tracking those at https://github.com/robotpy/robotpy-commands-v2/issues/28