Renaming the pyb module?

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
ldmoretti
Posts: 5
Joined: Fri Mar 26, 2021 1:34 am

Renaming the pyb module?

Post by ldmoretti » Thu Jan 20, 2022 7:05 pm

We've got a custom board that we want to run Micropython on, but my lead developer wants it to be our board name, not pyb, for the name of the module.

He previously just downloaded the code and did a global search-and-replace but that makes it much harder to upgrade releases. I'm making a forked Git project with the changes for our board and want to try to keep the divergence minimal.

Is there a simple way to change the module name or to alias the module name?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Renaming the pyb module?

Post by dhylands » Thu Jan 20, 2022 8:07 pm

You can get away with changing a single line.

Namely this one:
https://github.com/micropython/micropyt ... ort.h#L188

change MP_QSTR_pyb to be MP_QSTR_myboardname

and rebuild (you may need to do a clean and rebuild).

ldmoretti
Posts: 5
Joined: Fri Mar 26, 2021 1:34 am

Re: Renaming the pyb module?

Post by ldmoretti » Thu Jan 20, 2022 9:41 pm

Thanks David:
I found that one and that helped with the import.

My lead wasn't happy that the help(boardname) command still said __name__ = pyb so I found the MP_ROM_QSTR(MP_QSTR_pyb) in modpyb.c pyb_module_globals_table{}

Once I changed those two it seems to work well.

Luciano

Post Reply