Skip to content
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

Add __name__ to all board modules #5248

Closed
jepler opened this issue Aug 27, 2021 · 3 comments · Fixed by #5299
Closed

Add __name__ to all board modules #5248

jepler opened this issue Aug 27, 2021 · 3 comments · Fixed by #5299

Comments

@jepler
Copy link
Member

jepler commented Aug 27, 2021

@capellini noticed that (most?) boards don't have __name__ in the board module: #5183 (comment)

It would be good to see this added, just for consistency's sake.

@PracticalMetal
Copy link

Hi, I would like to work on this. Can you suggest me ways to get started?

@dhalbert
Copy link
Collaborator

Take a look at #5222, which added board.board_id. The author wrote a script to automate the changes.

@capellini
Copy link

@PracticalMetal We want add a __name__ attribute and assign it a q-string value of 'board', since that's the name of the module. So that, at the serial terminal, instead of getting a blank name for the module:

>>> import board
>>> board
<module ''>

we would get 'board' instead:

>>> import board
>>> board  # the next line prints 'board' instead of a blank string
<module 'board'>

Inside the pins.c file for each board (ports/**/boards/**/pins.c), we would need to change the board_global_dict_table (sometimes named board_module_globals_table) to add the following line:

STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
    { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_board) }, // this line needs to be added to each file
    // ...

provided that you have access to a terminal, you can use a utility likesed to do an in-place substitution, where we insert the line above in the first line of the board_global_dict_table definition:

sed -i \
   's/STATIC const mp_rom_map_elem_t board_global_dict_table\[\] = {/STATIC const mp_rom_map_elem_t board_global_dict_table\[\] = {\n    { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_board) },/' \
  ports/**/boards/**/pins.c

You could also do the same for files that use board_module_globals_table instead of board_global_dict_table. Then it should be a matter of making sure that sed put the correct lines in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants