bytecode not possible for boot.py & main.py?

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
smhodge
Posts: 86
Joined: Tue Jan 22, 2019 2:16 am
Location: Kirkland, WA, USA

bytecode not possible for boot.py & main.py?

Post by smhodge » Thu May 21, 2020 11:59 pm

It seems like boot.py and main.py cannot be bytecode (mpy files). Is that correct?

Pyboard 1.1, firmware 1.12

User avatar
tve
Posts: 216
Joined: Wed Jan 01, 2020 10:12 pm
Location: Santa Barbara, CA
Contact:

Re: bytecode not possible for boot.py & main.py?

Post by tve » Fri May 22, 2020 12:52 am

I'm afraid you're correct. From main.c:

Code: Select all

        const char *boot_py = "boot.py";
        int ret = pyexec_file_if_exists(boot_py);

smhodge
Posts: 86
Joined: Tue Jan 22, 2019 2:16 am
Location: Kirkland, WA, USA

Re: bytecode not possible for boot.py & main.py?

Post by smhodge » Fri May 22, 2020 3:27 pm

Thanks. So much for boot.py. But tests I did also seem to indicate that even if boot.py exists, changing the line in it that starts main.py won't work either if changed to

pyb.main('main.mpy') # main script to run after this one

won't work either.

User avatar
tve
Posts: 216
Joined: Wed Jan 01, 2020 10:12 pm
Location: Santa Barbara, CA
Contact:

Re: bytecode not possible for boot.py & main.py?

Post by tve » Fri May 22, 2020 4:41 pm

Both boot.py and main.py (regardless of it's name) must be python source files. There is nothing in the code that looks at the filename extension as these files are not imported, simply executed. You'd have to test the filename and switch to EXEC_FLAG_SOURCE_IS_RAW_CODE in https://github.com/micropython/micropyt ... xec.c#L551

I don't know what you're trying to achieve by making these files .mpy but you could make them 1-liners and import an .mpy
I'll have to look into that when I get around to periodic wake-up on battery on the esp32...

smhodge
Posts: 86
Joined: Tue Jan 22, 2019 2:16 am
Location: Kirkland, WA, USA

Re: bytecode not possible for boot.py & main.py?

Post by smhodge » Fri May 22, 2020 4:52 pm

I have a python (not microPython) pre-processor script that ends up compiling all files in a project to bytecode (and then uses rshell to sync all of them to the board, reset the board, and open a PuTTY connection to stdout). To deal with the aforementioned complication yesterday I added a workaround to that script to copy .py instead of .mpy for boot.py and main.py. Your suggestion of a one-liner import for (a renamed) main is a good idea.

Post Reply