Skip to content

Remove main file if empty during hex creation #1223

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

microbit-robert
Copy link
Collaborator

This creates a "clean" MicroPython hex. When the REPL is launched it already includes "from microbit import *".

This creates a "clean" MicroPython hex. When the REPL is launched
it already includes "from microbit import *".
Copy link

Preview build will be at
https://review-python-editor-v3.microbit.org/empty-main-file/

// Get the project stats after flashing as this will remove the main file if empty.
this.logging.event({
type: "flash",
detail: await this.projectStats(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Needs moving, otherwise the first save will include an empty main.py (which is then removed), and subsequent saves will not (unless code is added by the user).

@microbit-robert microbit-robert requested a review from a team June 26, 2025 09:42
@microbit-matt-hillsdon
Copy link
Collaborator

Please can we double check that we don't read main.py from the fs directly anywhere else?

@microbit-robert
Copy link
Collaborator Author

microbit-robert commented Jun 26, 2025

Please can we double check that we don't read main.py from the fs directly anywhere else?

We read it using FileSystem read, but not using MicropythonFsHex read/readBytes. So this looks safe to me.

Hmm did just create an error reloading a hex file though. Moving back to draft to investigate.

Update: We can't load a hex file that doesn't have a main.py. The same is true of a blank hex you can create from the V2 editor. I think we should fix as we're adding the ability to create such hex files in this PR.

@microbit-robert microbit-robert marked this pull request as draft June 26, 2025 12:37
@microbit-robert
Copy link
Collaborator Author

microbit-robert commented Jun 26, 2025

The V2 editor also fails to load hex files without python code:
Screenshot 2025-06-26 at 14 07 51

Error occurs during call to importFilesFromHex in importFilesFromUniversalHex.

@microbit-robert
Copy link
Collaborator Author

microbit-robert commented Jun 26, 2025

This change also allows the user to create an additional file with content. If main.py is empty, the saved hex when re-imported will remove main.py from the project in the editor. Which leads to errors when saving the main Python file: unexpected-error-description Please try again or raise a support request

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