Skip to content

Conversation

@multiplemonomials
Copy link
Collaborator

@multiplemonomials multiplemonomials commented Oct 28, 2025

Summary of changes

This PR adds an autoformatter for Mbed OS's python scripts. This makes sure that they all have consistent formatting, and will make development easier going forward.

Note: I did not make any manual modifications to python scripts as part of this PR. Everything that was changed was done by Ruff. The only files that need to be reviewed are:

  • .github/workflows/basic_checks.yml
  • tools/pyproject.toml
  • tools/run_python_linters.sh

Impact of changes

Migration actions required

Documentation

None


Pull request type

[X] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[X] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

@multiplemonomials multiplemonomials changed the title [draft] Add Python autoformatter (no actual formatting yet) [draft] Add Python autoformatter Oct 28, 2025
@multiplemonomials multiplemonomials changed the title [draft] Add Python autoformatter Add Python autoformatter Oct 29, 2025
style-check:
runs-on: ubuntu-latest
container:
image: ghcr.io/armmbed/mbed-os-env:master-latest
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unfortunately this docker container still has an ancient Python version (3.8, I think), so I doubt it would support the latest versions of tools like Ruff. We really need a new version of this container, but that's really not something I am excited to do, so for now I had to make these jobs not use the container.

Comment on lines 84 to 103
boot_magic = bytes(
[
0x77,
0xC2,
0x95,
0xF3,
0x60,
0xD2,
0xEF,
0x7F,
0x35,
0x52,
0x50,
0x0F,
0x2C,
0xB6,
0x79,
0x80,
]
)

Choose a reason for hiding this comment

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

I think this would look much better as a single line instead of a couple dozen. It's small enough to fit with 120 characters, which means that this formatting was due to the magic trailing comma.

I think you should re-run formatting with skip-magic-trailing-comma enabled (and then disable it and re-run ruff format), though I would also suggest combing through the changes since some magic trailing commas appear to be beneficial.

I would be OK to pass on that if you thought that it would require too much effort or discretion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oddly, adding that setting did not cause any changes to be made. However, I can fix this line at least.

Choose a reason for hiding this comment

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

Did you add this to your pyproject.toml?

[tool.ruff.format]
skip-magic-trailing-comma = true

I enabled the setting and it reformatted 77 files.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, I think I got confused and thought the default was true so I set it to false X_X. Now it worked, done!

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.

3 participants