sagas/mpy: Use main module name instead of __main__.#2367
sagas/mpy: Use main module name instead of __main__.#2367laurensvalk merged 3 commits intomasterfrom
Conversation
This is separate from Python's __main__ mechanism, so we shouldn't be manually renaming things to __main__ here. This also makes file names show correctly on EV3. See pybricks/support#2364
|
Is there any version of the firmware that checks for the name |
|
Thanks. Hmm, because we do show the update warning, my brain was at this one:
Originally posted by @dlech in #2364 But that was about the intermediate versions, and we probably still do need the following:
Originally posted by @laurensvalk in #2364 But we don't have access to the currently active version in that module, so needs some more work. |
|
Should do the trick: const fwVersion = yield* select((s: RootState) => s.hub.deviceFirmwareVersion);If it is empty string (because not connected to a hub), then use the "new" way since we are just doing compile check and not downloading. |
|
Or if we want to be fancy, we could add a new state flag like |
Heh, I started that way but thought you'd call me out on that 😄
So that is indeed what I tried. I'm always a little puzzled doing this, as there seem to be so many placed to add a single boolean condition. |
I think it would be fine to do: const useLegacyMainModule = yield* select((s: RootState) => s.hub.useLegacyMainModule);In the mpy saga so that we don't have to add it as a parameter to the action. |
|
Done! |
src/mpy/sagas.ts
Outdated
| const mainPyPath = useLegacyMainModule | ||
| ? '__main__.py' | ||
| : metadata.path ?? '__main__.py'; |
There was a problem hiding this comment.
Is the change to the legacy behavior intentional?
Before, the behavior was always metadata.path ?? '__main__.py', but now the legacy behavior will be only '__main__.py'.
I would expect useLegacyMainModule to only affect mainPyName in order to preserve the old behavior.
Needed for backwards compatibility. Older firmware always look for __main__. See pybricks/support#2364
|
Thanks, this was a little rushed. Updated now. Perhaps separately, there's something off with the BLE/USB actions, e.g.: This one works because the usb saga dispatches a ble action so Maybe So currently, if you connect a Prime Hub with stable firmware and then an EV3 with newer firmware, the flags are bad. If you restart Pybricks Code, it only works because the various legacy flags default to false. |
|
Added a commit to simply also match against the USB action. It looks like we were already doing that for firmware revisions and just missed it for software revisions. |
We were already doing something similar for USB firmware revision, but this was missed for software revision.
Good catch. This is probably why we didn't notice before. All looks good to me now. |
This is separate from Python's
__main__mechanism, so we shouldn't be manually renaming things to__main__here.This also makes file names show correctly on EV3.
See pybricks/support#2364