Skip to content

tools: Ensure codeformat.py uses uncrustify 0.72. #15221

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: master
Choose a base branch
from

Conversation

Gadgetoid
Copy link
Contributor

As identified in #14046 it's really easy to install a mismatched version of Uncrustify and format source in a way that the CI (which just installs whatever mystery meat Uncrustify apt cares to offer) disagrees with.

Eg: when I develop on macOS, brew installs Uncrustify-0.79.0_f.

This may also vary across Linux distributions, and is also prone to some future break if runs-on: ubuntu-22.04 is ever changed.

This change is a proposal for installing Uncrustify in a consistent fashion, so that developers and CI get the same version, the same rules and the same output.

.gitignore: Ignore tools/uncrustify build directory.
tools/ci.sh: Replace uncrustify install with from-source build.
tools/codeformat.py: Use tools/uncrustify/uncrustify.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
@Gadgetoid
Copy link
Contributor Author

Note: It may be prudent to try the "apt install uncrustify" step first and only install from source if there's a version mismatch. This would avoid any performance impact both on CI and to developers who already have the correct version.

Copy link

codecov bot commented Jun 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.42%. Comparing base (3c8089d) to head (d03889b).
Report is 812 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #15221   +/-   ##
=======================================
  Coverage   98.42%   98.42%           
=======================================
  Files         161      161           
  Lines       21204    21204           
=======================================
  Hits        20870    20870           
  Misses        334      334           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

github-actions bot commented Jun 6, 2024

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS

@dhalbert
Copy link
Contributor

dhalbert commented Jun 6, 2024

@dlech just built a pypi package that installs the proper version:
https://pypi.org/project/micropython-uncrustify/

See https://github.com/orgs/micropython/discussions/14496

@dlech
Copy link
Contributor

dlech commented Jun 6, 2024

FYI, I recently published https://pypi.org/project/micropython-uncrustify/ to have an easy way to get a pre-compiled binary with the correct version of uncrustify. This would be more efficient than everyone having to compile it themselves.

@Gadgetoid
Copy link
Contributor Author

Haha, now that's an approach. D'oh!

Downside is that you probably now have to contend with cursed virtualenvs somehow 🫠 ... but that's not my problem runs away

Happy to close this and defer to whatever solution you're cookin' up! I got a little carried away 😆

@Gadgetoid
Copy link
Contributor Author

Hmmm, well it works -

brew install virtualenvwrapper pyenv-virtualenvwrapper
source virtualenvwrapper.sh
mkvirtualenv micropython
pip install micropython-uncrustify
~/.virtualenvs/micropython/bin/uncrustify --version 
Uncrustify-f44f717

And bonus points for Windows builds!

I guess it's supposed to huck it into /bin if I do naughty things with system python?

@dlech
Copy link
Contributor

dlech commented Jun 6, 2024

You can also run it like this if you don't want to make a vritualenv or pollute your PATH.

pipx run --spec micropython-uncrustify uncrustify --version

@Gadgetoid
Copy link
Contributor Author

pipx aha, that's the one people keep telling me about that my brain never retains. TIL, thank you.

Though, uh, remind me not to try and brew install pipx again... kicked off some kind of dependency chain chaos involving ffmpeg.

@projectgus
Copy link
Contributor

projectgus commented Jun 11, 2024

Oh nice work, @dlech! I mentioned in the linked issue that I did some work getting uncrustify to build under wasm, but it's even better if you've got it building native binaries for all of the relevant architectures.

Downside is that you probably now have to contend with cursed virtualenvs somehow 🫠 ... but that's not my problem runs away

pre-commit manages its own sandbox Python environments, from what I can tell, and it seems pretty seamless. So I think what we can probably do is make a pre-commit hook that installs and runs the correct micropython-uncrustify version and that should be pretty seamless for most #users. EDIT: I must have remembered this wrong, it is just using the current virtualenv I think.

@dpgeorge dpgeorge added the tools Relates to tools/ directory in source, or other tooling label Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tools Relates to tools/ directory in source, or other tooling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants