- 
                Notifications
    You must be signed in to change notification settings 
- Fork 26
Add Python autoformatter #513
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
base: master
Are you sure you want to change the base?
Conversation
| style-check: | ||
| runs-on: ubuntu-latest | ||
| container: | ||
| image: ghcr.io/armmbed/mbed-os-env:master-latest | 
There was a problem hiding this comment.
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.
| boot_magic = bytes( | ||
| [ | ||
| 0x77, | ||
| 0xC2, | ||
| 0x95, | ||
| 0xF3, | ||
| 0x60, | ||
| 0xD2, | ||
| 0xEF, | ||
| 0x7F, | ||
| 0x35, | ||
| 0x52, | ||
| 0x50, | ||
| 0x0F, | ||
| 0x2C, | ||
| 0xB6, | ||
| 0x79, | ||
| 0x80, | ||
| ] | ||
| ) | 
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 = trueI enabled the setting and it reformatted 77 files.
There was a problem hiding this comment.
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!
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:
Impact of changes
Migration actions required
Documentation
None
Pull request type
Test results