Skip to content

sagas/mpy: Use main module name instead of __main__.#2367

Open
laurensvalk wants to merge 2 commits intomasterfrom
__main__
Open

sagas/mpy: Use main module name instead of __main__.#2367
laurensvalk wants to merge 2 commits intomasterfrom
__main__

Conversation

@laurensvalk
Copy link
Member

@laurensvalk laurensvalk commented Mar 17, 2026

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

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
@dlech
Copy link
Member

dlech commented Mar 17, 2026

Is there any version of the firmware that checks for the name __main__.mpy? Or do all versions of the firmware just use the first file as the entry point?

@laurensvalk
Copy link
Member Author

Thanks. Hmm, because we do show the update warning, my brain was at this one:

We can work around this by making a file literally named __main__.py if we ever need to do a git bisect and run a program on the hub.

Originally posted by @dlech in #2364

But that was about the intermediate versions, and we probably still do need the following:

@dlech indicated we can just have Pybricks Code check the protocol version to use __main__ for older firmware. I'm all for it 👍

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.

@dlech
Copy link
Member

dlech commented Mar 17, 2026

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.

@dlech
Copy link
Member

dlech commented Mar 17, 2026

Or if we want to be fancy, we could add a new state flag like useLegacyStartUserProgram that is useLegacyDunderMain.

@laurensvalk
Copy link
Member Author

Should do the trick:

Heh, I started that way but thought you'd call me out on that 😄

Or if we want to be fancy, we could add a new state flag like useLegacyStartUserProgram that is useLegacyDunderMain.

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.

@dlech
Copy link
Member

dlech commented Mar 17, 2026

as there seem to be so many places 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.

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.

2 participants