Skip to content

scripts: sort boards alphabetically #89483

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

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

Conversation

Jyx
Copy link

@Jyx Jyx commented May 5, 2025

Sort the output alphabetically when executing 'west boards'. Doing so makes it simpler to locate boards while scrolling through the list of all accessible boards. This method is compatible with the '-n' argument too, which also will result in a filtered and sorted list.

Copy link

github-actions bot commented May 5, 2025

Hello @Jyx, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

@github-actions github-actions bot added the area: West West utility label May 5, 2025
@pdgendt
Copy link
Contributor

pdgendt commented May 5, 2025

It's not entirely true what you're claiming. You now have 2 sorted lists appended, first v1 boards, and then v2 boards. Not sure if this is a big concern, but this might be equally confusing as non-sorted boards.

@Jyx
Copy link
Author

Jyx commented May 5, 2025

It's not entirely true what you're claiming. You now have 2 sorted lists appended, first v1 boards, and then v2 boards. Not sure if this is a big concern,

Ah, you're right, I just realized that with the setup I have, I get no outputs from the v1 boards. I.e., it's only the second loop that produces output.

but this might be equally confusing as non-sorted boards.

Yes maybe, but what about printing "v1-boards" before running the first loop and then "v2-boards" before running the second loop? Then you at least have separation and you still get each section sorted. I.e., something like this:

$ git diff
diff --git a/scripts/west_commands/boards.py b/scripts/west_commands/boards.py
index 9668c53b407..bcb1a69e8c5 100644
--- a/scripts/west_commands/boards.py
+++ b/scripts/west_commands/boards.py
@@ -92,6 +92,7 @@ class Boards(WestCommand):
         args.board_roots += module_settings['board_root']
         args.soc_roots += module_settings['soc_root']

+        print("v1-boards\n=========")
         for board in sorted(list_boards.find_boards(args),
                             key=lambda b: b.name):
             if name_re is not None and not name_re.search(board.name):
@@ -107,6 +108,7 @@ class Boards(WestCommand):
                                         revisions=revisions_list,
                                         dir=board.dir, hwm=board.hwm, qualifiers=''))

+        print("v2-boards\n=========")
         for board in sorted(list_boards.find_v2_boards(args).values(),
                             key=lambda b: b.name):
             if name_re is not None and not name_re.search(board.name):

That would produce this

west boards
v1-boards
=========
v2-boards
=========
96b_aerocore2
96b_argonkey
96b_avenger96
96b_carbon
96b_meerkat96
96b_neonkey
96b_nitrogen
96b_stm32_sensor_mez
96b_wistrio
acn52832
acp_6_0_adsp
acrn
acrn_adl_crb
acrn_ehl_crb
...

Would that be good and acceptable?

@pdgendt
Copy link
Contributor

pdgendt commented May 5, 2025

Would that be good and acceptable?

Don't use print, and I think we need to consider that the output could be redirected to other scripts, so I'd rather not add those. If anything is printed extra, it should be done with debug.

But as V1 boards are deprecated, I'm not sure we should even bother.

@Jyx
Copy link
Author

Jyx commented May 5, 2025

Don't use print

Got it!

But as V1 boards are deprecated, I'm not sure we should even bother.

Let me try to fix find_v2_boards based on your suggestion, so that also returns a sorted list.

Sort the output alphabetically when executing 'west boards'. Doing so
makes it simpler to locate boards while scrolling through the list of
all accessible boards. This method is compatible with the '-n' argument
too, which also will result in a filtered and sorted list.

Signed-off-by: Joakim Bech <joakim.bech@gmail.com>
@Jyx
Copy link
Author

Jyx commented May 6, 2025

@pdgendt please let me know if this is more inline with what you were looking for. I've been running the tests locally (had to add -e Gitlint, since otherwise it seemed to never finish). No failures were found.

@kartben
Copy link
Contributor

kartben commented May 6, 2025

I haven't looked at the changes in details but changing the signature of the find_v2_boards() API is asking for trouble. For example, this breaks documentation generation (see https://github.com/jyx/zephyr/blob/f3caf3c0a8234f47a088fee6da52858a3672ed13/doc/_scripts/gen_boards_catalog.py#L264), which CI will likely confirm in a minute.

@pdgendt
Copy link
Contributor

pdgendt commented May 6, 2025

@pdgendt please let me know if this is more inline with what you were looking for. I've been running the tests locally (had to add -e Gitlint, since otherwise it seemed to never finish). No failures were found.

Thanks, as I see these changes required, I'm a bit concerned about changing the return type of this "public" function find_v2_boards.
I might have set you on a wrong path here, sorry. Maybe your initial proposal was the cleanest, but only applied to V2 boards. 🫣
@carlescufi

@tejlmand
Copy link
Contributor

please note that boards are currently ordered per vendor, and that is very useful in many cases as you often know the vendor of your board, but perhaps mistyped the name of the board.

This becomes more visible if you use format printing.

For example when using west boards -f "{vendor},{name}", then output look like this:

which makes it easy to find boards by a given vendor.

With this PR, this becomes messy:

How to sort is of course very much based upon how people use a tool, but if changing sorting mechanism, then provide the option for users to decide how to sort instead of just changing it to another personal preference.

@fabiobaltieri
Copy link
Member

Could this sort based on the formatted output? then you'd have it by vendor if you use -f "{vendor},{name}", that's kindof how I'd expect it to behave

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

Successfully merging this pull request may close these issues.

5 participants