Skip to content
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

Port Commands to Pure Python #26

Closed
wants to merge 27 commits into from
Closed

Conversation

TheTripleV
Copy link
Member

No description provided.

@auscompgeek
Copy link
Member

Please create a separate PR with the tests.

commands2/__init__.py Outdated Show resolved Hide resolved
commands2/__init__.py Outdated Show resolved Hide resolved
commands2/__init__.py Outdated Show resolved Hide resolved
commands2/__init__.py Show resolved Hide resolved
commands2/commandscheduler.py Show resolved Hide resolved
commands2/button/commandgenerichid.py Outdated Show resolved Hide resolved
commands2/button/trigger.py Outdated Show resolved Hide resolved
commands2/command.py Show resolved Hide resolved
commands2/command.py Show resolved Hide resolved
commands2/command.py Outdated Show resolved Hide resolved
"""
if CommandScheduler._instance is not None:
return
CommandScheduler._instance = self
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird that this is assigned here instead of __new__, but I see why.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I can only get rid of it if I force the constructor to crash.

commands2/commandscheduler.py Show resolved Hide resolved
commands2/parallelcommandgroup.py Outdated Show resolved Hide resolved
commands2/commandscheduler.py Outdated Show resolved Hide resolved
@TheTripleV
Copy link
Member Author

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++.

@auscompgeek auscompgeek linked an issue Aug 5, 2023 that may be closed by this pull request
@lospugs
Copy link
Contributor

lospugs commented Nov 1, 2023

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 virtuald force-pushed the mclaren branch 2 times, most recently from 1b46350 to c2c2280 Compare November 5, 2023 05:33
@virtuald
Copy link
Member

virtuald commented Nov 5, 2023

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 #28

@virtuald virtuald closed this Nov 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rewrite in pure python
4 participants